I've spent a couple days researching how to write a small amount of data to the storage_partition that is fairly standard in Nordic devicetrees. I haven't been successful and am looking for guidance.
My setup: nrf Connect SDK v2.2.0, Zephyr, nrf52840, using MCUBoot for DFU updates. I believe the fact that my application uses MCUBoot is the crucial bit of information.
Here's my board's Devicetree for the flash partitions.
&flash0 { partitions { compatible = "fixed-partitions"; #address-cells = <1>; #size-cells = <1>; boot_partition: partition@0 { label = "mcuboot"; reg = <0x000000000 0x0000C000>; }; slot0_partition: partition@c000 { label = "image-0"; reg = <0x0000C000 0x00067000>; }; slot1_partition: partition@73000 { label = "image-1"; reg = <0x00073000 0x00067000>; }; scratch_partition: partition@da000 { label = "image-scratch"; reg = <0x000da000 0x0001e000>; }; /* * The flash starting at 0x000f8000 and ending at * 0x000fffff is reserved for use by the application. */ /* * Storage partition will be used by FCB/LittleFS/NVS * if enabled. */ storage_partition: partition@f8000 { label = "storage"; reg = <0x000f8000 0x00008000>; }; }; };
I am able to successfully build and run the following sample program for the nrf52840 DK. This sample does not assume MCUBoot is present.
If I import this sample into my application and board, which includes MCUBoot, it fails. Note that I've changed "slot1_partition" to "storage_partition". It works completely fine if I leave TEST_PARTITION as "slot1_partition".
#ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE #define TEST_PARTITION storage_partition #else #define TEST_PARTITION storage_partition #endif #define TEST_PARTITION_OFFSET FIXED_PARTITION_OFFSET(TEST_PARTITION) #define TEST_PARTITION_DEVICE FIXED_PARTITION_DEVICE(TEST_PARTITION) #define FLASH_PAGE_SIZE 4096 #define TEST_DATA_WORD_0 0x1122 #define TEST_DATA_WORD_1 0xaabb #define TEST_DATA_WORD_2 0xabcd #define TEST_DATA_WORD_3 0x1234 #define FLASH_TEST_OFFSET2 0x41234 #define FLASH_TEST_PAGE_IDX 37 void main(void) { const struct device *flash_dev = TEST_PARTITION_DEVICE; uint32_t buf_array_1[4] = { TEST_DATA_WORD_0, TEST_DATA_WORD_1, TEST_DATA_WORD_2, TEST_DATA_WORD_3 }; uint32_t buf_array_2[4] = { TEST_DATA_WORD_3, TEST_DATA_WORD_1, TEST_DATA_WORD_2, TEST_DATA_WORD_0 }; uint32_t buf_array_3[8] = { TEST_DATA_WORD_0, TEST_DATA_WORD_1, TEST_DATA_WORD_2, TEST_DATA_WORD_3, TEST_DATA_WORD_0, TEST_DATA_WORD_1, TEST_DATA_WORD_2, TEST_DATA_WORD_3 }; uint32_t buf_word = 0U; uint32_t i, offset; printf("\nNordic nRF5 Flash Testing\n"); printf("=========================\n"); if (!device_is_ready(flash_dev)) { printf("Flash device not ready\n"); return; } .....
The primary symptom here is that TEST_PARTITION_DEVICE gets processed as NULL, so the device is null and the device_is_ready() test fails.
So to summarize, my MCUBoot-enabled project cannot access storage_partition. It can access slot1_partition.
I've looked into possibly using pm_static.yml, but when I define the storage partition there, my application images don't get placed in the flash.
It would be wonderful if there were a simple way I could add the definition of the storage_partition only, or even better, directly use the devicetree's specification of the storage_partition.
Thanks in advance for looking into this.
Best,
Steve