1/*
2 * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6/*
7Linker file used to link the bootloader.
8*/
9
10
11/* Simplified memory map for the bootloader
12
13   The main purpose is to make sure the bootloader can load into main memory
14   without overwriting itself.
15*/
16
17MEMORY
18{
19  /* IRAM POOL1, used for APP CPU cache. Bootloader runs from here during the final stage of loading the app because APP CPU is still held in reset, the main app enables APP CPU cache */
20  iram_loader_seg (RWX) :           org = 0x40078000, len = 0x8000  /* 32KB, APP CPU cache */
21  /* 63kB, IRAM. We skip the first 1k to prevent the entry point being
22     placed into the same range as exception vectors in the app.
23     This leads to idf_monitor decoding ROM bootloader "entry 0x40080xxx"
24     message as one of the exception vectors, which looks scary to users.
25  */
26  iram_seg (RWX) :                  org = 0x40080400, len = 0xfc00
27  /* 64k at the end of DRAM, after ROM bootloader stack */
28  dram_seg (RW) :                  	org = 0x3FFF0000, len = 0x6000
29}
30
31/*  Default entry point:  */
32ENTRY(call_start_cpu0);
33
34
35SECTIONS
36{
37
38  .iram_loader.text :
39  {
40    . = ALIGN (16);
41    _loader_text_start = ABSOLUTE(.);
42    *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
43     *(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
44    *liblog.a:(.literal .text .literal.* .text.*)
45    *libgcc.a:(.literal .text .literal.* .text.*)
46    *libbootloader_support.a:bootloader_clock_loader.*(.literal .text .literal.* .text.*)
47    *libbootloader_support.a:bootloader_common_loader.*(.literal .text .literal.* .text.*)
48    *libbootloader_support.a:bootloader_flash.*(.literal .text .literal.* .text.*)
49    *libbootloader_support.a:bootloader_random.*(.literal .text .literal.* .text.*)
50    *libbootloader_support.a:bootloader_random*.*(.literal.bootloader_random_disable .text.bootloader_random_disable)
51    *libesp_common.a:fpga_overrides.*(.literal.bootloader_fill_random .text.bootloader_fill_random)
52    *libbootloader_support.a:bootloader_efuse.*(.literal .text .literal.* .text.*)
53    *libbootloader_support.a:bootloader_utility.*(.literal .text .literal.* .text.*)
54    *libbootloader_support.a:bootloader_sha.*(.literal .text .literal.* .text.*)
55    *libbootloader_support.a:bootloader_console_loader.*(.literal .text .literal.* .text.*)
56    *libbootloader_support.a:bootloader_panic.*(.literal .text .literal.* .text.*)
57    *libbootloader_support.a:bootloader_soc.*(.literal .text .literal.* .text.*)
58    *libbootloader_support.a:esp_image_format.*(.literal .text .literal.* .text.*)
59    *libbootloader_support.a:flash_encrypt.*(.literal .text .literal.* .text.*)
60    *libbootloader_support.a:flash_encryption_secure_features.*(.literal .text .literal.* .text.*)
61    *libbootloader_support.a:flash_partitions.*(.literal .text .literal.* .text.*)
62    *libbootloader_support.a:secure_boot.*(.literal .text .literal.* .text.*)
63    *libbootloader_support.a:secure_boot_secure_features.*(.literal .text .literal.* .text.*)
64    *libbootloader_support.a:secure_boot_signatures_bootloader.*(.literal .text .literal.* .text.*)
65    *libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
66    *libspi_flash.a:*.*(.literal .text .literal.* .text.*)
67    *libhal.a:wdt_hal_iram.*(.literal .text .literal.* .text.*)
68    *libhal.a:mmu_hal.*(.literal .text .literal.* .text.*)
69    *libhal.a:efuse_hal.*(.literal .text .literal.* .text.*)
70    *libesp_hw_support.a:rtc_clk.*(.literal .text .literal.* .text.*)
71    *libesp_hw_support.a:rtc_time.*(.literal .text .literal.* .text.*)
72    *libefuse.a:*.*(.literal .text .literal.* .text.*)
73    *libesp_rom.a:*.*(.literal .text .literal.* .text.*)
74    *(.fini.literal)
75    *(.fini)
76    *(.gnu.version)
77    _loader_text_end = ABSOLUTE(.);
78  } > iram_loader_seg
79
80  .iram.text :
81  {
82    . = ALIGN (16);
83    *(.entry.text)
84    *(.init.literal)
85    *(.init)
86  } > iram_seg
87
88
89  /* Shared RAM */
90  .dram0.bss (NOLOAD) :
91  {
92    . = ALIGN (8);
93    _dram_start = ABSOLUTE(.);
94    _bss_start = ABSOLUTE(.);
95    *(.dynsbss)
96    *(.sbss)
97    *(.sbss.*)
98    *(.gnu.linkonce.sb.*)
99    *(.scommon)
100    *(.sbss2)
101    *(.sbss2.*)
102    *(.gnu.linkonce.sb2.*)
103    *(.dynbss)
104    *(.bss)
105    *(.bss.*)
106    *(.gnu.linkonce.b.*)
107    *(COMMON)
108    . = ALIGN (8);
109    _bss_end = ABSOLUTE(.);
110  } >dram_seg
111
112  .dram0.data :
113  {
114    _data_start = ABSOLUTE(.);
115    *(.data)
116    *(.data.*)
117    *(.gnu.linkonce.d.*)
118    *(.data1)
119    *(.sdata)
120    *(.sdata.*)
121    *(.gnu.linkonce.s.*)
122    *(.gnu.linkonce.s2.*)
123    *(.jcr)
124    _data_end = ABSOLUTE(.);
125  } >dram_seg
126
127  .dram0.rodata :
128  {
129    _rodata_start = ABSOLUTE(.);
130    *(.rodata)
131    *(.rodata.*)
132    *(.gnu.linkonce.r.*)
133    *(.rodata1)
134    *(.sdata2 .sdata2.*)
135    __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
136    *(.xt_except_table)
137    *(.gcc_except_table)
138    *(.gnu.linkonce.e.*)
139    *(.gnu.version_r)
140    *(.eh_frame)
141    . = (. + 3) & ~ 3;
142    /*  C++ constructor and destructor tables, properly ordered:  */
143    __init_array_start = ABSOLUTE(.);
144    KEEP (*crtbegin.*(.ctors))
145    KEEP (*(EXCLUDE_FILE (*crtend.*) .ctors))
146    KEEP (*(SORT(.ctors.*)))
147    KEEP (*(.ctors))
148    __init_array_end = ABSOLUTE(.);
149    KEEP (*crtbegin.*(.dtors))
150    KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
151    KEEP (*(SORT(.dtors.*)))
152    KEEP (*(.dtors))
153    /*  C++ exception handlers table:  */
154    __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
155    *(.xt_except_desc)
156    *(.gnu.linkonce.h.*)
157    __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
158    *(.xt_except_desc_end)
159    *(.dynamic)
160    *(.gnu.version_d)
161    _rodata_end = ABSOLUTE(.);
162	/* Literals are also RO data. */
163    _lit4_start = ABSOLUTE(.);
164    *(*.lit4)
165    *(.lit4.*)
166    *(.gnu.linkonce.lit4.*)
167    _lit4_end = ABSOLUTE(.);
168    . = ALIGN(4);
169    _dram_end = ABSOLUTE(.);
170  } >dram_seg
171
172  .iram.text :
173  {
174    _stext = .;
175    _text_start = ABSOLUTE(.);
176    *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
177    *(.iram .iram.*) /* catch stray IRAM_ATTR */
178    *(.fini.literal)
179    *(.fini)
180    *(.gnu.version)
181
182    /** CPU will try to prefetch up to 16 bytes of
183      * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
184      * safe access to up to 16 bytes after the last real instruction, add
185      * dummy bytes to ensure this
186      */
187    . += 16;
188
189    _text_end = ABSOLUTE(.);
190    _etext = .;
191  } > iram_seg
192
193  /** This section will be used by the debugger and disassembler to get more information
194   * about raw data present in the code.
195   * Indeed, it may be required to add some padding at some points in the code
196   * in order to align a branch/jump destination on a particular bound.
197   * Padding these instructions will generate null bytes that shall be
198   * interpreted as data, and not code by the debugger or disassembler.
199   * This section will only be present in the ELF file, not in the final binary
200   * For more details, check GCC-212
201   */
202  .xt.prop 0 :
203  {
204    KEEP (*(.xt.prop .gnu.linkonce.prop.*))
205  }
206
207  .xt.lit 0 :
208  {
209    KEEP (*(.xt.lit .gnu.linkonce.p.*))
210  }
211
212}
213