Skip to content

Commit 4a5d56d

Browse files
authored
Remove flip link (#4295)
* Remove `flip-link` * Changelog entry * PR number
1 parent 3541ade commit 4a5d56d

File tree

10 files changed

+31
-95
lines changed

10 files changed

+31
-95
lines changed

esp-hal/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
280280
- Removed the `FullDuplex` trait from the PARL_IO driver. (#3339)
281281
- Removed `Flex::{set_as_input, set_as_output, set_drive_strength, set_as_open_drain, pull_direction}` functions (#3387)
282282
- The `Efuse::read_field_be` function has been removed (#3440)
283+
- The config option (`ESP_HAL_CONFIG_FLIP_LINK`) got removed, `ESP_HAL_CONFIG_WRITE_VEC_TABLE_MONITORING` will yield equally good results (#4295)
283284

284285
## [v1.0.0-beta.0] - 2025-02-24
285286

esp-hal/esp_config.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ options:
7070
- value: true
7171
active: 'chip == "esp32"'
7272

73-
- name: flip-link
74-
description: Move the stack to start of RAM to get zero-cost stack overflow protection.
75-
default:
76-
- value: false
77-
active: 'chip == "esp32c6" || chip == "esp32h2"'
78-
7973
- name: psram-mode
8074
description: SPIRAM chip mode
8175
default:

esp-hal/ld/esp32c2/esp32c2.x

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,4 @@ INCLUDE "metadata.x"
5454
INCLUDE "eh_frame.x"
5555
/* End of Shared sections */
5656

57-
#IF ESP_HAL_CONFIG_FLIP_LINK
58-
_dram_data_start = ORIGIN( DRAM );
59-
#ELSE
60-
_dram_data_start = ORIGIN( DRAM ) + SIZEOF(.trap) + SIZEOF(.rwtext);
61-
#ENDIF
57+
_dram_data_start = ORIGIN( DRAM ) + SIZEOF(.trap) + SIZEOF(.rwtext);

esp-hal/ld/esp32c3/esp32c3.x

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,4 @@ INCLUDE "metadata.x"
5555
INCLUDE "eh_frame.x"
5656
/* End of Shared sections */
5757

58-
#IF ESP_HAL_CONFIG_FLIP_LINK
59-
_dram_data_start = ORIGIN( DRAM );
60-
#ELSE
61-
_dram_data_start = ORIGIN( DRAM ) + SIZEOF(.trap) + SIZEOF(.rwtext);
62-
#ENDIF
58+
_dram_data_start = ORIGIN( DRAM ) + SIZEOF(.trap) + SIZEOF(.rwtext);

esp-hal/ld/esp32c6/esp32c6.x

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ SECTIONS {
1010
INCLUDE "rwdata.x"
1111
/* End of Shared sections */
1212
}
13-
#IF ESP_HAL_CONFIG_FLIP_LINK
14-
/* INSERT BEFORE does not seem to work for the .stack section. Instead, we place every RAM
15-
section after .stack if `flip_link` is enabled. */
16-
INSERT AFTER .stack;
17-
#ENDIF
1813

1914
SECTIONS {
2015
/**
@@ -39,8 +34,4 @@ INCLUDE "metadata.x"
3934
INCLUDE "eh_frame.x"
4035
/* End of Shared sections #2 */
4136

42-
#IF ESP_HAL_CONFIG_FLIP_LINK
43-
_dram_data_start = ORIGIN( RAM );
44-
#ELSE
45-
_dram_data_start = ORIGIN( RAM ) + SIZEOF(.trap) + SIZEOF(.rwtext);
46-
#ENDIF
37+
_dram_data_start = ORIGIN( RAM ) + SIZEOF(.trap) + SIZEOF(.rwtext);

esp-hal/ld/esp32h2/esp32h2.x

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ SECTIONS {
99
INCLUDE "rwdata.x"
1010
/* End of Shared sections */
1111
}
12-
#IF ESP_HAL_CONFIG_FLIP_LINK
13-
/* INSERT BEFORE does not seem to work for the .stack section. Instead, we place every RAM
14-
section after .stack if `flip_link` is enabled. */
15-
INSERT AFTER .stack;
16-
#ENDIF
1712

1813
SECTIONS {
1914
/**
@@ -37,8 +32,4 @@ INCLUDE "metadata.x"
3732
INCLUDE "eh_frame.x"
3833
/* End of Shared sections #2 */
3934

40-
#IF ESP_HAL_CONFIG_FLIP_LINK
41-
_dram_data_start = ORIGIN( RAM );
42-
#ELSE
43-
_dram_data_start = ORIGIN( RAM ) + SIZEOF(.trap) + SIZEOF(.rwtext);
44-
#ENDIF
35+
_dram_data_start = ORIGIN( RAM ) + SIZEOF(.trap) + SIZEOF(.rwtext);

esp-hal/ld/sections/stack.x

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@ SECTIONS {
88
/* The stack_guard for `stack-protector` mitigation - https://doc.rust-lang.org/rustc/exploit-mitigations.html#stack-smashing-protection */
99
__stack_chk_guard = ABSOLUTE(_stack_end) + ${ESP_HAL_CONFIG_STACK_GUARD_OFFSET};
1010

11-
/* no Xtensa chip is supported - so we can assume RISC-V */
12-
#IF ESP_HAL_CONFIG_FLIP_LINK
13-
/* Since we cannot know how much the alignment padding of the sections will add we shrink the stack for "the worst case"
14-
*/
15-
. = . + LENGTH(RWDATA) - (SIZEOF(.trap) + SIZEOF(.rwtext) + SIZEOF(.rwtext.wifi) + SIZEOF(.data) + SIZEOF(.bss) + SIZEOF(.noinit) + SIZEOF(.data.wifi)) - 304;
16-
#ELSE
1711
. = ORIGIN(RWDATA) + LENGTH(RWDATA);
18-
#ENDIF
12+
1913
. = ALIGN (4);
2014
_stack_start = ABSOLUTE(.);
2115
_stack_start_cpu0 = ABSOLUTE(.);

esp-hal/src/soc/mod.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -261,39 +261,36 @@ pub(crate) fn enable_main_stack_guard_monitoring() {
261261

262262
#[cfg(all(riscv, write_vec_table_monitoring))]
263263
pub(crate) fn setup_trap_section_protection() {
264-
#[cfg(not(flip_link))]
264+
if !cfg!(stack_guard_monitoring_with_debugger_connected)
265+
&& crate::debugger::debugger_connected()
265266
{
266-
if !cfg!(stack_guard_monitoring_with_debugger_connected)
267-
&& crate::debugger::debugger_connected()
268-
{
269-
return;
270-
}
267+
return;
268+
}
271269

272-
unsafe extern "C" {
273-
static _rwtext_len: u32;
274-
static _trap_section_origin: u32;
275-
}
270+
unsafe extern "C" {
271+
static _rwtext_len: u32;
272+
static _trap_section_origin: u32;
273+
}
276274

277-
let rwtext_len = core::ptr::addr_of!(_rwtext_len) as usize;
275+
let rwtext_len = core::ptr::addr_of!(_rwtext_len) as usize;
278276

279-
// protect as much as possible via NAPOT
280-
let len = 1 << (usize::BITS - rwtext_len.leading_zeros() - 1) as usize;
281-
if len == 0 {
282-
warn!("No trap vector protection available");
283-
return;
284-
}
277+
// protect as much as possible via NAPOT
278+
let len = 1 << (usize::BITS - rwtext_len.leading_zeros() - 1) as usize;
279+
if len == 0 {
280+
warn!("No trap vector protection available");
281+
return;
282+
}
285283

286-
// protect MTVEC and trap handlers
287-
// (probably plus some more bytes because of NAPOT)
288-
// via watchpoint 1.
289-
//
290-
// Why not use PMP? On C2/C3 the bootloader locks all available PMP entries.
291-
// And additionally we write to MTVEC for direct-vectoring and we write
292-
// to __EXTERNAL_INTERRUPTS when setting an interrupt handler.
293-
let addr = core::ptr::addr_of!(_trap_section_origin) as usize;
284+
// protect MTVEC and trap handlers
285+
// (probably plus some more bytes because of NAPOT)
286+
// via watchpoint 1.
287+
//
288+
// Why not use PMP? On C2/C3 the bootloader locks all available PMP entries.
289+
// And additionally we write to MTVEC for direct-vectoring and we write
290+
// to __EXTERNAL_INTERRUPTS when setting an interrupt handler.
291+
let addr = core::ptr::addr_of!(_trap_section_origin) as usize;
294292

295-
unsafe {
296-
crate::debugger::set_watchpoint(1, addr, len);
297-
}
293+
unsafe {
294+
crate::debugger::set_watchpoint(1, addr, len);
298295
}
299296
}

hil-test/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ harness = false
3636
name = "dma_mem2mem"
3737
harness = false
3838

39-
[[bin]]
40-
name = "flip_link"
41-
harness = false
42-
4339
[[bin]]
4440
name = "gpio"
4541
harness = false

hil-test/src/bin/flip_link.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)