drivers: spi_nor: improve documentation and validation on flash layout size

The smallest region that can be erashed is one sector, so setting
SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=2048 will fail at runtime when the
flash page API is used to erase a single (or misaligned) page.  Add a
compile-time check that the requested layout page size is erasable.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2019-10-29 05:18:46 -05:00 committed by Carles Cufí
parent 98a344fe21
commit 2d4d6f05e6
2 changed files with 5 additions and 1 deletions

View file

@ -29,7 +29,8 @@ config SPI_NOR_FLASH_LAYOUT_PAGE_SIZE
When CONFIG_FLASH_PAGE_LAYOUT is used this driver will support
that API. By default the page size corresponds to the block
size (65536). Other options include the 32K-byte erase size
(32768), and the sector size (4096).
(32768), the sector size (4096), or any non-zero multiple of the
sector size.
config SPI_NOR_IDLE_IN_DPD
bool "Use Deep Power-Down mode when flash is not being accessed."

View file

@ -528,6 +528,9 @@ static int spi_nor_init(struct device *dev)
/* instance 0 size in bytes */
#define INST_0_BYTES (DT_INST_0_JEDEC_SPI_NOR_SIZE / 8)
BUILD_ASSERT_MSG(SPI_NOR_IS_SECTOR_ALIGNED(CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE),
"SPI_NOR_FLASH_LAYOUT_PAGE_SIZE must be multiple of 4096");
/* instance 0 page count */
#define LAYOUT_PAGES_COUNT (INST_0_BYTES / CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE)