noinit region of RAM also takes up Flash space

Hi,

I'm working with a nRF54L15 within the nRF Connect SDK on Zephyr. I need an array which retains its content through soft resets, so in another RAM section than the usual bss/data. I'm familiar with doing this on projects where I have full control over linker scripts and the likes and used to do this on nRF52 without any issue, but I'm new to Zephyr.

I found this Q/A and the appropriate zephyr macro to achieve this, and it works well. The issue is that my array not only takes up RAM, but also Flash, which doesn't make sense as it's just a static array with no initialization values.

Here's how it's declared:

#include <zephyr/linker/section_tags.h>
#include <zephyr/toolchain.h>
#include <stdint.h> 

static __noinit uint8_t persistent_array[24*1024];
static __noinit uint32_t persistent_crc32;

// .. some functions to read/write in this array

And here's the output of `size -A zephyr.elf`:

build/zephyr/zephyr.elf  :
section                                                                         size        addr
rom_start                                                                       1148           0
text                                                                          155692        1152
.ARM.exidx                                                                         8      156844
initlevel                                                                        168      156852
device_area                                                                      160      157020
sw_isr_table                                                                    2168      157180
_static_thread_data_area                                                          48      159352
bt_l2cap_fixed_chan_area                                                          36      159400
bt_conn_cb_area                                                                   32      159436
bt_gatt_service_static_area                                                       48      159468
settings_handler_static_area                                                     120      159516
tbss                                                                               8      159636
rodata                                                                         12600      159648
.ramfunc                                                                           0   536870912
datas                                                                           2332   536870912
device_states                                                                     16   536873244
k_mem_slab_area                                                                   84   536873260
k_mutex_area                                                                     120   536873344
k_msgq_area                                                                       48   536873464
k_sem_area                                                                        24   536873512
k_event_area                                                                      24   536873536
k_fifo_area                                                                       24   536873560
net_buf_pool_area                                                                308   536873584
._NOINIT_SECTION_NAME."CMAKE_SOURCE_DIR/src/dummy/dummy_array.c".1                 4   536873892
._NOINIT_SECTION_NAME."CMAKE_SOURCE_DIR/src/dummy/dummy_array.c".0             24576   536873896
bss                                                                            13697   536898472
noinit                                                                         22624   536912176
.comment                                                                          64           0
.debug_aranges                                                                 17648           0
.debug_info                                                                  2255551           0
.debug_abbrev                                                                 133539           0
.debug_line                                                                   368703           0
.debug_frame                                                                   48492           0
.debug_str                                                                    157143           0
.debug_loc                                                                    434689           0
.debug_ranges                                                                  57856           0
.ARM.attributes                                                                   56           0
.last_section                                                                      4      199808
Total                                                                        3709862

And the linker summary after building:

Memory region         Used Size  Region Size  %age Used
           FLASH:      199812 B      1524 KB     12.80%
             RAM:       63888 B       256 KB     24.37%
        IDT_LIST:          0 GB        32 KB      0.00%

For comparison, if I set the array size to 4:

Memory region         Used Size  Region Size  %age Used
           FLASH:      175224 B      1524 KB     11.23%
             RAM:       39320 B       256 KB     15.00%
        IDT_LIST:          0 GB        32 KB      0.00%

Is there a way through Zephyr to have such a persistent linker section which only takes up RAM and not Flash ? I don't care what the initial data is, if it wasn't persistent it would just go to .bss.

edit: Forgot to add that this is a fresh new project, so close to nothing changed compared to the base example project following Nordic's tutorial.

Thanks for any help you can provide

  • Hi tf_tdm,

    I tried to do replicate your issue myself with Hello World sample, but I cannot reproduce it. The variables don't take space on FLASH as expected.

    I tried to have another array with initialized value but still .noinit, but runs into some error with the linker trying to put it into bss. I didn't try to further to make it work.

    Could you please give more details about your setup so that I can reproduce it and try to find out what is wrong?

    Hieu

  • Hi Hieu, thanks for looking into this. Could it be related with the nRF Connect SDK version ? I'm on 2.6.99-cs2 , although I just saw in the getting started guide that -cs1 is the one recommended. Or should we take a more recent version, e.g. one of the 2.7.0 tags ?

    Regarding the setup, we build using nrf-docker with very little modifications, sdk_nrf_version=v2.6.99-cs2 as parameter and the toolchain 2.6.0. The Dockerfile is based on nrf-docker hash 8ffb5e32e549c205834ffcc976df615f96715a75 (still the latest commit of the main branch at the time I'm writing this)

  • Hi tf_tdm,

    tf_tdm said:
    Could it be related with the nRF Connect SDK version ? I'm on 2.6.99-cs2 , although I just saw in the getting started guide that -cs1 is the one recommended. Or should we take a more recent version, e.g. one of the 2.7.0 tags ?

    It's hard to tell for sure, but my hunch is that the version doesn't matter. I would try to look at something else first, but you can explore that direction if you wish.

    tf_tdm said:
    Regarding the setup, we build using nrf-docker with very little modifications, sdk_nrf_version=v2.6.99-cs2 as parameter and the toolchain 2.6.0. The Dockerfile is based on nrf-docker hash 8ffb5e32e549c205834ffcc976df615f96715a75 (still the latest commit of the main branch at the time I'm writing this)

    I am honestly unfamiliar with the Docker setup, and I worry that for me to learn it and then set up will take significant amount of time, more so during this busy summertime.

    Could you please try building my project on your setup to see if the issue is reproduced? 
    Here is it: hello_world_261_01.zip

    If not, could you create a minimal setup where you reproduce the issue and send it to me?

    Hieu

Related