![]() |
coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
|
#include <assert.h>
#include <boot/coreboot_tables.h>
#include <commonlib/region.h>
#include <console/console.h>
#include <string.h>
#include <spi-generic.h>
#include <spi_flash.h>
#include <timer.h>
#include <types.h>
#include "spi_flash_internal.h"
Go to the source code of this file.
Macros | |
#define | IDCODE_LEN 5 |
Functions | |
static void | spi_flash_addr (u32 addr, u8 *cmd) |
static int | do_spi_flash_cmd (const struct spi_slave *spi, const u8 *dout, size_t bytes_out, void *din, size_t bytes_in) |
static int | do_dual_output_cmd (const struct spi_slave *spi, const u8 *dout, size_t bytes_out, void *din, size_t bytes_in) |
static int | do_dual_io_cmd (const struct spi_slave *spi, const u8 *dout, size_t bytes_out, void *din, size_t bytes_in) |
int | spi_flash_cmd (const struct spi_slave *spi, u8 cmd, void *response, size_t len) |
int | spi_flash_cmd_write (const struct spi_slave *spi, const u8 *cmd, size_t cmd_len, const void *data, size_t data_len) |
int | spi_flash_cmd_read (const struct spi_flash *flash, u32 offset, size_t len, void *buf) |
int | spi_flash_cmd_poll_bit (const struct spi_flash *flash, unsigned long timeout, u8 cmd, u8 poll_bit) |
int | spi_flash_cmd_wait_ready (const struct spi_flash *flash, unsigned long timeout) |
int | spi_flash_cmd_erase (const struct spi_flash *flash, u32 offset, size_t len) |
int | spi_flash_cmd_status (const struct spi_flash *flash, u8 *reg) |
int | spi_flash_cmd_write_page_program (const struct spi_flash *flash, u32 offset, size_t len, const void *buf) |
static int | fill_spi_flash (const struct spi_slave *spi, struct spi_flash *flash, const struct spi_flash_vendor_info *vi, const struct spi_flash_part_id *part) |
static const struct spi_flash_part_id * | find_part (const struct spi_flash_vendor_info *vi, uint16_t id[2]) |
static int | find_match (const struct spi_slave *spi, struct spi_flash *flash, uint8_t manuf_id, uint16_t id[2]) |
int | spi_flash_generic_probe (const struct spi_slave *spi, struct spi_flash *flash) |
int | spi_flash_probe (unsigned int bus, unsigned int cs, struct spi_flash *flash) |
int | spi_flash_read (const struct spi_flash *flash, u32 offset, size_t len, void *buf) |
int | spi_flash_write (const struct spi_flash *flash, u32 offset, size_t len, const void *buf) |
int | spi_flash_erase (const struct spi_flash *flash, u32 offset, size_t len) |
int | spi_flash_status (const struct spi_flash *flash, u8 *reg) |
int | spi_flash_is_write_protected (const struct spi_flash *flash, const struct region *region) |
int | spi_flash_set_write_protected (const struct spi_flash *flash, const struct region *region, const enum spi_flash_status_reg_lockdown mode) |
int | spi_flash_volatile_group_begin (const struct spi_flash *flash) |
int | spi_flash_volatile_group_end (const struct spi_flash *flash) |
void | lb_spi_flash (struct lb_header *header) |
int | spi_flash_ctrlr_protect_region (const struct spi_flash *flash, const struct region *region, const enum ctrlr_prot_type type) |
int | spi_flash_vector_helper (const struct spi_slave *slave, struct spi_op vectors[], size_t count, int(*func)(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin)) |
Variables | |
static const struct spi_flash_vendor_info * | spi_flash_vendors [] |
static uint32_t | volatile_group_count |
const struct spi_flash_ops_descriptor | spi_flash_pp_0x20_sector_desc |
const struct spi_flash_ops_descriptor | spi_flash_pp_0xd8_sector_desc |
#define IDCODE_LEN 5 |
Definition at line 373 of file spi_flash.c.
|
static |
Definition at line 82 of file spi_flash.c.
References spi_slave::ctrlr, spi_op::din, spi_op::dout, NULL, spi_claim_bus(), spi_release_bus(), spi_xfer_vector(), and spi_ctrlr::xfer_dual.
Referenced by spi_flash_cmd_read().
|
static |
Definition at line 54 of file spi_flash.c.
References spi_slave::ctrlr, spi_op::din, spi_op::dout, NULL, spi_claim_bus(), spi_release_bus(), spi_xfer_vector(), and spi_ctrlr::xfer_dual.
Referenced by spi_flash_cmd_read().
|
static |
Definition at line 23 of file spi_flash.c.
References ARRAY_SIZE, count, spi_op::din, spi_op::dout, NULL, spi_claim_bus(), spi_release_bus(), and spi_xfer_vector().
Referenced by spi_flash_cmd(), spi_flash_cmd_poll_bit(), spi_flash_cmd_read(), and spi_flash_cmd_write().
|
static |
Definition at line 375 of file spi_flash.c.
References spi_flash_vendor_info::after_probe, spi_flash_vendor_info::desc, spi_flash::dual_io, spi_flash::dual_output, spi_flash_ops_descriptor::erase_cmd, spi_flash::erase_cmd, spi_flash_part_id::fast_read_dual_io_support, spi_flash_part_id::fast_read_dual_output_support, spi_flash::flags, spi_flash_part_id::id, spi_flash_vendor_info::id, KiB, memcpy(), spi_flash::model, spi_flash_part_id::nr_sectors_shift, spi_flash_ops_descriptor::ops, spi_flash::ops, spi_flash::page_size, spi_flash_vendor_info::page_size_shift, spi_flash::part, spi_flash_ops_descriptor::pp_cmd, spi_flash::pp_cmd, spi_flash_vendor_info::prot_ops, spi_flash::prot_ops, spi_flash::sector_size, spi_flash_vendor_info::sector_size_kib_shift, spi_flash::size, spi_flash::spi, spi_flash_ops_descriptor::status_cmd, spi_flash::status_cmd, spi_flash::vendor, spi_flash_ops_descriptor::wren_cmd, and spi_flash::wren_cmd.
Referenced by find_match().
|
static |
Definition at line 423 of file spi_flash.c.
References ARRAY_SIZE, fill_spi_flash(), find_part(), spi_flash_vendor_info::id, NULL, and spi_flash_vendors.
Referenced by spi_flash_generic_probe().
|
static |
Definition at line 404 of file spi_flash.c.
References spi_flash_part_id::id, spi_flash_vendor_info::ids, spi_flash_vendor_info::match_id_mask, spi_flash_vendor_info::nr_part_ids, and NULL.
Referenced by find_match().
void lb_spi_flash | ( | struct lb_header * | header | ) |
Definition at line 683 of file spi_flash.c.
References boot_device_spi_flash(), CMD_BLOCK_ERASE, CONFIG, lb_spi_flash::erase_cmd, spi_flash::erase_cmd, lb_spi_flash::flash_size, header, KiB, lb_new_record(), LB_TAG_SPI_FLASH, lb_spi_flash::mmap_count, lb_spi_flash::sector_size, spi_flash::sector_size, lb_spi_flash::size, spi_flash::size, spi_flash_get_mmap_windows(), and lb_spi_flash::tag.
Definition at line 15 of file spi_flash.c.
References addr.
Referenced by spi_flash_cmd_erase(), spi_flash_cmd_read(), and spi_flash_cmd_write_page_program().
Definition at line 107 of file spi_flash.c.
References BIOS_WARNING, do_spi_flash_cmd(), and printk.
Referenced by spi_flash_cmd_erase(), spi_flash_cmd_status(), spi_flash_cmd_write_page_program(), spi_flash_generic_probe(), spi_flash_probe(), sst_disable_writing(), sst_enable_writing(), sst_enable_writing_status(), winbond_flash_cmd_status(), and winbond_get_write_protection().
Definition at line 228 of file spi_flash.c.
References BIOS_DEBUG, BIOS_SPEW, BIOS_WARNING, CMD_WRITE_ENABLE, spi_flash::erase_cmd, NULL, offset, printk, spi_flash::sector_size, spi_flash::spi, spi_flash_addr(), spi_flash_cmd(), spi_flash_cmd_wait_ready(), spi_flash_cmd_write(), SPI_FLASH_PAGE_ERASE_TIMEOUT_MS, and stopwatch::start.
int spi_flash_cmd_poll_bit | ( | const struct spi_flash * | flash, |
unsigned long | timeout, | ||
u8 | cmd, | ||
u8 | poll_bit | ||
) |
Definition at line 190 of file spi_flash.c.
References BIOS_WARNING, do_spi_flash_cmd(), printk, spi_flash::spi, stopwatch_duration_msecs(), stopwatch_expired(), and stopwatch_init_msecs_expire().
Referenced by spi_flash_cmd_wait_ready().
Definition at line 142 of file spi_flash.c.
References BIOS_WARNING, buf, CMD_READ_ARRAY_FAST, CMD_READ_ARRAY_SLOW, CMD_READ_FAST_DUAL_IO, CMD_READ_FAST_DUAL_OUTPUT, CONFIG, spi_slave::ctrlr, do_dual_io_cmd(), do_dual_output_cmd(), do_spi_flash_cmd(), spi_flash::dual_io, spi_flash::dual_output, spi_flash::flags, offset, printk, spi_flash::spi, spi_crop_chunk(), spi_flash_addr(), and spi_ctrlr::xfer_dual.
Definition at line 276 of file spi_flash.c.
References spi_flash::spi, spi_flash_cmd(), and spi_flash::status_cmd.
Definition at line 221 of file spi_flash.c.
References CMD_READ_STATUS, spi_flash_cmd_poll_bit(), and STATUS_WIP.
Referenced by spi_flash_cmd_erase(), spi_flash_cmd_write_page_program(), sst_byte_write(), sst_write_ai(), and winbond_flash_cmd_status().
int spi_flash_cmd_write | ( | const struct spi_slave * | spi, |
const u8 * | cmd, | ||
size_t | cmd_len, | ||
const void * | data, | ||
size_t | data_len | ||
) |
Definition at line 122 of file spi_flash.c.
References BIOS_WARNING, do_spi_flash_cmd(), memcpy(), NULL, and printk.
Referenced by spi_flash_cmd_erase(), spi_flash_cmd_write_page_program(), sst_byte_write(), sst_write_ai(), and winbond_flash_cmd_status().
int spi_flash_cmd_write_page_program | ( | const struct spi_flash * | flash, |
u32 | offset, | ||
size_t | len, | ||
const void * | buf | ||
) |
Definition at line 281 of file spi_flash.c.
References BIOS_SPEW, BIOS_WARNING, buf, CONFIG, MIN, NULL, offset, spi_flash::page_size, spi_flash::pp_cmd, printk, spi_flash::spi, spi_crop_chunk(), spi_flash_addr(), spi_flash_cmd(), spi_flash_cmd_wait_ready(), spi_flash_cmd_write(), SPI_FLASH_PROG_TIMEOUT_MS, and spi_flash::wren_cmd.
int spi_flash_ctrlr_protect_region | ( | const struct spi_flash * | flash, |
const struct region * | region, | ||
const enum ctrlr_prot_type | type | ||
) |
Definition at line 719 of file spi_flash.c.
References spi_slave::ctrlr, spi_ctrlr::flash_protect, region_is_subregion(), region::size, spi_flash::size, spi_flash::spi, and type.
Referenced by boot_device_wp_region(), and nvm_protect().
Definition at line 553 of file spi_flash.c.
References spi_flash_ops::erase, offset, spi_flash::ops, spi_flash_volatile_group_begin(), and spi_flash_volatile_group_end().
Referenced by spi_eraseat().
Definition at line 448 of file spi_flash.c.
References BIOS_INFO, BIOS_SPEW, CMD_READ_ID, CONFIG, find_match(), IDCODE_LEN, printk, spi_flash_cmd(), and stmicro_release_deep_sleep_identify().
Referenced by spi_flash_probe(), and spi_flash_programmer_probe().
Definition at line 576 of file spi_flash.c.
References BIOS_WARNING, spi_flash_protection_ops::get_write, printk, spi_flash::prot_ops, region_is_subregion(), region::size, and spi_flash::size.
Referenced by boot_device_wp_region(), mainboard_print_info(), and protect_ro_rgn_spi_flash().
Definition at line 486 of file spi_flash.c.
References BIOS_ERR, BIOS_INFO, BIOS_WARNING, CMD_EXIT_4BYTE_ADDR_MODE, CONFIG, spi_slave::cs, spi_slave::ctrlr, spi_flash::dual_io, spi_flash::dual_output, ENV_INITIAL_STAGE, spi_flash::flags, spi_ctrlr::flash_probe, spi_flash::model, NULL, printk, spi_flash::sector_size, spi_flash::size, spi_flash::spi, spi_flash_cmd(), spi_flash_generic_probe(), spi_setup_slave(), spi_flash::vendor, and spi_ctrlr::xfer_dual.
Referenced by boot_device_init(), boot_device_rw_init(), and spi_init_cb().
Definition at line 531 of file spi_flash.c.
References buf, offset, spi_flash::ops, and spi_flash_ops::read.
Referenced by pre_mem_debug_init(), and spi_readat().
int spi_flash_set_write_protected | ( | const struct spi_flash * | flash, |
const struct region * | region, | ||
const enum spi_flash_status_reg_lockdown | mode | ||
) |
Definition at line 598 of file spi_flash.c.
References BIOS_INFO, BIOS_WARNING, printk, spi_flash::prot_ops, region_is_subregion(), spi_flash_protection_ops::set_write, region::size, spi_flash::size, SPI_WRITE_PROTECTION_NONE, SPI_WRITE_PROTECTION_PERMANENT, SPI_WRITE_PROTECTION_PIN, SPI_WRITE_PROTECTION_PRESERVE, and SPI_WRITE_PROTECTION_REBOOT.
Referenced by boot_device_wp_region(), and protect_ro_rgn_spi_flash().
Definition at line 568 of file spi_flash.c.
References spi_flash::ops, and spi_flash_ops::status.
Referenced by mainboard_config_cbi_wp(), nvm_is_write_protected(), and protect_ro_rgn_spi_flash().
int spi_flash_vector_helper | ( | const struct spi_slave * | slave, |
struct spi_op | vectors[], | ||
size_t | count, | ||
int(*)(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin) | func | ||
) |
Definition at line 745 of file spi_flash.c.
Referenced by xfer_vectors().
int spi_flash_volatile_group_begin | ( | const struct spi_flash * | flash | ) |
Definition at line 647 of file spi_flash.c.
References chipset_volatile_group_begin(), CONFIG, count, and volatile_group_count.
Referenced by spi_flash_erase(), and spi_flash_write().
int spi_flash_volatile_group_end | ( | const struct spi_flash * | flash | ) |
Definition at line 664 of file spi_flash.c.
References assert, chipset_volatile_group_end(), CONFIG, count, and volatile_group_count.
Referenced by spi_flash_erase(), and spi_flash_write().
Definition at line 537 of file spi_flash.c.
References buf, offset, spi_flash::ops, spi_flash_volatile_group_begin(), spi_flash_volatile_group_end(), and spi_flash_ops::write.
Referenced by spi_writeat().
const struct spi_flash_ops_descriptor spi_flash_pp_0x20_sector_desc |
Definition at line 745 of file spi_flash.c.
const struct spi_flash_ops_descriptor spi_flash_pp_0xd8_sector_desc |
Definition at line 745 of file spi_flash.c.
|
static |
Definition at line 335 of file spi_flash.c.
Referenced by find_match().
|
static |
Definition at line 645 of file spi_flash.c.
Referenced by spi_flash_volatile_group_begin(), and spi_flash_volatile_group_end().