From b8322f95fe142544a55023fd50eac217c8fd89d7 Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Mon, 21 Oct 2024 15:08:10 +0200 Subject: [PATCH 01/10] boards: st: nucleo_f207zg: Rework flash partition STM32F2 series flash layout is as follows: {.pages_count = 4, .pages_size = KB(16)}, {.pages_count = 1, .pages_size = KB(64)}, {.pages_count = 7, .pages_size = KB(128)} Since NVS subsys requires 2 sectors of max 32K in total, provide a flash partition which respects this constraint using 2 of the 16K sectors in the beginning of the layout. Provide a compatible flash partition usable with mcuboot, but keep the storage partition commented as its usage is not compatible with use w/o mcuboot enabled (in this case main image starts as offset 0 which conflicts with storage partition). Note that it isn't possible either to get main image starting directly in the 128K sectors w/o bootloader as boot flash address can't be configured. Signed-off-by: Erwan Gouriou --- boards/st/nucleo_f207zg/nucleo_f207zg.dts | 30 +++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/boards/st/nucleo_f207zg/nucleo_f207zg.dts b/boards/st/nucleo_f207zg/nucleo_f207zg.dts index 0c8d36af39bd9..4f3e8cafde3aa 100644 --- a/boards/st/nucleo_f207zg/nucleo_f207zg.dts +++ b/boards/st/nucleo_f207zg/nucleo_f207zg.dts @@ -197,12 +197,32 @@ zephyr_udc0: &usbotg_fs { #address-cells = <1>; #size-cells = <1>; - /* Last sector of size 128KB at the end of 1MB flash is set - * for storage. + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x0 DT_SIZE_K(32)>; + read-only; + }; + + /* + * nvs subsystem requires 2 sectors with a max total of 32K + * On F2 series, the only option is to use the following + * partition, which is compatible with mcuboot usage. + * Keep it commented in order it is not used by CI. + * + * storage_partition: partition@8000 { + * label = "storage"; + * reg = <0x8000 DT_SIZE_K(32)>; + * }; */ - storage_partition: partition@e0000 { - label = "storage"; - reg = <0x000e0000 DT_SIZE_K(128)>; + + slot0_partition: partition@20000 { + label = "image-0"; + reg = <0x20000 DT_SIZE_K(448)>; + }; + + slot1_partition: partition@90000 { + label = "image-1"; + reg = <0x90000 DT_SIZE_K(448)>; }; }; }; From fd2e2f919b44a915e5767b48d802fa210b34411a Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Mon, 21 Oct 2024 15:09:06 +0200 Subject: [PATCH 02/10] boards: st: b_l4s5i_iot01a: Rework flash partition Rework flash partition to make use of the whole 2M of flash. Signed-off-by: Erwan Gouriou --- boards/st/b_l4s5i_iot01a/b_l4s5i_iot01a.dts | 24 +++++++-------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/boards/st/b_l4s5i_iot01a/b_l4s5i_iot01a.dts b/boards/st/b_l4s5i_iot01a/b_l4s5i_iot01a.dts index d41c75c44bf0d..064d61fb69108 100644 --- a/boards/st/b_l4s5i_iot01a/b_l4s5i_iot01a.dts +++ b/boards/st/b_l4s5i_iot01a/b_l4s5i_iot01a.dts @@ -181,31 +181,23 @@ boot_partition: partition@0 { label = "mcuboot"; - reg = <0x00000000 DT_SIZE_K(64)>; + reg = <0x0 DT_SIZE_K(64)>; read-only; }; - /* - * The flash starting at offset 0x10000 and ending at - * offset 0x1ffff is reserved for use by the application. - */ - - slot0_partition: partition@20000 { + slot0_partition: partition@1000 { label = "image-0"; - reg = <0x00020000 DT_SIZE_K(432)>; + reg = <0x1000 DT_SIZE_K(976)>; }; - slot1_partition: partition@8c000 { + + slot1_partition: partition@104000 { label = "image-1"; - reg = <0x0008C000 DT_SIZE_K(432)>; - }; - scratch_partition: partition@f8000 { - label = "image-scratch"; - reg = <0x000F8000 DT_SIZE_K(16)>; + reg = <0x104000 DT_SIZE_K(976)>; }; - storage_partition: partition@fc000 { + storage_partition: partition@1f8000 { label = "storage"; - reg = <0x000fc000 DT_SIZE_K(16)>; + reg = <0x1f8000 DT_SIZE_K(32)>; }; }; }; From 676d30eb8c17670f043bd12762218e2da54e05a3 Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Mon, 21 Oct 2024 15:10:33 +0200 Subject: [PATCH 03/10] boards: st: disco_l475_iot1: Rework flash partition Rework flash partition to provide a storage partition and 2 image slots. Signed-off-by: Erwan Gouriou --- boards/st/disco_l475_iot1/disco_l475_iot1.dts | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/boards/st/disco_l475_iot1/disco_l475_iot1.dts b/boards/st/disco_l475_iot1/disco_l475_iot1.dts index fbea236337d4e..33e6d973cf89c 100644 --- a/boards/st/disco_l475_iot1/disco_l475_iot1.dts +++ b/boards/st/disco_l475_iot1/disco_l475_iot1.dts @@ -224,23 +224,18 @@ boot_partition: partition@0 { label = "mcuboot"; - reg = <0x00000000 DT_SIZE_K(64)>; + reg = <0x0 DT_SIZE_K(64)>; read-only; }; - /* - * The flash starting at offset 0x10000 and ending at - * offset 0x1ffff is reserved for use by the application. - */ - - slot0_partition: partition@20000 { + slot0_partition: partition@1000 { label = "image-0"; - reg = <0x00020000 DT_SIZE_K(864)>; + reg = <0x1000 DT_SIZE_K(928)>; }; - scratch_partition: partition@f8000 { - label = "image-scratch"; - reg = <0x000F8000 DT_SIZE_K(16)>; + storage_partition: partition@f8000 { + label = "storage"; + reg = <0xf8000 DT_SIZE_K(32)>; }; }; }; @@ -343,8 +338,8 @@ zephyr_udc0: &usbotg_fs { reg = <0x00000000 DT_SIZE_K(864)>; }; - storage_partition: partition@d8000 { - label = "storage"; + slot2_partition: partition@d8000 { + label = "image-3"; reg = <0x000d8000 DT_SIZE_M(7)>; }; }; From 4da38c06ee793d110f125b62e24f5335b4551b33 Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Mon, 21 Oct 2024 15:14:28 +0200 Subject: [PATCH 04/10] boards: st: nucleo_g07xrb: Rework storage partition NVS susbsystem requires a slot covering 2 sectors of flash, which should be at minimum 4K on G0 series which provised 2K sectors. Signed-off-by: Erwan Gouriou --- boards/st/nucleo_g070rb/nucleo_g070rb.dts | 6 +++--- boards/st/nucleo_g071rb/nucleo_g071rb.dts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/boards/st/nucleo_g070rb/nucleo_g070rb.dts b/boards/st/nucleo_g070rb/nucleo_g070rb.dts index 7e976c930594b..d0491570d1dee 100644 --- a/boards/st/nucleo_g070rb/nucleo_g070rb.dts +++ b/boards/st/nucleo_g070rb/nucleo_g070rb.dts @@ -155,10 +155,10 @@ #address-cells = <1>; #size-cells = <1>; - /* Set 2KB of storage at the end of 128KB flash */ - storage_partition: partition@1f800 { + /* Set 4KB of storage at the end of 128KB flash */ + storage_partition: partition@1f000 { label = "storage"; - reg = <0x0001f800 DT_SIZE_K(2)>; + reg = <0x0001f000 DT_SIZE_K(4)>; }; }; }; diff --git a/boards/st/nucleo_g071rb/nucleo_g071rb.dts b/boards/st/nucleo_g071rb/nucleo_g071rb.dts index 6bfd17bd89398..553feebd2e959 100644 --- a/boards/st/nucleo_g071rb/nucleo_g071rb.dts +++ b/boards/st/nucleo_g071rb/nucleo_g071rb.dts @@ -169,10 +169,10 @@ #address-cells = <1>; #size-cells = <1>; - /* Set 2KB of storage at the end of 128KB flash */ - storage_partition: partition@1f800 { + /* Set 4KB of storage at the end of 128KB flash */ + storage_partition: partition@1f000 { label = "storage"; - reg = <0x0001f800 DT_SIZE_K(2)>; + reg = <0x0001f000 DT_SIZE_K(4)>; }; }; }; From 0461534963e668eb363c4b0e90ccada67017f2ea Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Mon, 21 Oct 2024 15:25:02 +0200 Subject: [PATCH 05/10] boards: st: nucleo_l152re: Rework storage partition NVS susbsystem requires a slot covering 2 sectors of flash, which should be at minimum 8K on L1 series which provides 4K sectors. Signed-off-by: Erwan Gouriou --- boards/st/nucleo_l152re/nucleo_l152re.dts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boards/st/nucleo_l152re/nucleo_l152re.dts b/boards/st/nucleo_l152re/nucleo_l152re.dts index fc308f5988fe3..afcccc8dd01db 100644 --- a/boards/st/nucleo_l152re/nucleo_l152re.dts +++ b/boards/st/nucleo_l152re/nucleo_l152re.dts @@ -145,10 +145,10 @@ #address-cells = <1>; #size-cells = <1>; - /* Set 2KB of storage at the end of 512KB flash */ - storage_partition: partition@7f800 { + /* Set 8KB of storage at the end of 512KB flash */ + storage_partition: partition@7e000 { label = "storage"; - reg = <0x0007f800 DT_SIZE_K(2)>; + reg = <0x0007e000 DT_SIZE_K(8)>; }; }; }; From 3b7ed48749f2022099e235360a0b61275f827adb Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Tue, 22 Oct 2024 18:24:11 +0200 Subject: [PATCH 06/10] tests: psa: its: Extend Timeout These tests could be long on slow targets Signed-off-by: Erwan Gouriou --- tests/subsys/secure_storage/psa/its/testcase.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/subsys/secure_storage/psa/its/testcase.yaml b/tests/subsys/secure_storage/psa/its/testcase.yaml index 0261c7961a370..c59c58532b493 100644 --- a/tests/subsys/secure_storage/psa/its/testcase.yaml +++ b/tests/subsys/secure_storage/psa/its/testcase.yaml @@ -3,7 +3,7 @@ common: - native_sim platform_exclude: - qemu_cortex_m0 # settings subsystem initialization fails - timeout: 120 + timeout: 600 tags: - psa.secure_storage tests: From c5caa125561ae99e4c65146522289da58a7c1745 Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Wed, 13 Nov 2024 16:49:00 +0100 Subject: [PATCH 07/10] boards: st: nucleo_f429zi: Rework flash partition STM32F4 series flash layout is as follows: {.pages_count = 4, .pages_size = KB(16)}, {.pages_count = 1, .pages_size = KB(64)}, {.pages_count = 7, .pages_size = KB(128)} Since NVS subsys requires 2 sectors of max 32K in total, provide a flash partition which respects this constraint using 2 of the 16K sectors in the beginning of the layout. Provide a compatible flash partition usable with mcuboot, but keep the storage partition commented as its usage is not compatible with use w/o mcuboot enabled (in this case main image starts as offset 0 which conflicts with storage partition). Note that it isn't possible either to get main image starting directly in the 128K sectors w/o bootloader as boot flash address can't be configured. Signed-off-by: Erwan Gouriou --- boards/st/nucleo_f429zi/nucleo_f429zi.dts | 20 +++++++++++++------- boards/st/nucleo_f429zi/nucleo_f429zi.yaml | 1 - 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/boards/st/nucleo_f429zi/nucleo_f429zi.dts b/boards/st/nucleo_f429zi/nucleo_f429zi.dts index 2e37e448655ac..29a36b1155573 100644 --- a/boards/st/nucleo_f429zi/nucleo_f429zi.dts +++ b/boards/st/nucleo_f429zi/nucleo_f429zi.dts @@ -194,18 +194,24 @@ zephyr_udc0: &usbotg_fs { #address-cells = <1>; #size-cells = <1>; - /* 64KB for bootloader */ + /* 32KB for bootloader */ boot_partition: partition@0 { label = "mcuboot"; - reg = <0x00000000 DT_SIZE_K(64)>; + reg = <0x00000000 DT_SIZE_K(32)>; read-only; }; - /* storage: 64KB for settings */ - storage_partition: partition@10000 { - label = "storage"; - reg = <0x00010000 DT_SIZE_K(64)>; - }; + /* + * nvs subsystem requires 2 sectors with a max total of 32K + * On F4 series, the only option is to use the following + * partition, which is compatible with mcuboot usage. + * Keep it commented in order it is not used by CI. + * + * storage_partition: partition@8000 { + * label = "storage"; + * reg = <0x0008000 DT_SIZE_K(32)>; + * }; + */ /* application image slot: 256KB */ slot0_partition: partition@20000 { diff --git a/boards/st/nucleo_f429zi/nucleo_f429zi.yaml b/boards/st/nucleo_f429zi/nucleo_f429zi.yaml index 8674acc45c831..bec17951950bc 100644 --- a/boards/st/nucleo_f429zi/nucleo_f429zi.yaml +++ b/boards/st/nucleo_f429zi/nucleo_f429zi.yaml @@ -23,7 +23,6 @@ supported: - adc - dac - dma - - nvs - rtc - usbd vendor: st From 8c68f5c1175fd9a5011da5e860512ee214e2b695 Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Thu, 14 Nov 2024 17:58:55 +0100 Subject: [PATCH 08/10] test: drivers: flash: common: Copied size can't exceed page.size flash_copy() is performed on a page.size span but following flash_read() verification step is performed on EXPECTED_SIZE length (512). This doesn't work on devices where page.size is lower than EXPECTED_SIZE, such as STM32L1 where page size is 256. To fix this, perform verification on the smalest value between page.size and EXPECTED_SIZE. Signed-off-by: Erwan Gouriou --- tests/drivers/flash/common/src/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/drivers/flash/common/src/main.c b/tests/drivers/flash/common/src/main.c index f7f7c6ee64ee7..a30f533f655d8 100644 --- a/tests/drivers/flash/common/src/main.c +++ b/tests/drivers/flash/common/src/main.c @@ -397,8 +397,10 @@ static void test_flash_copy_inner(const struct device *src_dev, off_t src_offset if ((expected_result == 0) && (size != 0) && (src_offset != dst_offset)) { /* verify a successful copy */ - zassert_ok(flash_read(flash_dev, TEST_AREA_OFFSET, expected, EXPECTED_SIZE)); - for (int i = 0; i < EXPECTED_SIZE; i++) { + off_t copy_size = MIN(size, EXPECTED_SIZE); + + zassert_ok(flash_read(flash_dev, TEST_AREA_OFFSET, expected, copy_size)); + for (int i = 0; i < copy_size; i++) { zassert_equal(buf[i], 0xaa, "incorrect data (%02x) at %d", buf[i], i); } } From e610d2bae06704e09baa890d0b777cfbe864c727 Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Fri, 15 Nov 2024 09:14:24 +0100 Subject: [PATCH 09/10] tests: drivers: flash: common: Remove stm32 specific test It's same test as "default", but more restrictive target wise. Signed-off-by: Erwan Gouriou --- tests/drivers/flash/common/testcase.yaml | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/drivers/flash/common/testcase.yaml b/tests/drivers/flash/common/testcase.yaml index 4c53bbba0840c..5b053e27321cd 100644 --- a/tests/drivers/flash/common/testcase.yaml +++ b/tests/drivers/flash/common/testcase.yaml @@ -46,28 +46,6 @@ tests: and dt_label_with_parent_compat_enabled("storage_partition", "fixed-partitions")) integration_platforms: - nrf9161dk/nrf9161/ns - drivers.flash.common.stm32: - platform_allow: - - nucleo_f103rb - - nucleo_f207zg - - stm32f3_disco - - nucleo_f429zi - - stm32f746g_disco - - nucleo_f767zi - - nucleo_g0b1re - - nucleo_g474re - - nucleo_h743zi - - nucleo_l152re - - disco_l475_iot1 - - nucleo_wb55rg - - nucleo_wl55jc - - stm32l562e_dk - - stm32l562e_dk/stm32l562xx/ns - integration_platforms: - - nucleo_f103rb - filter: (dt_compat_enabled("st,stm32-flash-controller") or - dt_compat_enabled("st,stm32h7-flash-controller")) and - dt_label_with_parent_compat_enabled("storage_partition", "fixed-partitions") drivers.flash.common.mx25r_high_perf: platform_allow: nrf52840dk/nrf52840 extra_args: From 9e658e761bbd7ba67f8772e32e4201558c86fe9e Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Fri, 15 Nov 2024 15:05:34 +0100 Subject: [PATCH 10/10] samples: subsys: nvs: stm32 overlays fixup Don't try to delete partitions that doesn't exist anymore Signed-off-by: Erwan Gouriou --- samples/subsys/nvs/boards/disco_l475_iot1.overlay | 1 - samples/subsys/nvs/boards/nucleo_f429zi.overlay | 2 -- 2 files changed, 3 deletions(-) diff --git a/samples/subsys/nvs/boards/disco_l475_iot1.overlay b/samples/subsys/nvs/boards/disco_l475_iot1.overlay index 2c304977ce529..786a8ff489a10 100644 --- a/samples/subsys/nvs/boards/disco_l475_iot1.overlay +++ b/samples/subsys/nvs/boards/disco_l475_iot1.overlay @@ -5,7 +5,6 @@ */ -/delete-node/ &scratch_partition; /delete-node/ &storage_partition; / { diff --git a/samples/subsys/nvs/boards/nucleo_f429zi.overlay b/samples/subsys/nvs/boards/nucleo_f429zi.overlay index bf5a3ad768b88..43960ce3df6d5 100644 --- a/samples/subsys/nvs/boards/nucleo_f429zi.overlay +++ b/samples/subsys/nvs/boards/nucleo_f429zi.overlay @@ -4,8 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -/delete-node/ &storage_partition; - &flash0 { partitions { /* Set 48KB of storage at the beginning of bank2 in order to have 3 sectors smaller than 32K