|
208 | 208 | //! where the stack has been used the 'paint' will have been 'scrubbed off' and the memory will
|
209 | 209 | //! have a value other than `STACK_PAINT_VALUE`.
|
210 | 210 | //!
|
| 211 | +//! ## `skip-data-init` |
| 212 | +//! |
| 213 | +//! If this feature is enabled, the `.data` section initialization is skipped during startup. |
| 214 | +//! By default, cortex-m-rt copies the `.data` section from its load address (LMA) in Flash |
| 215 | +//! to its virtual address (VMA) in RAM. However, in some scenarios this copy is unnecessary |
| 216 | +//! or undesirable: |
| 217 | +//! |
| 218 | +//! - When using bootloaders like RP2040's boot2 that copy all data from Flash to RAM and then |
| 219 | +//! unmap the Flash, the cortex-m-rt data initialization would fail because Flash is no longer |
| 220 | +//! accessible. |
| 221 | +//! - When the `.data` section is already placed in RAM at the correct address (LMA equals VMA). |
| 222 | +//! |
| 223 | +//! When this feature is enabled, it is the user's responsibility to ensure that the `.data` |
| 224 | +//! section is properly initialized before the program's main function is called. This can be |
| 225 | +//! done by: |
| 226 | +//! |
| 227 | +//! - Using a bootloader that copies the data before jumping to the Reset handler |
| 228 | +//! - Setting `__sidata = ADDR(.data)` in the linker script to make LMA equal to VMA (though this |
| 229 | +//! wastes Flash space) |
| 230 | +//! - Other custom initialization mechanisms |
| 231 | +//! |
| 232 | +//! **WARNING:** Using this feature without ensuring proper `.data` initialization will result |
| 233 | +//! in undefined behavior if your program uses initialized static variables. |
| 234 | +//! |
211 | 235 | //! # Inspection
|
212 | 236 | //!
|
213 | 237 | //! This section covers how to inspect a binary that builds on top of `cortex-m-rt`.
|
@@ -603,6 +627,7 @@ cfg_global_asm! {
|
603 | 627 | 1:",
|
604 | 628 |
|
605 | 629 | // Initialise .data memory. `__sdata`, `__sidata`, and `__edata` come from the linker script.
|
| 630 | + #[cfg(not(feature = "skip-data-init"))] |
606 | 631 | "ldr r0, =__sdata
|
607 | 632 | ldr r1, =__edata
|
608 | 633 | ldr r2, =__sidata
|
|
0 commit comments