esp32s3: Enhance protected build linker scripts and memory layout

Instead of setting kernel/user space instruction and data ROM as
hard-coded values on linker, set them according to the max size
of the kernel image set by CONFIG_ESP32S3_KERNEL_IMAGE_SIZE. This
is done by making KIROM, UIROM, KDROM and UDROM dependent on the
kernel size value. Also, override CONFIG_NUTTX_USERSPACE config
according to CONFIG_ESP32S3_KERNEL_IMAGE_SIZE by using a custom
PREBUILD definition.
This commit is contained in:
Tiago Medicci Serrano
2023-07-31 16:41:43 -03:00
committed by Petro Karashchenko
parent 4f83811a09
commit 1197a80741
5 changed files with 50 additions and 16 deletions
@@ -42,7 +42,7 @@
* Application Image properly.
*
* For more information, refer to the bootloader linker scripts:
* https://github.com/espressif/esp-idf/blob/v4.4.2/components/bootloader/subproject/main/ld/esp32s3/bootloader.ld#L41-L47
* https://github.com/espressif/esp-idf/blob/dbb64db552068d440c2659294dcf2a5544fe3b6b/components/bootloader/subproject/main/ld/esp32s3/bootloader.ld#L52
*/
#define SRAM_IRAM_END 0x403cc700
@@ -73,7 +73,7 @@ MEMORY
{
metadata (RX) : org = 0x0, len = 0x30
ROM (RX) : org = ORIGIN(metadata) + LENGTH(metadata),
len = 0x100000 - ORIGIN(ROM)
len = FLASH_SIZE - ORIGIN(ROM)
/* Instruction RAM */
@@ -90,13 +90,13 @@ MEMORY
* constraint that (paddr % 64KB == vaddr % 64KB).
*/
KIROM (RX) : org = 0x42000020, len = 0x80000 - 0x20
UIROM (RX) : org = 0x42080000, len = 0x180000
KIROM (RX) : org = 0x42000020, len = CONFIG_ESP32S3_KERNEL_IMAGE_SIZE - 0x20
UIROM (RX) : org = ORIGIN(KIROM) + LENGTH(KIROM), len = FLASH_SIZE - LENGTH(KIROM)
/* Shared data RAM, excluding memory reserved for ROM bss/data/stack. */
KDRAM (RW) : org = ORIGIN(KIRAM) + LENGTH(KIRAM) - I_D_SRAM_OFFSET, len = 64K
UDRAM (RW) : org = ORIGIN(KDRAM) + LENGTH(KDRAM), len = 256K
KDRAM (RW) : org = ORIGIN(KIRAM) + LENGTH(KIRAM) - I_D_SRAM_OFFSET, len = CONFIG_ESP32S3_KERNEL_RAM_SIZE
UDRAM (RW) : org = ORIGIN(KDRAM) + LENGTH(KDRAM), len = I_D_SRAM_SIZE - LENGTH(KDRAM)
/* Flash mapped constant data */
@@ -109,7 +109,7 @@ MEMORY
* SRAM contents when loading the User application image.
*/
KDROM (R) : org = 0x3c000020, len = 0x80000 - 0x20
UDROM (R) : org = 0x3c080030, len = 0x180000 - ORIGIN(ROM)
KDROM (R) : org = 0x3c000020, len = CONFIG_ESP32S3_KERNEL_IMAGE_SIZE - 0x20
UDROM (R) : org = ORIGIN(KDROM) + LENGTH(KDROM) + ORIGIN(ROM), len = FLASH_SIZE - LENGTH(KDROM) - ORIGIN(ROM)
}
@@ -23,6 +23,8 @@ CONFIG_BUILD_PROTECTED=y
CONFIG_BUILTIN=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_ESP32S3_KERNEL_IMAGE_SIZE=0x80000
CONFIG_ESP32S3_KERNEL_RAM_SIZE=0x10000
CONFIG_ESP32S3_UART0=y
CONFIG_ESP32S3_WCL=y
CONFIG_FS_PROCFS=y
@@ -37,7 +39,6 @@ CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_NUTTX_USERSPACE=0x3c080030
CONFIG_PASS1_BUILDIR="boards/xtensa/esp32s3/common/kernel"
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=114688