Skip to content

Commit 9a18992

Browse files
committed
Added ram or rom support and Improved linker scripts
1 parent d0200b7 commit 9a18992

File tree

4 files changed

+68
-29
lines changed

4 files changed

+68
-29
lines changed

build.rs

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ fn main() {
1010
.unwrap()
1111
.write_all(include_bytes!("memory.x"))
1212
.unwrap();
13+
14+
File::create(out.join("alias.x"))
15+
.unwrap()
16+
.write_all(if cfg!(feature = "all_in_ram") {
17+
include_bytes!("ram.x")
18+
} else {
19+
include_bytes!("rom.x")
20+
})
21+
.unwrap();
22+
1323
println!("cargo:rustc-link-search={}", out.display());
1424

1525
// Only re-run the build script when memory.x is changed,

memory.x

+52-29
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ RESERVE_RTC_SLOW = 0;
1212
/* Specify main memory areas */
1313
MEMORY
1414
{
15-
reserved1_seg ( RWX ) : ORIGIN = 0x40070000, len = 0x10000 /* SRAM0 64kB; reserved for usage as flash cache*/
16-
vectors ( RX ) : ORIGIN = 0x40080000, len = 0x400 /* SRAM0 1kB */
17-
iram_seg ( RX ) : ORIGIN = 0x40080400, len = 0x20000-0x400 /* SRAM0 127kB */
15+
reserved1_seg ( RWX ) : ORIGIN = 0x40070000, len = 64k /* SRAM0; reserved for usage as flash cache*/
16+
vectors ( RX ) : ORIGIN = 0x40080000, len = 1k /* SRAM0 */
17+
iram_seg ( RX ) : ORIGIN = 0x40080400, len = 128k-0x400 /* SRAM0 */
1818

19-
reserved2_seg ( RW ) : ORIGIN = 0x3FFAE000, len = 0x2000 /* SRAM2 8kB; reserved for usage by the ROM */
20-
dram_seg ( RW ) : ORIGIN = 0x3FFB0000 + RESERVE_DRAM, len = 0x2c200 - RESERVE_DRAM /* SRAM2+1 176.5kB; first 64kB used by BT if enable */
21-
reserved3_seg ( RW ) : ORIGIN = 0x3FFDC200, len = 0x23e00 /* SRAM1 143.5kB; reserved for static ROM usage; can be used for heap */
19+
reserved2_seg ( RW ) : ORIGIN = 0x3FFAE000, len = 8k /* SRAM2; reserved for usage by the ROM */
20+
dram_seg ( RW ) : ORIGIN = 0x3FFB0000 + RESERVE_DRAM, len = 176k - RESERVE_DRAM /* SRAM2+1; first 64kB used by BT if enable */
21+
reserved3_seg ( RW ) : ORIGIN = 0x3FFDC200, len = 144k /* SRAM1; reserved for static ROM usage; can be used for heap */
2222

2323
/* external flash
2424
The 0x20 offset is a convenience for the app binary image generation.
@@ -27,69 +27,68 @@ MEMORY
2727
header. Setting this offset makes it simple to meet the flash cache MMU's
2828
constraint that (paddr % 64KB == vaddr % 64KB).)
2929
*/
30-
irom_seg ( RX ) : ORIGIN = 0x400D8020, len = 0x330000-0x20 /* 3MB */
31-
drom_seg ( R ) : ORIGIN = 0x3F400020, len = 0x400000-0x20 /* 4MB */
30+
irom_seg ( RX ) : ORIGIN = 0x400D0020, len = 3M - 0x20
31+
drom_seg ( R ) : ORIGIN = 0x3F400020, len = 4M - 0x20
3232

3333

3434
/* RTC fast memory (executable). Persists over deep sleep. Only for core 0 (PRO_CPU) */
35-
rtc_fast_iram_seg(RWX) : ORIGIN = 0x400C0000, len = 0x2000 /* 8kB */
35+
rtc_fast_iram_seg(RWX) : ORIGIN = 0x400C0000, len = 8k
3636

3737
/* RTC fast memory (same block as above), viewed from data bus. Only for core 0 (PRO_CPU) */
38-
rtc_fast_dram_seg(RW) : ORIGIN = 0x3ff80000 + RESERVE_RTC_FAST, len = 0x2000 - RESERVE_RTC_FAST /* 8kB */
38+
rtc_fast_dram_seg(RW) : ORIGIN = 0x3FF80000 + RESERVE_RTC_FAST, len = 8k - RESERVE_RTC_FAST
3939

4040
/* RTC slow memory (data accessible). Persists over deep sleep. */
41-
rtc_slow_seg(RW) : ORIGIN = 0x50000000 + RESERVE_RTC_SLOW, len = 0x2000 - RESERVE_RTC_SLOW /* 8kB */
41+
rtc_slow_seg(RW) : ORIGIN = 0x50000000 + RESERVE_RTC_SLOW, len = 8k - RESERVE_RTC_SLOW
4242

4343
/* external memory, including data and text,
4444
4MB is the maximum, if external psram is bigger, paging is required */
45-
psram_seg(RWX) : ORIGIN = 0x3F800000, len = 0x400000 /* 4MB */
45+
psram_seg(RWX) : ORIGIN = 0x3F800000, len = 4M
4646
}
4747

4848
/* map generic regions to output sections */
49-
REGION_ALIAS("ROTEXT", irom_seg);
50-
REGION_ALIAS("RODATA", drom_seg);
51-
REGION_ALIAS("RWDATA", dram_seg);
49+
INCLUDE "alias.x"
50+
51+
PROVIDE(__pre_init = ESP32PreInit);
5252

5353
/* esp32 specific regions */
5454
SECTIONS {
5555
.rwtext :
5656
{
5757
. = ALIGN(4);
5858
*(.rwtext.literal .rwtext .rwtext.literal.* .rwtext.*)
59-
} > iram_seg
59+
} > iram_seg AT > RODATA
6060

6161
.rtc_fast.text : {
6262
. = ALIGN(4);
6363
*(.rtc_fast.literal .rtc_fast.text .rtc_fast.literal.* .rtc_fast.text.*)
64-
} > rtc_fast_iram_seg
64+
} > rtc_fast_iram_seg AT > RODATA
6565

6666
/*
6767
This section is required to skip rtc.text area because rtc_iram_seg and
6868
rtc_data_seg are reflect the same address space on different buses.
6969
*/
7070
.rtc_fast.dummy (NOLOAD) :
7171
{
72-
_rtc_dummy_start = ABSOLUTE(.);
73-
_rtc_fast_start = ABSOLUTE(.);
72+
_rtc_dummy_start = ABSOLUTE(.); /* needed to make section proper size */
7473
. = SIZEOF(.rtc_fast.text);
75-
_rtc_dummy_end = ABSOLUTE(.);
74+
_rtc_dummy_end = ABSOLUTE(.); /* needed to make section proper size */
7675
} > rtc_fast_dram_seg
7776

7877

7978
.rtc_fast.data :
8079
{
81-
. = ALIGN(4);
8280
_rtc_fast_data_start = ABSOLUTE(.);
81+
. = ALIGN(4);
8382
*(.rtc_fast.data .rtc_fast.data.*)
8483
_rtc_fast_data_end = ABSOLUTE(.);
85-
} > rtc_fast_dram_seg
84+
} > rtc_fast_dram_seg AT > RODATA
8685

87-
_rtc_fast_data_start_loadaddr = LOADADDR(.data);
86+
_rtc_fast_data_load = LOADADDR(.rtc_fast.data);
8887

8988
.rtc_fast.bss (NOLOAD) :
9089
{
91-
. = ALIGN(4);
9290
_rtc_fast_bss_start = ABSOLUTE(.);
91+
. = ALIGN(4);
9392
*(.rtc_fast.bss .rtc_fast.bss.*)
9493
_rtc_fast_bss_end = ABSOLUTE(.);
9594
} > rtc_fast_dram_seg
@@ -104,22 +103,22 @@ SECTIONS {
104103
.rtc_slow.text : {
105104
. = ALIGN(4);
106105
*(.rtc_slow.literal .rtc_slow.text .rtc_slow.literal.* .rtc_slow.text.*)
107-
} > rtc_slow_seg
106+
} > rtc_slow_seg AT > RODATA
108107

109108
.rtc_slow.data :
110109
{
111-
. = ALIGN(4);
112110
_rtc_slow_data_start = ABSOLUTE(.);
111+
. = ALIGN(4);
113112
*(.rtc_slow.data .rtc_slow.data.*)
114113
_rtc_slow_data_end = ABSOLUTE(.);
115-
} > rtc_slow_seg
114+
} > rtc_slow_seg AT > RODATA
116115

117-
_rtc_slow_data_start_loadaddr = LOADADDR(.data);
116+
_rtc_slow_data_load = LOADADDR(.rtc_slow.data);
118117

119118
.rtc_slow.bss (NOLOAD) :
120119
{
121-
. = ALIGN(4);
122120
_rtc_slow_bss_start = ABSOLUTE(.);
121+
. = ALIGN(4);
123122
*(.rtc_slow.bss .rtc_slow.bss.*)
124123
_rtc_slow_bss_end = ABSOLUTE(.);
125124
} > rtc_slow_seg
@@ -130,4 +129,28 @@ SECTIONS {
130129
*(.rtc_slow.noinit .rtc_slow.noinit.*)
131130
} > rtc_slow_seg
132131

132+
.external.data :
133+
{
134+
_external_data_start = ABSOLUTE(.);
135+
. = ALIGN(4);
136+
*(.external.data .external.data.*)
137+
_external_data_end = ABSOLUTE(.);
138+
} > psram_seg AT > RODATA
139+
140+
_external_data_load = LOADADDR(.external.data);
141+
142+
.external.bss (NOLOAD) :
143+
{
144+
_external_bss_start = ABSOLUTE(.);
145+
. = ALIGN(4);
146+
*(.external.bss .external.bss.*)
147+
_external_bss_end = ABSOLUTE(.);
148+
} > psram_seg
149+
150+
.external.noinit (NOLOAD) :
151+
{
152+
. = ALIGN(4);
153+
*(.external.noinit .external.noinit.*)
154+
} > psram_seg
133155
}
156+

ram.x

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REGION_ALIAS("ROTEXT", iram_seg);
2+
REGION_ALIAS("RODATA", dram_seg);
3+
REGION_ALIAS("RWDATA", dram_seg);

rom.x

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REGION_ALIAS("ROTEXT", irom_seg);
2+
REGION_ALIAS("RODATA", drom_seg);
3+
REGION_ALIAS("RWDATA", dram_seg);

0 commit comments

Comments
 (0)