Avoid nonit region to be overridden by MCUBoot

Hi,

I'm using the nRF Connect SDK 2.5.1 with the nRF5340 and MCUBoot as bootloader. I want to store some information about the reboot reason (and some other stuff) in the noinit region to save it across a restart. I placed the variables in the noinit region like this:

static __noinit volatile unsigned int reset_reason;

But on the next boot my whole noinit region is set to 0xFF. I think this comes from MCUBoot as in the map files I can see the noinit region of my application overlaps with the mock_flash region of the flash simulator from MCUBoot (which is needed to transfer the image to the network core afaik). The answer here does not provide a soultion for that, even though the question seems similar.

build/mcuboot/zephyr/zephyr.map:

 .bss.mock_flash
                0x00000000200060da    0x40000 zephyr/drivers/flash/libdrivers__flash.a(flash_simulator.c.obj)

build/zephyr/zephyr.map:

noinit          0x000000002001af70    0x13888
 *(SORT_BY_ALIGNMENT(.noinit))
 *(SORT_BY_ALIGNMENT(.noinit.*))
...

What is the proper way to keep my noinit section? Please give an example if possible.

Best regards,
Lars

Parents
  • Colar,

    I think it is a bit complicated and untested waters to try to edit MCUboot linker scripts to sync it with application specific mem regions.

    But there is this retention system that you try to use. Configuring the DTS seems the biggest part in it but use in the source code seems quite simple.

  • Hi,

    thanks, that seems to work. When using the device tree as in the retention system the RAM partition is reduced for all images including MCUBoot, so the retention section will then only used by the retention system (it takes the address then from the device tree).

    Besides using the retention API it is also possible to just declare a memory section in the device tree and then place variables in there with __attribute__((__section__(".anotherretainedsection"))).

    Here is an example device tree overlay for a nRF5340:

    / {
        soc {
            sram0: memory@20000000 {
                compatible = "mmio-sram";
                reg = <0x20000000 0x7e000>;  // reduce SRAM size 
            };
    
            retentionram: memory@2007f000 {  // new node for the retention RAM
                compatible = "zephyr,memory-region", "mmio-sram";
                reg = <0x2007f000 0x1000>;
                zephyr,memory-region = "RetainedMem";
                status = "okay";
    
                retainedmem {
                    compatible = "zephyr,retained-ram";
                    status = "okay";
                    #address-cells = <1>;
                    #size-cells = <1>;
    
                    /* This creates a 256-byte partition */
                    retention0: retention@0 {
                        compatible = "zephyr,retention";
                        status = "okay";
                        reg = <0x0 0x100>;  // adjust this and other partitions as necessary
                        prefix = [08 04];
                        checksum = <1>;
                    };
                };
            };
    
            anotherretainedsection: memory@2007e000 {  // new node for the retention RAM
                compatible = "zephyr,memory-region", "mmio-sram";
                reg = <0x2007e000 0x1000>;
                zephyr,memory-region = "anotherretainedsection";
                status = "okay";
            };
        };
    
    };

    Best regards,
    Lars

Reply
  • Hi,

    thanks, that seems to work. When using the device tree as in the retention system the RAM partition is reduced for all images including MCUBoot, so the retention section will then only used by the retention system (it takes the address then from the device tree).

    Besides using the retention API it is also possible to just declare a memory section in the device tree and then place variables in there with __attribute__((__section__(".anotherretainedsection"))).

    Here is an example device tree overlay for a nRF5340:

    / {
        soc {
            sram0: memory@20000000 {
                compatible = "mmio-sram";
                reg = <0x20000000 0x7e000>;  // reduce SRAM size 
            };
    
            retentionram: memory@2007f000 {  // new node for the retention RAM
                compatible = "zephyr,memory-region", "mmio-sram";
                reg = <0x2007f000 0x1000>;
                zephyr,memory-region = "RetainedMem";
                status = "okay";
    
                retainedmem {
                    compatible = "zephyr,retained-ram";
                    status = "okay";
                    #address-cells = <1>;
                    #size-cells = <1>;
    
                    /* This creates a 256-byte partition */
                    retention0: retention@0 {
                        compatible = "zephyr,retention";
                        status = "okay";
                        reg = <0x0 0x100>;  // adjust this and other partitions as necessary
                        prefix = [08 04];
                        checksum = <1>;
                    };
                };
            };
    
            anotherretainedsection: memory@2007e000 {  // new node for the retention RAM
                compatible = "zephyr,memory-region", "mmio-sram";
                reg = <0x2007e000 0x1000>;
                zephyr,memory-region = "anotherretainedsection";
                status = "okay";
            };
        };
    
    };

    Best regards,
    Lars

Children
No Data
Related