15 #define SFDP_MAGIC 0x50444653
16 #define SFDP_ACCESS_PROT 0xFF
17 #define SFDP_BASIC_FLASH 0xFF00
18 #define SFDP_4BYTE_ADDR 0xFF84
66 uint32_t *ptable =
NULL;
67 unsigned int j, k, nph;
68 int retval, erase_type = 0;
73 memset(&header, 0,
sizeof(header));
83 LOG_ERROR(
"access protocol 0x%02x not implemented",
89 nph = ((header.
revision >> 16) & 0xFF) + 1;
91 pheaders = malloc(
sizeof(
struct sfdp_phdr) * nph);
96 memset(pheaders, 0,
sizeof(
struct sfdp_phdr) * nph);
98 (
sizeof(
struct sfdp_phdr) >> 2) * nph, (uint32_t *)pheaders);
102 for (k = 0; k < nph; k++) {
103 uint8_t words = (pheaders[k].
revision >> 24) & 0xFF;
104 uint16_t
id = (((pheaders[k].
ptr) >> 16) & 0xFF00) | (pheaders[k].
revision & 0xFF);
105 uint32_t
ptr = pheaders[k].
ptr & 0xFFFFFF;
107 LOG_DEBUG(
"pheader %d len=0x%02" PRIx8
" id=0x%04" PRIx16
108 " ptr=0x%06" PRIx32, k, words,
id,
ptr);
111 ptable = malloc(words << 2);
121 for (j = 0; j < words; j++)
122 LOG_DEBUG(
"word %02d 0x%08X", j + 1, ptable[j]);
129 LOG_ERROR(
"id=0x%04" PRIx16
" invalid length %d",
id, words);
134 LOG_DEBUG(
"basic flash parameter table");
144 if (table->
density & (1UL << 31))
158 erase = (table->
erase_t12 >> 0) & 0xFFFF;
160 if (((table->
erase_t12 >> 16) & 0xFF) > (erase & 0xFF)) {
161 erase = (table->
erase_t12 >> 16) & 0xFFFF;
164 if (((table->
erase_t34 >> 0) & 0xFF) > (erase & 0xFF)) {
165 erase = (table->
erase_t34 >> 0) & 0xFFFF;
168 if (((table->
erase_t34 >> 16) & 0xFF) > (erase & 0xFF)) {
169 erase = (table->
erase_t34 >> 16) & 0xFFFF;
190 if (((table->
fast_addr >> 17) & 0x3) == 0x0)
191 LOG_ERROR(
"device needs paging - not implemented");
204 }
else if (((table->
fast_addr >> 17) & 0x3) == 0x1)
205 LOG_INFO(
"device has to be switched to 4-byte addresses");
212 LOG_INFO(
"4-byte address parameter table");
215 if (table->
flags & (1UL << 0))
217 if (table->
flags & (1UL << 5))
219 if (table->
flags & (1UL << 6))
223 if ((erase_type == 1) && (table->
flags & (1UL << 9)))
225 else if ((erase_type == 2) && (table->
flags & (1UL << 10)))
227 else if ((erase_type == 3) && (table->
flags & (1UL << 11)))
229 else if ((erase_type == 4) && (table->
flags & (1UL << 12)))
232 LOG_ERROR(
"parameter table id=0x%04" PRIx16
" invalid length %d",
id, words);
234 LOG_DEBUG(
"unimplemented parameter table id=0x%04" PRIx16,
id);
240 if (erase_type != 0) {
#define ERROR_FLASH_BANK_NOT_PROBED
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
int spi_sfdp(struct flash_bank *bank, struct flash_device *dev, read_sfdp_block_t read_sfdp_block)
static const char * sfdp_name
int(* read_sfdp_block_t)(struct flash_bank *bank, uint32_t addr, uint32_t words, uint32_t *buffer)
#define SPIFLASH_PAGE_PROGRAM
#define SPIFLASH_MASS_ERASE
static int read_sfdp_block(struct flash_bank *bank, uint32_t addr, uint32_t words, uint32_t *buffer)
Provides details of a flash bank, available either on-chip or through a major interface.