From f5fa4b3bcdd8af30ac2a8d95b32be9776cd6b953 Mon Sep 17 00:00:00 2001 From: Sylvio Alves Date: Wed, 13 Sep 2023 07:24:52 -0300 Subject: [PATCH] soc: espressif: provide VMA to rodata and text by default Flash segments require VMA to proper work. Executing from LMA is not possible. Current implementation did not take into account runtime iterable rom sections that any application could implement. In the above cenario and as reported in the issue below, ESP32 won't run when those ROM sections are created in application level. This change make sure all flash segments are properly mapped accordingly. Fixes #61834 Signed-off-by: Sylvio Alves --- soc/riscv/espressif_esp32/esp32c3/default.ld | 11 +++++------ soc/xtensa/espressif_esp32/esp32/default.ld | 11 +++++------ soc/xtensa/espressif_esp32/esp32_net/linker.ld | 11 +++++------ soc/xtensa/espressif_esp32/esp32s2/default.ld | 11 +++++------ soc/xtensa/espressif_esp32/esp32s3/default.ld | 11 +++++------ 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/soc/riscv/espressif_esp32/esp32c3/default.ld b/soc/riscv/espressif_esp32/esp32c3/default.ld index 01aeb903af2..9fb9f0c1ab0 100644 --- a/soc/riscv/espressif_esp32/esp32c3/default.ld +++ b/soc/riscv/espressif_esp32/esp32c3/default.ld @@ -49,6 +49,11 @@ #define IROM_SEG_ALIGN 0x10000 #endif +/* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA. + * Executing directly from LMA is not possible. */ +#undef GROUP_ROM_LINK_IN +#define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion + /* Global symbols required for espressif hal build */ MEMORY { @@ -185,11 +190,6 @@ SECTIONS . = ALIGN(4); } GROUP_DATA_LINK_IN(RODATA_REGION, ROMABLE_REGION) - /* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA. - * Executing directly from LMA is not possible. */ - #pragma push_macro("GROUP_ROM_LINK_IN") - #undef GROUP_ROM_LINK_IN - #define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion #include #include #include @@ -197,7 +197,6 @@ SECTIONS #include #include #include - #pragma pop_macro("GROUP_ROM_LINK_IN") /* Create an explicit section at the end of all the data that shall be mapped into drom. * This is used to calculate the size of the _image_drom_size variable */ diff --git a/soc/xtensa/espressif_esp32/esp32/default.ld b/soc/xtensa/espressif_esp32/esp32/default.ld index b04399a24ac..ddc95c4527f 100644 --- a/soc/xtensa/espressif_esp32/esp32/default.ld +++ b/soc/xtensa/espressif_esp32/esp32/default.ld @@ -46,6 +46,11 @@ #endif #define IRAM_SEG_LEN 0x20000 +/* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA. + * Executing directly from LMA is not possible. */ +#undef GROUP_ROM_LINK_IN +#define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion + MEMORY { mcuboot_hdr (RX): org = 0x0, len = 0x20 @@ -209,11 +214,6 @@ SECTIONS . = ALIGN(4); } GROUP_DATA_LINK_IN(RODATA_REGION, ROMABLE_REGION) - /* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA. - * Executing directly from LMA is not possible. */ - #pragma push_macro("GROUP_ROM_LINK_IN") - #undef GROUP_ROM_LINK_IN - #define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion #include #include #include @@ -221,7 +221,6 @@ SECTIONS #include #include #include - #pragma pop_macro("GROUP_ROM_LINK_IN") /* Create an explicit section at the end of all the data that shall be mapped into drom. * This is used to calculate the size of the _image_drom_size variable */ diff --git a/soc/xtensa/espressif_esp32/esp32_net/linker.ld b/soc/xtensa/espressif_esp32/esp32_net/linker.ld index 6c1b69872b1..2b815957e84 100644 --- a/soc/xtensa/espressif_esp32/esp32_net/linker.ld +++ b/soc/xtensa/espressif_esp32/esp32_net/linker.ld @@ -26,6 +26,11 @@ #define ROMABLE_DATA_REGION dram0_1_seg #define dram0_0_seg dram0_1_seg +/* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA. + * Executing directly from LMA is not possible. */ +#undef GROUP_ROM_LINK_IN +#define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion + MEMORY { iram0_0_seg(RX): org = 0x40080000 + 0x08000, len = 0x18000 @@ -200,11 +205,6 @@ SECTIONS . = ALIGN(4); } GROUP_DATA_LINK_IN(RODATA_REGION, ROMABLE_DATA_REGION) - /* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA. - * Executing directly from LMA is not possible. */ - #pragma push_macro("GROUP_ROM_LINK_IN") - #undef GROUP_ROM_LINK_IN - #define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion #include #include #include @@ -212,7 +212,6 @@ SECTIONS #include #include #include - #pragma pop_macro("GROUP_ROM_LINK_IN") /* Create an explicit section at the end of all the data that shall be mapped into drom. * This is used to calculate the size of the _image_drom_size variable */ diff --git a/soc/xtensa/espressif_esp32/esp32s2/default.ld b/soc/xtensa/espressif_esp32/esp32s2/default.ld index c6681215e5d..35e2889db56 100644 --- a/soc/xtensa/espressif_esp32/esp32s2/default.ld +++ b/soc/xtensa/espressif_esp32/esp32s2/default.ld @@ -53,6 +53,11 @@ #define IROM_SEG_ALIGN 0x10000 #endif +/* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA. + * Executing directly from LMA is not possible. */ +#undef GROUP_ROM_LINK_IN +#define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion + MEMORY { mcuboot_hdr (RX): org = 0x0, len = 0x20 @@ -181,18 +186,12 @@ SECTIONS . = ALIGN(4); } GROUP_DATA_LINK_IN(RODATA_REGION, ROMABLE_REGION) - /* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA. - * Executing directly from LMA is not possible. */ - #pragma push_macro("GROUP_ROM_LINK_IN") - #undef GROUP_ROM_LINK_IN - #define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion #include #include #include #include #include #include - #pragma pop_macro("GROUP_ROM_LINK_IN") /* Create an explicit section at the end of all the data that shall be mapped into drom. * This is used to calculate the size of the _image_drom_size variable */ diff --git a/soc/xtensa/espressif_esp32/esp32s3/default.ld b/soc/xtensa/espressif_esp32/esp32s3/default.ld index b3cbd62c89b..fc6a4e47d0e 100644 --- a/soc/xtensa/espressif_esp32/esp32s3/default.ld +++ b/soc/xtensa/espressif_esp32/esp32s3/default.ld @@ -59,6 +59,11 @@ #define IROM_SEG_ALIGN 0x10000 +/* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA. + * Executing directly from LMA is not possible. */ +#undef GROUP_ROM_LINK_IN +#define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion + MEMORY { mcuboot_hdr (RX): org = 0x0, len = 0x20 @@ -207,11 +212,6 @@ SECTIONS . = ALIGN(4); } GROUP_DATA_LINK_IN(RODATA_REGION, ROMABLE_REGION) - /* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA. - * Executing directly from LMA is not possible. */ - #pragma push_macro("GROUP_ROM_LINK_IN") - #undef GROUP_ROM_LINK_IN - #define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion #include #include #include @@ -219,7 +219,6 @@ SECTIONS #include #include #include - #pragma pop_macro("GROUP_ROM_LINK_IN") /* Create an explicit section at the end of all the data that shall be mapped into drom. * This is used to calculate the size of the _image_drom_size variable */