Reserving internal flash for user data

nRF52832 & nRF Connect SDK 2.6.1

We would like to reserve some internal flash for user configuration data that would be written in production like

nrfjprog -f NRF52 --erasepage 0x7F000
nrfjprog -f NRF52 --memwr 0x07F000 --val <data0> --verify
nrfjprog -f NRF52 --memwr 0x07F004 --val <data1> --verify
...

and read by FW but never modified by FW.

So we shrank the "storage" partition and added a custom partition in our *.dts:

&flash0 {
    partitions {
        compatible = "fixed-partitions";
        #address-cells = <1>;
        #size-cells = <1>;

        boot_partition: partition@0 {
            label = "mcuboot";
            reg = <0x0 0xc000>;
        };
        slot0_partition: partition@c000 {
            label = "image-0";
            reg = <0xc000 0x32000>;
        };
        slot1_partition: partition@3e000 {
            label = "image-1";
            reg = <0x3e000 0x32000>;
        };
        scratch_partition: partition@70000 {
            label = "image-scratch";
            reg = <0x70000 0xa000>;
        };
        storage_partition: partition@7a000 {
            label = "storage";
            reg = <0x7a000 0x5000>;
        };
        config_partition: partition@7f000 {
            label = "config";
            reg = <0x7f000 0x1000>;
        };
    };
};

Is this enough to guarantee that this last flash page will neither be used by anything else (NVM, code, ...) nor erased or written to during FW flashing?

  • Thank you. In the meantime, I found a 2nd solution:

    - Put a custom.ld file in project folder with the following lines:

    .version_section 0x3DFC0 :
    {
    PROVIDE(__version_section_start = .);
    KEEP(*(.version_section))
    PROVIDE(__version_section_end = .);
    } > FLASH
    

    - Add the following line to CMakeLists.txt:

    zephyr_linker_sources(SECTIONS custom.ld)

    - Define your variable that will be put to the address specified in custom.ld:

    static const uint32_t FW_VERSION __attribute__((section(".version_section"))) __attribute__((used)) = 0x12345678;

Related