Skip to content

Commit 2d4d6f0

Browse files
pabigotcarlescufi
authored andcommitted
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 <[email protected]>
1 parent 98a344f commit 2d4d6f0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

drivers/flash/Kconfig.nor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ config SPI_NOR_FLASH_LAYOUT_PAGE_SIZE
2929
When CONFIG_FLASH_PAGE_LAYOUT is used this driver will support
3030
that API. By default the page size corresponds to the block
3131
size (65536). Other options include the 32K-byte erase size
32-
(32768), and the sector size (4096).
32+
(32768), the sector size (4096), or any non-zero multiple of the
33+
sector size.
3334

3435
config SPI_NOR_IDLE_IN_DPD
3536
bool "Use Deep Power-Down mode when flash is not being accessed."

drivers/flash/spi_nor.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,9 @@ static int spi_nor_init(struct device *dev)
528528
/* instance 0 size in bytes */
529529
#define INST_0_BYTES (DT_INST_0_JEDEC_SPI_NOR_SIZE / 8)
530530

531+
BUILD_ASSERT_MSG(SPI_NOR_IS_SECTOR_ALIGNED(CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE),
532+
"SPI_NOR_FLASH_LAYOUT_PAGE_SIZE must be multiple of 4096");
533+
531534
/* instance 0 page count */
532535
#define LAYOUT_PAGES_COUNT (INST_0_BYTES / CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE)
533536

0 commit comments

Comments
 (0)