zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.93k stars 6.65k forks source link

DRAM overflow of .bss.sector_buffers when slot partition is bigger then 4MB on esp32s3 (N16R8) #80138

Closed FacepalmMute closed 3 weeks ago

FacepalmMute commented 1 month ago

After adjusting my flash map, I noticed the following error.

This error occurs whenever either of the two slot partitions is assigned more than 4MB. In the case above, it was assigned 6MB.

A comparison of the ´zephyr_pre0.map´ from both compilations shows that sector_buffers requires more DRAM.

As a workaround, I increased ´BOOTLOADER_DRAM_SEG_LEN´ in ´zephyr/soc/espressif/esp32s3/memory.h´ by 0x2000. The error no longer occurs, but I am not sure about the side effects in regards to secure boot and other security features.

This issue is originally opened at mcuboot repo: https://github.com/mcu-tools/mcuboot/issues/2094

Update: I've gathered a few more insights:

The sector_buffers reserve 12 bytes for each sector (4KB of flash) for both arrays. So, <(partition_size / 4000) 12 2> bytes are allocated in .bss.sector_buffers. This explains why the DRAM overflows when the partition size exceeds a certain limit.

Update 2: At the end it seems that only 16 bytes per sector is used (based on calculations with zephyr_pre0.map)

To fix this, the limit would need to adjusted based on the number of sectors.

To Reproduce

Steps to reproduce the behavior:

  1. build any example project with esp32s3 with --sysbuild
  2. increase any image-slot in partition table to a size > 4MB
  3. See error

Expected behavior BOOTLOADER_DRAM_SEG_LEN should also consider the maximal sectors and adjust respectively.

Impact

We cannot use our full flash storage for image OTA.

Logs and console output

/usr/local/zephyr-sdk-0.16.8/xtensa-espressif_esp32s3_zephyr-elf/bin/../lib/gcc/xtensa-espressif_esp32s3_zephyr-elf/12.2.0/../../../../xtensa-espressif_esp32s3_zephyr-elf/bin/ld.bfd: zephyr/zephyr_pre0.elf section '.bss' will not fit in region 'dram_seg'
/usr/local/zephyr-sdk-0.16.8/xtensa-espressif_esp32s3_zephyr-elf/bin/../lib/gcc/xtensa-espressif_esp32s3_zephyr-elf/12.2.0/../../../../xtensa-espressif_esp32s3_zephyr-elf/bin/ld.bfd: DRAM segment data does not fit.
/usr/local/zephyr-sdk-0.16.8/xtensa-espressif_esp32s3_zephyr-elf/bin/../lib/gcc/xtensa-espressif_esp32s3_zephyr-elf/12.2.0/../../../../xtensa-espressif_esp32s3_zephyr-elf/bin/ld.bfd: region `dram_seg' overflowed by 7152 bytes

Environment:

github-actions[bot] commented 1 month ago

Hi @FacepalmMute! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙