Some flash drivers don't use DTS write-block-size setting (even though it's set)


Michael Scott
 

Hello Zephyr-devel list,

I noticed today that many of the flash drivers don't make use of the DTS
"write-block-size" setting (STM being the exception):

$ fgrep -nr "write_block_size" drivers/flash
drivers/flash/flash_handlers.c:32:_SYSCALL_HANDLER1_SIMPLE(flash_get_write_block_size,
K_OBJ_DRIVER_FLASH,
drivers/flash/soc_flash_nrf.c:215:    .write_block_size = 1,
drivers/flash/soc_flash_mcux.c:139:    .write_block_size =
FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE,
drivers/flash/flash_sam0.c:369:    .write_block_size = FLASH_PAGE_SIZE,
drivers/flash/flash_stm32.c:228:    .write_block_size =
FLASH_WRITE_BLOCK_SIZE,
drivers/flash/flash_stm32f3x.c:132:    .write_block_size = 2,
drivers/flash/spi_flash_w25qxxdv.c:352:    .write_block_size = 1,
drivers/flash/soc_flash_nios2_qspi.c:435:    .write_block_size =
NIOS2_WRITE_BLOCK_SIZE,
drivers/flash/soc_flash_qmsi.c:261:    .write_block_size = 4,

I know many boards don't have setting in their DTS, but the NXP, nRF and
STM32 and 1 of the Atmel boards have it:

$ fgrep -nr "write-block-size" dts/
dts/bindings/mtd/soc-nv-flash.yaml:29:    write-block-size:
dts/arm/st/stm32f4.dtsi:46:                write-block-size = <1>;
dts/arm/st/stm32l0.dtsi:46:                write-block-size = <4>;
dts/arm/st/stm32f0.dtsi:46:                write-block-size = <2>;
dts/arm/st/stm32l4.dtsi:47:                write-block-size = <8>;
dts/arm/nxp/nxp_kw40z.dtsi:66:                write-block-size = <4>;
dts/arm/nxp/nxp_kw2xd.dtsi:74:                write-block-size = <4>;
dts/arm/nxp/nxp_kl25z.dtsi:38:                write-block-size = <4>;
dts/arm/nxp/nxp_kw41z.dtsi:66:                write-block-size = <4>;
dts/arm/nxp/nxp_k6x.dtsi:82:                write-block-size = <8>;
dts/arm/atmel/samd21.dtsi:41:                write-block-size = <64>;
dts/arm/nordic/nrf52840.dtsi:30:                write-block-size = <4>;
dts/arm/nordic/nrf52832.dtsi:30:                write-block-size = <4>;
dts/arm/nordic/nrf51822.dtsi:30:                write-block-size = <4>;

We have a few areas in the source that use FLASH_WRITE_BLOCK_SIZE (DTS
generated) directly:
(specifically: subsys/dfu/img_util/flash_img.c and
subsys/dfu/boot/mcuboot.c require it to be set):

$ fgrep -nr "FLASH_WRITE_BLOCK_SIZE" .
./drivers/flash/flash_stm32.c:227:#ifdef FLASH_WRITE_BLOCK_SIZE
./drivers/flash/flash_stm32.c:228:    .write_block_size =
FLASH_WRITE_BLOCK_SIZE,
./samples/drivers/flash_shell/src/main.c:239:#if defined
FLASH_WRITE_BLOCK_SIZE
./samples/drivers/flash_shell/src/main.c:240:    printk("%d\n",
FLASH_WRITE_BLOCK_SIZE);
./doc/release-notes-1.11.rst:337:* :github:`5305` - flash: use generated
FLASH_WRITE_BLOCK_SIZE in flash_stm32_api
./subsys/dfu/img_util/flash_img.c:21:BUILD_ASSERT_MSG((CONFIG_IMG_BLOCK_BUF_SIZE
% FLASH_WRITE_BLOCK_SIZE == 0),
./subsys/dfu/img_util/flash_img.c:23:  "FLASH_WRITE_BLOCK_SIZE");
./subsys/dfu/boot/mcuboot.c:70:#define FLASH_MIN_WRITE_SIZE
FLASH_WRITE_BLOCK_SIZE

Worse .. when taking a close look, I see we have 2 *different* settings
for the nRF boards at the moment, since the driver sets a value of 1 and
the DTS all say 4.   Not sure which is correct.

Seems like this could be prone to getting out of sync.

- Mike

Join devel@lists.zephyrproject.org to automatically receive all group messages.