Skip to content

Commit e131679

Browse files
sylvioalvescarlescufi
authored andcommitted
linker: esp32: changes to enable newlibc and cpp support
This PR adds missing configuration to enable newlibc and cpp code to run in ESP32 SoC. This isn't enough though. Toolchain changes are also needed and will come up next. Signed-off-by: Sylvio Alves <[email protected]>
1 parent 48877f8 commit e131679

File tree

2 files changed

+98
-54
lines changed

2 files changed

+98
-54
lines changed

soc/xtensa/esp32/linker.ld

Lines changed: 93 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,23 @@ SECTIONS
112112
* - Size of IRAM region
113113
*/
114114

115-
LONG(ADDR(".iram0.vectors"))
116-
LONG(LOADADDR(".iram0.vectors"))
117-
LONG(LOADADDR(_TEXT_SECTION_NAME) + SIZEOF(_TEXT_SECTION_NAME) - LOADADDR(".iram0.vectors"))
115+
LONG(ADDR(.iram0.vectors))
116+
LONG(LOADADDR(.iram0.vectors))
117+
LONG(LOADADDR(_TEXT_SECTION_NAME) + SIZEOF(_TEXT_SECTION_NAME) - LOADADDR(.iram0.vectors))
118118

119119
/* DRAM metadata:
120120
* - Destination address (VMA) for DRAM region
121121
* - Flash offset (LMA) for start of DRAM region
122122
* - Size of DRAM region
123123
*/
124124

125-
LONG(ADDR(".dram0.data"))
126-
LONG(LOADADDR(".dram0.data"))
127-
LONG(LOADADDR(".dummy.dram.data") + SIZEOF(".dummy.dram.data") - LOADADDR(".dram0.data"))
125+
LONG(ADDR(.dram0.data))
126+
LONG(LOADADDR(.dram0.data))
127+
LONG(LOADADDR(.dram0.end) + SIZEOF(.dram0.end) - LOADADDR(.dram0.data))
128128
} > metadata
129129

130130
#include <zephyr/linker/rel-sections.ld>
131+
131132
_image_drom_start = LOADADDR(_RODATA_SECTION_NAME);
132133
_image_drom_size = LOADADDR(_RODATA_SECTION_NAME) + SIZEOF(_RODATA_SECTION_NAME) - _image_drom_start;
133134
_image_drom_vaddr = ADDR(_RODATA_SECTION_NAME);
@@ -149,51 +150,61 @@ SECTIONS
149150
*(EXCLUDE_FILE (*libarch__xtensa__core.a:* *libkernel.a:fatal.* *libkernel.a:init.* *libzephyr.a:cbprintf_complete* *libzephyr.a:log_core.* *libzephyr.a:log_backend_uart.* *libdrivers__flash.a:esp32_mp.* *libzephyr.a:log_output.* *libzephyr.a:loader.* *libdrivers__flash.a:flash_esp32.* *libdrivers__serial.a:uart_esp32.* *libdrivers__flash.a:spi_flash_rom_patch.*) .rodata)
150151
*(EXCLUDE_FILE (*libarch__xtensa__core.a:* *libkernel.a:fatal.* *libkernel.a:init.* *libzephyr.a:cbprintf_complete* *libzephyr.a:log_core.* *libzephyr.a:log_backend_uart.* *libdrivers__flash.a:esp32_mp.* *libzephyr.a:log_output.* *libzephyr.a:loader.* *libdrivers__flash.a:flash_esp32.* *libdrivers__serial.a:uart_esp32.* *libdrivers__flash.a:spi_flash_rom_patch.*) .rodata.*)
151152

153+
*(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */
152154
*(.gnu.linkonce.r.*)
153155
*(.rodata1)
154-
__XT_EXCEPTION_TABLE__ = ABSOLUTE(.);
155-
KEEP (*(.xt_except_table))
156-
KEEP (*(.gcc_except_table .gcc_except_table.*))
156+
__XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
157+
*(.xt_except_table)
158+
*(.gcc_except_table .gcc_except_table.*)
157159
*(.gnu.linkonce.e.*)
158160
*(.gnu.version_r)
159-
KEEP (*(.eh_frame))
160-
/* C++ constructor and destructor tables, properly ordered: */
161-
KEEP (*crtbegin.o(.ctors))
162-
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
163-
KEEP (*(SORT(.ctors.*)))
164-
KEEP (*(.ctors))
165-
KEEP (*crtbegin.o(.dtors))
166-
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
167-
KEEP (*(SORT(.dtors.*)))
168-
KEEP (*(.dtors))
161+
. = (. + 3) & ~ 3;
162+
__eh_frame = ABSOLUTE(.);
163+
KEEP(*(.eh_frame))
164+
. = (. + 7) & ~ 3;
165+
169166
/* C++ exception handlers table: */
170-
__XT_EXCEPTION_DESCS__ = ABSOLUTE(.);
167+
__XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
171168
*(.xt_except_desc)
172169
*(.gnu.linkonce.h.*)
173170
__XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
174171
*(.xt_except_desc_end)
175172
*(.dynamic)
176173
*(.gnu.version_d)
177-
. = ALIGN(4); /* this table MUST be 4-byte aligned */
174+
. = ALIGN(4);
178175
_rodata_end = ABSOLUTE(.);
176+
/* Literals are also RO data. */
177+
_lit4_start = ABSOLUTE(.);
178+
*(*.lit4)
179+
*(.lit4.*)
180+
*(.gnu.linkonce.lit4.*)
181+
_lit4_end = ABSOLUTE(.);
182+
. = ALIGN(4);
183+
_thread_local_start = ABSOLUTE(.);
184+
*(.tdata)
185+
*(.tdata.*)
186+
*(.tbss)
187+
*(.tbss.*)
188+
_thread_local_end = ABSOLUTE(.);
189+
. = ALIGN(4);
179190
} GROUP_DATA_LINK_IN(RODATA_REGION, ROMABLE_REGION)
180191

181192
/* Flash segments (rodata and text) should be mapped in virtual address space by providing VMA.
182193
* Executing directly from LMA is not possible. */
183194
#pragma push_macro("GROUP_ROM_LINK_IN")
184195
#undef GROUP_ROM_LINK_IN
185196
#define GROUP_ROM_LINK_IN(vregion, lregion) > RODATA_REGION AT > lregion
186-
#include "linker/common-rom/common-rom-kernel-devices.ld"
187-
#include "linker/common-rom/common-rom-cpp.ld"
188-
#include "linker/common-rom/common-rom-net.ld"
189-
#include "linker/common-rom/common-rom-bt.ld"
190-
#include "linker/common-rom/common-rom-debug.ld"
191-
#include "linker/common-rom/common-rom-misc.ld"
197+
#include <zephyr/linker/common-rom/common-rom-cpp.ld>
198+
#include <zephyr/linker/common-rom/common-rom-kernel-devices.ld>
199+
#include <zephyr/linker/common-rom/common-rom-net.ld>
200+
#include <zephyr/linker/common-rom/common-rom-bt.ld>
201+
#include <zephyr/linker/common-rom/common-rom-debug.ld>
202+
#include <zephyr/linker/common-rom/common-rom-misc.ld>
192203
#pragma pop_macro("GROUP_ROM_LINK_IN")
193204

194-
_image_dram_start = LOADADDR(".dram0.data");
195-
_image_dram_size = LOADADDR(".dummy.dram.data") + SIZEOF(".dummy.dram.data") - _image_dram_start;
196-
_image_dram_vaddr = ADDR(".dram0.data");
205+
_image_dram_start = LOADADDR(.dram0.data);
206+
_image_dram_size = LOADADDR(.dram0.end) + SIZEOF(.dram0.end) - _image_dram_start;
207+
_image_dram_vaddr = ADDR(.dram0.data);
197208

198209
#include <snippets-sections.ld>
199210

@@ -234,31 +245,33 @@ SECTIONS
234245
KEEP(*(.jcr))
235246
*(.dram1 .dram1.*)
236247
. = ALIGN(4);
237-
_dram_data_end = ABSOLUTE(.);
238248
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
239249

250+
#include <zephyr/linker/cplusplus-rom.ld>
240251
#include <snippets-data-sections.ld>
241252
#include <zephyr/linker/common-ram.ld>
242253
#include <snippets-ram-sections.ld>
254+
#include <zephyr/linker/cplusplus-ram.ld>
243255

244256
/* logging sections should be placed in RAM area to avoid flash cache disabled issues */
245257
#pragma push_macro("GROUP_ROM_LINK_IN")
246258
#undef GROUP_ROM_LINK_IN
247259
#define GROUP_ROM_LINK_IN GROUP_DATA_LINK_IN
248-
#include "linker/common-rom/common-rom-logging.ld"
260+
#include <zephyr/linker/common-rom/common-rom-logging.ld>
249261
#pragma pop_macro("GROUP_ROM_LINK_IN")
250262

251-
.dummy.dram.data :
263+
.dram0.end :
252264
{
253265
. = ALIGN(4);
254266
#include <snippets-rwdata.ld>
255267
. = ALIGN(4);
268+
_end = ABSOLUTE(.);
256269
_data_end = ABSOLUTE(.);
257270
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
258271

259-
_image_iram_start = LOADADDR(".iram0.vectors");
272+
_image_iram_start = LOADADDR(.iram0.vectors);
260273
_image_iram_size = LOADADDR(_TEXT_SECTION_NAME) + SIZEOF(_TEXT_SECTION_NAME) - _image_iram_start;
261-
_image_iram_vaddr = ADDR(".iram0.vectors");
274+
_image_iram_vaddr = ADDR(.iram0.vectors);
262275

263276
/* Send .iram0 code to iram */
264277
.iram0.vectors : ALIGN(4)
@@ -334,6 +347,7 @@ SECTIONS
334347
*libzephyr.a:log_backend_uart.*(.literal .text .literal.* .text.*)
335348
*libzephyr.a:loader.*(.literal .text .literal.* .text.*)
336349
*liblib__libc__minimal.a:string.*(.literal .text .literal.* .text.*)
350+
*liblib__libc__newlib.a:string.*(.literal .text .literal.* .text.*)
337351
*libphy.a:( .phyiram .phyiram.*)
338352
*libgcov.a:(.literal .text .literal.* .text.*)
339353

@@ -388,7 +402,8 @@ SECTIONS
388402
SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
389403
{
390404
. = ALIGN (8);
391-
_bss_start = ABSOLUTE(.);
405+
_bss_start = ABSOLUTE(.); /* required by bluetooth library */
406+
__bss_start = ABSOLUTE(.);
392407

393408
_btdm_bss_start = ABSOLUTE(.);
394409
*libbtdm_app.a:(.bss .bss.* COMMON)
@@ -413,10 +428,11 @@ SECTIONS
413428
*(.gnu.linkonce.b.*)
414429
*(COMMON)
415430
. = ALIGN (8);
416-
_bss_end = ABSOLUTE(.);
431+
__bss_end = ABSOLUTE(.);
432+
_end = ABSOLUTE(.);
417433
} GROUP_LINK_IN(RAMABLE_REGION)
418434

419-
ASSERT(((_bss_end - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)),
435+
ASSERT(((__bss_end - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)),
420436
"DRAM segment data does not fit.")
421437

422438
SECTION_DATA_PROLOGUE(_NOINIT_SECTION_NAME, (NOLOAD),)
@@ -436,9 +452,9 @@ SECTIONS
436452
} > ext_ram_seg
437453
#endif
438454

439-
_image_irom_start = LOADADDR(".flash.text");
440-
_image_irom_size = LOADADDR(".flash.text") + SIZEOF(".flash.text") - _image_irom_start;
441-
_image_irom_vaddr = ADDR(".flash.text");
455+
_image_irom_start = LOADADDR(.flash.text);
456+
_image_irom_size = LOADADDR(.flash.text) + SIZEOF(.flash.text) - _image_irom_start;
457+
_image_irom_vaddr = ADDR(.flash.text);
442458

443459
.flash.text : ALIGN(IROM_SEG_ALIGN)
444460
{
@@ -467,16 +483,47 @@ SECTIONS
467483
_flash_cache_start = ABSOLUTE(0);
468484
} GROUP_DATA_LINK_IN(FLASH_CODE_REGION, ROMABLE_REGION)
469485

470-
#ifdef CONFIG_GEN_ISR_TABLES
471-
#include <zephyr/linker/intlist.ld>
472-
#endif
486+
_heap_sentry = 0x3ffe3f20;
473487

474488
#include <zephyr/linker/debug-sections.ld>
475489

476-
SECTION_PROLOGUE(.xtensa.info, 0,)
490+
.xtensa.info 0 : { *(.xtensa.info) }
491+
.xt.insn 0 :
492+
{
493+
KEEP (*(.xt.insn))
494+
KEEP (*(.gnu.linkonce.x.*))
495+
}
496+
.xt.prop 0 :
497+
{
498+
KEEP (*(.xt.prop))
499+
KEEP (*(.xt.prop.*))
500+
KEEP (*(.gnu.linkonce.prop.*))
501+
}
502+
.xt.lit 0 :
503+
{
504+
KEEP (*(.xt.lit))
505+
KEEP (*(.xt.lit.*))
506+
KEEP (*(.gnu.linkonce.p.*))
507+
}
508+
.xt.profile_range 0 :
477509
{
478-
*(.xtensa.info)
510+
KEEP (*(.xt.profile_range))
511+
KEEP (*(.gnu.linkonce.profile_range.*))
479512
}
513+
.xt.profile_ranges 0 :
514+
{
515+
KEEP (*(.xt.profile_ranges))
516+
KEEP (*(.gnu.linkonce.xt.profile_ranges.*))
517+
}
518+
.xt.profile_files 0 :
519+
{
520+
KEEP (*(.xt.profile_files))
521+
KEEP (*(.gnu.linkonce.xt.profile_files.*))
522+
}
523+
524+
#ifdef CONFIG_GEN_ISR_TABLES
525+
#include <zephyr/linker/intlist.ld>
526+
#endif
480527

481528
}
482529

soc/xtensa/esp32/soc.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <string.h>
1717
#include <zephyr/toolchain/gcc.h>
1818
#include <zephyr/types.h>
19+
#include <zephyr/linker/linker-defs.h>
20+
#include <kernel_internal.h>
1921

2022
#include "esp_private/system_internal.h"
2123
#include "esp32/rom/cache.h"
@@ -27,8 +29,6 @@
2729
#include "esp32/spiram.h"
2830
#include "sys/printk.h"
2931

30-
extern void z_cstart(void);
31-
3232
/*
3333
* This is written in C rather than assembly since, during the port bring up,
3434
* Zephyr is being booted by the Espressif bootloader. With it, the C stack
@@ -40,22 +40,19 @@ void __attribute__((section(".iram1"))) __esp_platform_start(void)
4040
volatile uint32_t *wdt_rtc_reg = (uint32_t *)RTC_CNTL_WDTCONFIG0_REG;
4141
volatile uint32_t *app_cpu_config_reg = (uint32_t *)DPORT_APPCPU_CTRL_B_REG;
4242
extern uint32_t _init_start;
43-
extern uint32_t _bss_start;
44-
extern uint32_t _bss_end;
4543

4644
/* Move the exception vector table to IRAM. */
4745
__asm__ __volatile__ (
4846
"wsr %0, vecbase"
4947
:
5048
: "r"(&_init_start));
5149

52-
/* Zero out BSS. Clobber _bss_start to avoid memset() elision. */
53-
(void)memset(&_bss_start, 0,
54-
(&_bss_end - &_bss_start) * sizeof(_bss_start));
50+
z_bss_zero();
51+
5552
__asm__ __volatile__ (
5653
""
5754
:
58-
: "g"(&_bss_start)
55+
: "g"(&__bss_start)
5956
: "memory");
6057

6158
/* Disable normal interrupts. */

0 commit comments

Comments
 (0)