diff --git a/cortex-m-rt/CHANGELOG.md b/cortex-m-rt/CHANGELOG.md index fe639fb8..176a6784 100644 --- a/cortex-m-rt/CHANGELOG.md +++ b/cortex-m-rt/CHANGELOG.md @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Mark `pre_init` as deprecated - Add `set_msplim` feature to conditionally set the MSPLIM register at device reset ([#580]). +- Add `skip-data-copy` feature to prevent copying the `.data` section from the + load address to the virtual address. Use when the load address is inaccessible + by the time user code runs, such as when copying from flash or when booting + from an external device. Note that this relies on the bootloader to have already + copied `.data` to the VMA before relinquishing control. ## [v0.7.5] diff --git a/cortex-m-rt/Cargo.toml b/cortex-m-rt/Cargo.toml index 377a8d5d..b2be8aa1 100644 --- a/cortex-m-rt/Cargo.toml +++ b/cortex-m-rt/Cargo.toml @@ -48,6 +48,7 @@ set-vtor = [] set-msplim = [] zero-init-ram = [] paint-stack = [] +skip-data-copy = [] [package.metadata.docs.rs] features = ["device"] diff --git a/cortex-m-rt/src/lib.rs b/cortex-m-rt/src/lib.rs index 20ed4f11..7d2cac1d 100644 --- a/cortex-m-rt/src/lib.rs +++ b/cortex-m-rt/src/lib.rs @@ -221,6 +221,14 @@ //! where the stack has been used the 'paint' will have been 'scrubbed off' and the memory will //! have a value other than `STACK_PAINT_VALUE`. //! +//! ## `skip-data-copy` +//! +//! Skips copying the .data section (containing the initial values for static variables) when a bootloader +//! (or other mechanism) is responsible for initializing the section. Use when the code is loaded from a location +//! that's invalid after the bootloader runs (e.g. copy-from-XIP or copy-from-network boot). For example, +//! rp2040-boot2 with `BOOT_LOADER_RAM_MEMCPY` (not the default of boot2!) set, which copies the code out +//! of the XIP flash memory and then disables the XIP peripheral afterwards. +//! //! # Inspection //! //! This section covers how to inspect a binary that builds on top of `cortex-m-rt`. @@ -616,6 +624,7 @@ cfg_global_asm! { 1:", // Initialise .data memory. `__sdata`, `__sidata`, and `__edata` come from the linker script. + #[cfg(not(feature = "skip-data-copy"))] "ldr r0, =__sdata ldr r1, =__edata ldr r2, =__sidata