Skip to content

Commit c15fc67

Browse files
authored
Esp32: ensure wifi data comes before bss (#3635)
* Place wifi data before bss * Minor fixes * Changelog * Fix the stack guard's address
1 parent 793b01b commit c15fc67

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

esp-hal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
### Fixed
1818

1919
- Fixed a typo in the ESP32-C3 memory linker script, causing ICACHE to not be defined (#3613)
20+
- Prevent bootloops when DRAM is close to being full. (#3635)
2021

2122
### Removed
2223

esp-hal/ld/esp32/memory.x

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/* This memory map assumes the flash cache is on;
2-
the blocks used are excluded from the various memory ranges
3-
1+
/* This memory map assumes the flash cache is on;
2+
the blocks used are excluded from the various memory ranges
3+
44
see: https://github.com/espressif/esp-idf/blob/5b1189570025ba027f2ff6c2d91f6ffff3809cc2/components/heap/port/esp32/memory_layout.c
55
for details
66
*/
@@ -19,8 +19,8 @@ MEMORY
1919

2020
reserved_for_rom_seg : ORIGIN = 0x3FFAE000, len = 8k /* SRAM2; reserved for usage by the ROM */
2121
dram_seg ( RW ) : ORIGIN = 0x3FFB0000 + RESERVE_DRAM, len = 176k - RESERVE_DRAM /* SRAM2+1; first 64kB used by BT if enable */
22-
23-
/*
22+
23+
/*
2424
* The following values come from the heap allocator in esp-idf: https://github.com/espressif/esp-idf/blob/ab63aaa4a24a05904da2862d627f3987ecbeafd0/components/heap/port/esp32/memory_layout.c#L137-L157
2525
* The segment dram2_seg after the rom data space is not mentioned in the esp32 linker scripts in esp-idf, instead the space after is used as heap space.
2626
* It seems not all rom data space is reserved, but only "core"/"important" ROM functions that may be called after booting from ROM.
@@ -30,15 +30,15 @@ MEMORY
3030

3131
/*
3232
* The following values are derived from the __stack and _stack_sentry values from ROM.
33-
* They represent the stacks used for each core setup by ROM code. In theory both of these
33+
* They represent the stacks used for each core setup by ROM code. In theory both of these
3434
* can be reclaimed once both cores are running, but for now we play it safe and reserve them both.
3535
*/
3636
reserved_rom_stack_pro : ORIGIN = 0x3ffe1320, len = 11264
3737
reserved_rom_stack_app : ORIGIN = 0x3ffe5230, len = 11264
3838

3939
dram2_seg : ORIGIN = 0x3ffe7e30, len = 98767 /* the rest of DRAM after the rom data segments and rom stacks in the middle */
4040

41-
/* external flash
41+
/* external flash
4242
The 0x20 offset is a convenience for the app binary image generation.
4343
Flash cache has 64KB pages. The .bin file which is flashed to the chip
4444
has a 0x18 byte file header, and each segment has a 0x08 byte segment

esp-hal/ld/sections/rwdata.x

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
/* LMA of .data */
2424
_sidata = LOADADDR(.data);
2525

26+
.data.wifi :
27+
{
28+
. = ALIGN(4);
29+
*( .dram1 .dram1.*)
30+
. = ALIGN(4);
31+
} > RWDATA
32+
2633
.bss (NOLOAD) : ALIGN(4)
2734
{
2835
_bss_start = ABSOLUTE(.);
@@ -51,10 +58,3 @@ _sidata = LOADADDR(.data);
5158
*(.uninit .uninit.*)
5259
. = ALIGN(4);
5360
} > RWDATA
54-
55-
.data.wifi :
56-
{
57-
. = ALIGN(4);
58-
*( .dram1 .dram1.*)
59-
. = ALIGN(4);
60-
} > RWDATA

esp-hal/ld/sections/stack.x

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SECTIONS {
66
_stack_end_cpu0 = ABSOLUTE(.);
77

88
/* The stack_guard for `stack-protector` mitigation - https://doc.rust-lang.org/rustc/exploit-mitigations.html#stack-smashing-protection */
9-
__stack_chk_guard = _stack_end + ${ESP_HAL_CONFIG_STACK_GUARD_OFFSET};
9+
__stack_chk_guard = ABSOLUTE(_stack_end) + ${ESP_HAL_CONFIG_STACK_GUARD_OFFSET};
1010

1111
/* no Xtensa chip is supported - so we can assume RISC-V */
1212
#IF ESP_HAL_CONFIG_FLIP_LINK

esp-wifi/src/wifi/os_adapter.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,11 +1495,15 @@ pub unsafe extern "C" fn log_writev(
14951495
format: *const crate::binary::c_types::c_char,
14961496
args: crate::binary::include::va_list,
14971497
) {
1498-
crate::binary::log::syslog(
1499-
level,
1500-
format as _,
1501-
core::mem::transmute::<crate::binary::include::va_list, core::ffi::VaListImpl<'_>>(args),
1502-
);
1498+
unsafe {
1499+
crate::binary::log::syslog(
1500+
level,
1501+
format as _,
1502+
core::mem::transmute::<crate::binary::include::va_list, core::ffi::VaListImpl<'_>>(
1503+
args,
1504+
),
1505+
);
1506+
}
15031507
}
15041508

15051509
/// **************************************************************************

hil-test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ esp-metadata = { path = "../esp-metadata" }
269269
default = []
270270
unstable = ["esp-hal/unstable"]
271271

272-
defmt = ["dep:defmt-rtt", "esp-hal/defmt", "embedded-test/defmt", "esp-wifi/defmt", "esp-hal-embassy/defmt"]
272+
defmt = ["dep:defmt-rtt", "esp-hal/defmt", "embedded-test/defmt", "esp-wifi?/defmt", "esp-hal-embassy?/defmt"]
273273

274274
# Device support (required!):
275275
esp32 = [

0 commit comments

Comments
 (0)