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.52k stars 6.45k forks source link

esp32s3 does not build with mcuboot and CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256 or CONFIG_BOOT_SIGNATURE_TYPE_RSA #76566

Closed brandon-exact closed 1 hour ago

brandon-exact commented 1 month ago

Describe the bug

esp32s3 iram overflows when trying to build with mcuboot and CONFIG_BOOT_SIGNATURE_TYPE_* To Reproduce

diff --git a/samples/sysbuild/with_mcuboot/sysbuild.conf b/samples/sysbuild/with_mcuboot/sysbuild.conf
index 92042e44734..bbf9149c359 100644
--- a/samples/sysbuild/with_mcuboot/sysbuild.conf
+++ b/samples/sysbuild/with_mcuboot/sysbuild.conf
@@ -2,3 +2,4 @@

 # Enable MCUboot per default for this sample.
 SB_CONFIG_BOOTLOADER_MCUBOOT=y
+SB_CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y
cd zephyr/samples/sysbuild/with_mcuboot
west build -b esp32s3_devkitc/esp32s3/procpu --sysbuild

Expected behavior

The sample builds Impact

cannot use mcuboot and esp32s3 Logs and console output

/home/brandon/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 `.iram0.text' will not fit in region `iram_seg'
/home/brandon/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: section .iram0.loader_text LMA [00000000403c6400,00000000403c7c77] overlaps section .iram0.text LMA [00000000403bc000,00000000403c6863]
/home/brandon/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 `iram_seg' overflowed by 1124 bytes

Environment (please complete the following information):

brandon-exact commented 1 month ago

If I modify memory.h to get it to compile

diff --git a/soc/espressif/esp32s3/memory.h b/soc/espressif/esp32s3/memory.h
index cd9a0ef984b..5dc2b3aa633 100644
--- a/soc/espressif/esp32s3/memory.h
+++ b/soc/espressif/esp32s3/memory.h
@@ -45,9 +45,9 @@

 /* For safety margin between bootloader data section and startup stacks */
 #define BOOTLOADER_STACK_OVERHEAD      0x0
-#define BOOTLOADER_DRAM_SEG_LEN        0x8000
+#define BOOTLOADER_DRAM_SEG_LEN        0xa000
 #define BOOTLOADER_IRAM_LOADER_SEG_LEN 0x1a00
-#define BOOTLOADER_IRAM_SEG_LEN        0xa800
+#define BOOTLOADER_IRAM_SEG_LEN        0xc800

I get a boot loop of

Checksum failure. Calculated 0xe5 stored 0x3c
ets_main.c 329 
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x7 (TG0WDT_SYS_RST),boot:0xa (SPI_FAST_FLASH_BOOT)
Saved PC:0x40043ac8
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fcbfc00,len:0x3094
load:0x403b9c00,len:0xc258
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x10 (RTCWDT_RTC_RST),boot:0xa (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fcbfc00,len:0x3094
load:0x403b9c00,len:0xc258
load:0x403c6400,len:0x1898
Checksum failure. Calculated 0xe5 stored 0x3c
ets_main.c 329 
brandon-exact commented 1 month ago

Is there going to be a fix for this in the next 3-4 months? Thanks!

sylvioalves commented 1 month ago

@brandon-exact Really sorry I missed this. I have just tried using latest main and I get no overflow issues. Would you retry?

brandon-exact commented 4 weeks ago

@sylvioalves I tried on main and still get the same overflow. I ran west update and west blobs fetch hal_espressif

sylvioalves commented 4 weeks ago

@brandon-exact, would you manually increase the iram size for the mcuboot bootloader? https://github.com/zephyrproject-rtos/zephyr/blob/main/soc/espressif/esp32s3/memory.h#L50

#define BOOTLOADER_IRAM_SEG_LEN 0xb000

@marekmatej PTAL.

Edit: I see that you already tried and it worked. This is indeed the resolution for the overflow issue. We will check whether there is an alternative way to improve it somehow.

marekmatej commented 4 weeks ago

I think we could increase the IRAM and DRAM to accommodate different build scenarios as it is safe and doesn't make any difference in the user/application memory available.

brandon-exact commented 4 weeks ago

@brandon-exact, would you manually increase the iram size for the mcuboot bootloader? https://github.com/zephyrproject-rtos/zephyr/blob/main/soc/espressif/esp32s3/memory.h#L50

#define BOOTLOADER_IRAM_SEG_LEN 0xb000

@marekmatej PTAL.

Edit: I see that you already tried and it worked. This is indeed the resolution for the overflow issue. We will check whether there is an alternative way to improve it somehow.

This fixes and works on my dev board with SB_CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256.

When using SB_CONFIG_BOOT_SIGNATURE_TYPE_RSA there is still overflows in iram and dram

/home/brandon/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 `iram_seg' overflowed by 2348 bytes
/home/brandon/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 1272 bytes

but increasing their segments even more allowed it to work on my dev board.

sylvioalves commented 4 weeks ago

@brandon-exact right, thanks. We will increase it and evaluate properly.