Skip to content

Commit 9b51b40

Browse files
committed
Move zero-init-ram to just before bss initialisation, so that pre_init occurs before
1 parent e501494 commit 9b51b40

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

cortex-m-rt/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Add `zero-init-ram` feature to initialize RAM with zeros on startup. This can be necessary on
11+
safety-critical hardware to properly initialize memory integrity measures.
12+
13+
## [v0.7.3]
14+
1015
- Fixed a potential miscompilation caused by the initial stack pointer
1116
not being 8-byte aligned. This issue affected 0.7.1 and 0.7.2; for
1217
more details please see [the advisory] ([#467]).
1318
- A linker error is generated if the initial stack pointer is not 8-byte aligned ([#464]).
1419
- The initial stack pointer is now forced to be 8-byte aligned in the linker script,
1520
to defend against it being overridden outside of the cortex-m-rt linker script ([#465]).
16-
- Add `zero-init-ram` feature to initialize RAM with zeros on startup. This can be necessary on
17-
safety-critical hardware to properly initialize memory integrity measures.
1821

1922
[the advisory]: https://github.com/rust-embedded/cortex-m/discussions/469
2023
[#464]: https://github.com/rust-embedded/cortex-m/issues/464

cortex-m-rt/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -521,19 +521,6 @@ cfg_global_asm! {
521521
"ldr r0, =_stack_start
522522
msr msp, r0",
523523

524-
// If enabled, initialize RAM with zeros. This is not usually required, but might be necessary
525-
// to properly initialize checksum-based memory integrity measures on safety-critical hardware.
526-
#[cfg(feature = "zero-init-ram")]
527-
"ldr r0, =_ram_start
528-
ldr r1, =_ram_end
529-
movs r2, #0
530-
0:
531-
cmp r1, r0
532-
beq 1f
533-
stm r0!, {{r2}}
534-
b 0b
535-
1:",
536-
537524
// If enabled, initialise VTOR to the start of the vector table. This is normally initialised
538525
// by a bootloader when the non-reset value is required, but some bootloaders do not set it,
539526
// leading to frustrating issues where everything seems to work but interrupts are never
@@ -549,6 +536,19 @@ cfg_global_asm! {
549536
// Example use cases include disabling default watchdogs or enabling RAM.
550537
"bl __pre_init",
551538

539+
// If enabled, initialize RAM with zeros. This is not usually required, but might be necessary
540+
// to properly initialize checksum-based memory integrity measures on safety-critical hardware.
541+
#[cfg(feature = "zero-init-ram")]
542+
"ldr r0, =_ram_start
543+
ldr r1, =_ram_end
544+
movs r2, #0
545+
0:
546+
cmp r1, r0
547+
beq 1f
548+
stm r0!, {{r2}}
549+
b 0b
550+
1:",
551+
552552
// Initialise .bss memory. `__sbss` and `__ebss` come from the linker script.
553553
#[cfg(not(feature = "zero-init-ram"))]
554554
"ldr r0, =__sbss

0 commit comments

Comments
 (0)