Skip to content

Commit 7f72edf

Browse files
committed
Add skip-data-copy feature for when the .data LMA is uninitialized after boot
1 parent edc79e2 commit 7f72edf

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

cortex-m-rt/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- Mark `pre_init` as deprecated
1111
- Add `set_msplim` feature to conditionally set the MSPLIM register at device
1212
reset ([#580]).
13+
- Add `skip-data-copy` feature to prevent copying the `.data` section from the
14+
load address to the virtual address. Use when the load address is inaccessible
15+
by the time user code runs, such as when copying from flash or when booting
16+
from an external device. Note that this relies on the bootloader to have already
17+
copied `.data` to the VMA before relinquishing control.
1318

1419
## [v0.7.5]
1520

cortex-m-rt/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ set-vtor = []
4848
set-msplim = []
4949
zero-init-ram = []
5050
paint-stack = []
51+
skip-data-copy = []
5152

5253
[package.metadata.docs.rs]
5354
features = ["device"]

cortex-m-rt/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@
220220
//! You can then inspect memory during debugging to determine how much of the stack has been used -
221221
//! where the stack has been used the 'paint' will have been 'scrubbed off' and the memory will
222222
//! have a value other than `STACK_PAINT_VALUE`.
223+
//!
224+
//! ## `skip-data-copy`
225+
//!
226+
//! Skips copying the .data section (containing the initial values for static variables) when a bootloader
227+
//! (or other mechanism) is responsible for initializing the section. Use when the code is loaded from a location
228+
//! that's invalid after the bootloader runs (e.g. copy-from-XIP or copy-from-network boot). For example,
229+
//! rp2040-boot2 with `BOOT_LOADER_RAM_MEMCPY` (not the default of boot2!) set, which copies the code out
230+
//! of the XIP flash memory and then disables the XIP peripheral afterwards.
223231
//!
224232
//! # Inspection
225233
//!
@@ -616,6 +624,7 @@ cfg_global_asm! {
616624
1:",
617625

618626
// Initialise .data memory. `__sdata`, `__sidata`, and `__edata` come from the linker script.
627+
#[cfg(not(feature = "skip-data-copy"))]
619628
"ldr r0, =__sdata
620629
ldr r1, =__edata
621630
ldr r2, =__sidata

0 commit comments

Comments
 (0)