123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- #ifndef SPIFLASH_H
- #define SPIFLASH_H
- #include <inttypes.h>
- #include <stddef.h>
- #include <string.h>
- #include "fwimg.h"
- enum romcmd {
-
- ROM_WRITE_ENABLE = 0x06,
- ROM_VOLATILE_SR_WRITE_ENABLE = 0x50,
- ROM_WRITE_DISABLE = 0x04,
- ROM_RELEASE_POWERDOWN_ID = 0xab,
- ROM_MANUFACTURER_DEVICE_ID = 0x90,
- ROM_JEDEC_ID = 0x9f,
- ROM_READ_UNIQUE_ID = 0x4b,
- ROM_READ_DATA = 0x03,
- ROM_READ_DATA_32BIT = 0x13,
- ROM_FAST_READ = 0x0b,
- ROM_FAST_READ_32BIT = 0x0c,
- ROM_PAGE_PROGRAM = 0x02,
- ROM_PAGE_PROGRAM_32BIT = 0x12,
- ROM_ERASE_4K = 0x20,
- ROM_ERASE_4K_32BIT = 0x21,
- ROM_ERASE_32K = 0x52,
- ROM_ERASE_64K = 0xd8,
- ROM_ERASE_64K_32BIT = 0xdc,
- ROM_ERASE_ALL = 0xc7,
- ROM_READ_SR1 = 0x05,
- ROM_WRITE_SR1 = 0x01,
- ROM_READ_SR2 = 0x35,
- ROM_WRITE_SR2 = 0x31,
- ROM_READ_SR3 = 0x15,
- ROM_WRITE_SR3 = 0x11,
- ROM_READ_EAR = 0xc8,
- ROM_WRITE_EAR = 0xc5,
- ROM_READ_SFDP = 0x5a,
- ROM_ERASE_SECURITY = 0x44,
- ROM_PROGRAM_SECURITY = 0x42,
- ROM_READ_SECURITY = 0x48,
- ROM_GLOBAL_BLOCK_LOCK = 0x7e,
- ROM_GLOBAL_BLOCK_UNLOCK = 0x98,
- ROM_READ_BLOCK_LOCK = 0x3d,
- ROM_ONE_BLOCK_LOCK = 0x36,
- ROM_ONE_BLOCK_UNLOCK = 0x39,
- ROM_ERASE_PROGRAM_SUSPEND = 0x75,
- ROM_ERASE_PROGRAM_RESUME = 0x7a,
- ROM_POWER_DOWN = 0xb9,
- ROM_ENTER_32BIT = 0xb7,
- ROM_LEAVE_32BIT = 0xe9,
- ROM_ENTER_QPI = 0x48,
- ROM_ENABLE_RESET = 0x66,
- ROM_RESET = 0x99,
-
- ROM_FAST_READ_DUAL = 0x3b,
- ROM_FAST_READ_DUAL_32BIT = 0x3c
- };
- #define SPIFLASH_SFDP_SIZE 256
- #define SPIFLASH_PAGE_SHIFT 8
- #define SPIFLASH_PAGE_SIZE (1 << SPIFLASH_PAGE_SHIFT)
- #define SPIFLASH_SECTOR_SHIFT 12
- #define SPIFLASH_SECTOR_SIZE (1 << SPIFLASH_SECTOR_SHIFT)
- #define SPIFLASH_BLOCK_SHIFT 16
- #define SPIFLASH_BLOCK_SIZE (1 << SPIFLASH_BLOCK_SHIFT)
- struct spiflash_ops {
-
- int (*spi_write)(void *cookie,
- const void *cmd, unsigned int cmd_len,
- const void *data, unsigned int data_len,
- int tshsl);
-
- int (*spi_read)(void *cookie,
- const void *cmd, unsigned int cmd_len,
- void *data, unsigned int data_len,
- int tshsl);
-
- void (*yield)(void *cookie, int delay);
- };
- enum spiflash_addr_mode {
- SPIFLASH_ADDR_DYNAMIC,
- SPIFLASH_ADDR_24BIT,
- SPIFLASH_ADDR_32BIT
- };
- struct spiflash_param {
-
- enum spiflash_addr_mode addr;
-
- int tshsl;
- int tshsl1;
- int tshsl2;
-
- int trst;
- int tw;
- int tpp;
- int tse;
- int tbe1;
- int tbe2;
- int tce;
- };
- struct spiflash {
-
- int (*read_data)(void *cookie, void *buf, unsigned int bufsize);
- void *cookie;
-
- const struct spiflash_ops *ops;
- const struct spiflash_param *param;
- const char *target;
- };
- int spiflash_flash_file(const struct spiflash *flash,
- void *data, size_t datalen);
- int spiflash_flash_data(const struct spiflash *flash, uint32_t addr,
- const void *data, size_t datalen);
- #define SPIFLASH_ID_LEN 8
- int spiflash_read_id(const struct spiflash *flash, void *id);
- #define SPIFLASH_VDID_LEN 2
- int spiflash_read_vdid(const struct spiflash *flash, void *vdid);
- #endif
|