Skip to content

Commit f25752f

Browse files
committed
soc: esp32c6: add userspace linker support
Add linker script support for CONFIG_USERSPACE: - MPU alignment macros for PMP granularity - User stacks section in noinit area - Application shared memory partitions - Kernel object sections (text, rom, data, priv-stacks) - ROM region size symbol for PMP configuration Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
1 parent 722c716 commit f25752f

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

soc/espressif/esp32c6/default.ld

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ user_sram_size = (user_sram_end - user_sram_org);
3131
#define RAMABLE_REGION sram0_0_seg
3232
#define ROMABLE_REGION FLASH
3333

34+
#ifdef CONFIG_RISCV_PMP
35+
#define MPU_MIN_SIZE CONFIG_PMP_GRANULARITY
36+
#define MPU_MIN_SIZE_ALIGN . = ALIGN(MPU_MIN_SIZE);
37+
#if defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
38+
#define MPU_ALIGN(region_size) \
39+
. = ALIGN(MPU_MIN_SIZE); \
40+
. = ALIGN(1 << LOG2CEIL(region_size))
41+
#else
42+
#define MPU_ALIGN(region_size) \
43+
. = ALIGN(MPU_MIN_SIZE)
44+
#endif
45+
#else
46+
#define MPU_MIN_SIZE_ALIGN
47+
#define MPU_ALIGN(region_size) . = ALIGN(4)
48+
#endif
49+
3450
#undef GROUP_DATA_LINK_IN
3551
#define GROUP_DATA_LINK_IN(vregion, lregion) > vregion AT > lregion
3652

@@ -695,6 +711,24 @@ SECTIONS
695711
#include <zephyr/linker/common-rom/common-rom-logging.ld>
696712
#pragma pop_macro("GROUP_ROM_LINK_IN")
697713

714+
/*
715+
* Userspace sections (app_smem, kobject_data) must be placed before .dram0.end
716+
* so they are included in the DRAM segment that MCUboot loads to RAM.
717+
* The MCUboot load header uses .dram0.end to calculate DRAM size.
718+
*/
719+
#if defined(CONFIG_USERSPACE)
720+
#define APP_SHARED_ALIGN MPU_MIN_SIZE_ALIGN
721+
#define SMEM_PARTITION_ALIGN MPU_ALIGN
722+
723+
#include <app_smem.ld>
724+
725+
_app_smem_size = _app_smem_end - _app_smem_start;
726+
_app_smem_rom_start = LOADADDR(_APP_SMEM_SECTION_NAME);
727+
#endif /* CONFIG_USERSPACE */
728+
729+
#include <zephyr/linker/kobject-data.ld>
730+
#include <zephyr/linker/kobject-priv-stacks.ld>
731+
698732
.dram0.end :
699733
{
700734
. = ALIGN(4);
@@ -707,12 +741,18 @@ SECTIONS
707741
. = ALIGN(4);
708742
*(.noinit)
709743
*(.noinit.*)
744+
#ifdef CONFIG_USERSPACE
745+
z_user_stacks_start = .;
746+
*(.user_stacks*)
747+
z_user_stacks_end = .;
748+
#endif /* CONFIG_USERSPACE */
710749
. = ALIGN(4);
711750
} GROUP_LINK_IN(RAMABLE_REGION)
712751

713752
/* Shared RAM */
714753
.dram0.bss (NOLOAD) :
715754
{
755+
MPU_MIN_SIZE_ALIGN
716756
. = ALIGN (8);
717757
__bss_start = ABSOLUTE(.);
718758
_bss_start = ABSOLUTE(.);
@@ -750,6 +790,9 @@ SECTIONS
750790

751791
/* Provide total SRAM usage, including IRAM and DRAM */
752792
_image_ram_start = _iram_start;
793+
794+
#define LAST_RAM_ALIGN MPU_MIN_SIZE_ALIGN
795+
753796
#include <zephyr/linker/ram-end.ld>
754797

755798
ASSERT(((_end - ORIGIN(sram0_0_seg)) <= LENGTH(sram0_0_seg)), "SRAM code/data does not fit.")
@@ -792,6 +835,7 @@ SECTIONS
792835
*(.literal .text .literal.* .text.*)
793836
*(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
794837
*(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */
838+
#include <zephyr/linker/kobject-text.ld>
795839

796840
*(.fini.literal)
797841
*(.fini)
@@ -809,7 +853,10 @@ SECTIONS
809853
_text_end = ABSOLUTE(.);
810854
_instruction_reserved_end = ABSOLUTE(.);
811855
__text_region_end = ABSOLUTE(.);
856+
/* Align for PMP granularity requirements */
857+
MPU_MIN_SIZE_ALIGN
812858
__rom_region_end = ABSOLUTE(.);
859+
__rom_region_size = __rom_region_end - __rom_region_start;
813860
_etext = .;
814861

815862
} GROUP_DATA_LINK_IN(FLASH_CODE_REGION, ROMABLE_REGION)
@@ -864,7 +911,6 @@ SECTIONS
864911
*(.xt_except_desc_end)
865912
*(.dynamic)
866913
*(.gnu.version_d)
867-
__rodata_region_end = .;
868914
_rodata_end = ABSOLUTE(.);
869915
/* Literals are also RO data. */
870916
_lit4_start = ABSOLUTE(.);
@@ -879,7 +925,9 @@ SECTIONS
879925
*(.rodata.*)
880926
*(.rodata_wlog)
881927
*(.rodata_wlog*)
928+
#include <zephyr/linker/kobject-rom.ld>
882929
. = ALIGN(4);
930+
__rodata_region_end = .;
883931
} GROUP_DATA_LINK_IN(RODATA_REGION, ROMABLE_REGION)
884932

885933
#include <zephyr/linker/cplusplus-rom.ld>
@@ -890,6 +938,7 @@ SECTIONS
890938
#include <zephyr/linker/common-rom/common-rom-bt.ld>
891939
#include <zephyr/linker/common-rom/common-rom-debug.ld>
892940
#include <zephyr/linker/common-rom/common-rom-misc.ld>
941+
#include <snippets-rom-sections.ld>
893942
#include <zephyr/linker/thread-local-storage.ld>
894943
#include <snippets-sections.ld>
895944

0 commit comments

Comments
 (0)