diff options
Diffstat (limited to 'firmware/microblaze/usrp2p/spi_flash_read.c')
-rw-r--r-- | firmware/microblaze/usrp2p/spi_flash_read.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/firmware/microblaze/usrp2p/spi_flash_read.c b/firmware/microblaze/usrp2p/spi_flash_read.c index 1c65350f7..4682c5fe6 100644 --- a/firmware/microblaze/usrp2p/spi_flash_read.c +++ b/firmware/microblaze/usrp2p/spi_flash_read.c @@ -20,6 +20,8 @@ #include "spi_flash_private.h" #include <stdlib.h> // abort +static size_t _spi_flash_log2_memory_size; + uint32_t spi_flash_rdid(void) { @@ -48,9 +50,26 @@ spi_flash_log2_sector_size(void) }; _spi_flash_log2_sector_size = log2_sector_size[size - 22]; + _spi_flash_log2_memory_size = size; //while we're at it return _spi_flash_log2_sector_size; } +size_t +spi_flash_log2_memory_size(void) +{ + if (_spi_flash_log2_memory_size != 0) + return _spi_flash_log2_memory_size; + + uint32_t id = spi_flash_rdid(); + int type = (id >> 8) & 0xff; + int size = id & 0xff; + if (type != 0x20 || size < 22 || size > 24) + abort(); + + _spi_flash_log2_memory_size = size; + return _spi_flash_log2_memory_size; +} + void spi_flash_read(uint32_t flash_addr, size_t nbytes, void *buf) { |