From bc06d86ea3b030b0ee495c1f7f6404019ac6afc1 Mon Sep 17 00:00:00 2001 From: Brian Glod Date: Fri, 7 Sep 2018 11:04:12 -0400 Subject: [PATCH] host: libbladeRF: Replace BLADERF_FLASH_NUM_PAGES The BLADERF_FLASH_NUM_PAGES macro was replaced with data from the device's flash architecture structure (e.g. dev->flash_arch->num_pages). Functions with new parameters include: - spi_flash.c: check_page_access() - bladeRF device handle --- host/libraries/libbladeRF/include/bladeRF1.h | 4 ---- host/libraries/libbladeRF/src/driver/spi_flash.c | 13 +++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/host/libraries/libbladeRF/include/bladeRF1.h b/host/libraries/libbladeRF/include/bladeRF1.h index d5940276..0b9c3209 100644 --- a/host/libraries/libbladeRF/include/bladeRF1.h +++ b/host/libraries/libbladeRF/include/bladeRF1.h @@ -110,10 +110,6 @@ /** SPI flash 64KiB erase block size, in bytes */ #define BLADERF_FLASH_EB_SIZE (64 * 1024) -/** Size of the SPI flash, in pages */ -#define BLADERF_FLASH_NUM_PAGES \ - (BLADERF_FLASH_TOTAL_SIZE / BLADERF_FLASH_PAGE_SIZE) - /** Size of the SPI flash, in 64KiB erase blocks */ #define BLADERF_FLASH_NUM_EBS (BLADERF_FLASH_TOTAL_SIZE / BLADERF_FLASH_EB_SIZE) diff --git a/host/libraries/libbladeRF/src/driver/spi_flash.c b/host/libraries/libbladeRF/src/driver/spi_flash.c index f50e50c4..f6cccdfa 100644 --- a/host/libraries/libbladeRF/src/driver/spi_flash.c +++ b/host/libraries/libbladeRF/src/driver/spi_flash.c @@ -49,15 +49,16 @@ static inline int check_eb_access(uint32_t erase_block, uint32_t count) } } -static inline int check_page_access(uint32_t page, uint32_t count) +static inline int check_page_access(struct bladerf *dev, + uint32_t page, uint32_t count) { - if (page >= BLADERF_FLASH_NUM_PAGES) { + if (page >= dev->flash_arch->num_pages) { log_debug("Invalid page: %u\n", page); return BLADERF_ERR_INVAL; - } else if (count > BLADERF_FLASH_NUM_PAGES) { + } else if (count > dev->flash_arch->num_pages) { log_debug("Invalid number of pages: %u\n", count); return BLADERF_ERR_INVAL; - } else if ((page + count) > BLADERF_FLASH_NUM_PAGES) { + } else if ((page + count) > dev->flash_arch->num_pages) { log_debug("Requested operation extends past end of flash: " "page=%u, count=%u\n", page, count); return BLADERF_ERR_INVAL; @@ -80,7 +81,7 @@ int spi_flash_erase(struct bladerf *dev, uint32_t erase_block, uint32_t count) int spi_flash_read(struct bladerf *dev, uint8_t *buf, uint32_t page, uint32_t count) { - int status = check_page_access(page, count); + int status = check_page_access(dev, page, count); if (status == 0) { status = dev->backend->read_flash_pages(dev, buf, page, count); @@ -92,7 +93,7 @@ int spi_flash_read(struct bladerf *dev, uint8_t *buf, int spi_flash_write(struct bladerf *dev, const uint8_t *buf, uint32_t page, uint32_t count) { - int status = check_page_access(page, count); + int status = check_page_access(dev, page, count); if (status == 0) { status = dev->backend->write_flash_pages(dev, buf, page, count);