|
12 | 12 | use core::convert::Infallible; |
13 | 13 | use core::mem::MaybeUninit; |
14 | 14 | use core::ops::Range; |
15 | | -use core::ptr; |
16 | 15 | use drv_lpc55_flash::{BYTES_PER_FLASH_PAGE, BYTES_PER_FLASH_WORD}; |
17 | 16 | use drv_lpc55_update_api::{ |
18 | 17 | Fwid, RawCabooseError, RotBootInfo, RotBootInfoV2, RotComponent, RotPage, |
@@ -1476,25 +1475,33 @@ fn bootstate() -> Result<RotBootStateV2, HandoffDataLoadError> { |
1476 | 1475 | RotBootStateV2::load_from_addr(addr) |
1477 | 1476 | } |
1478 | 1477 |
|
| 1478 | +extern "C" { |
| 1479 | + // Symbols injected by the linker. |
| 1480 | + // |
| 1481 | + // This requires adding `extern-regions = ["transient_override"]` to the task config. |
| 1482 | + pub static mut __REGION_TRANSIENT_OVERRIDE_BASE: [u32; 0]; |
| 1483 | +} |
| 1484 | + |
1479 | 1485 | fn set_transient_override(preference: [u8; 32]) { |
1480 | | - // Safety: Data is consumed by Bootleby on next boot. |
1481 | | - // There are no concurrent writers possible. |
1482 | | - // Calling this function multiple times is ok. |
1483 | | - // Bootleby is careful to vet contents before acting. |
| 1486 | + // Safety: populated by the linker, getting the address is fine. |
| 1487 | + // SAFETY: this points to a valid region of RAM that is otherwise unused by Rust, so we can |
| 1488 | + // write to it. |
1484 | 1489 | unsafe { |
1485 | | - ptr::write_volatile( |
1486 | | - ptr::addr_of_mut!(TRANSIENT_OVERRIDE), |
1487 | | - MaybeUninit::new(preference), |
1488 | | - ); |
| 1490 | + let override_addr = |
| 1491 | + core::ptr::addr_of_mut!(__REGION_TRANSIENT_OVERRIDE_BASE) |
| 1492 | + as *mut [u8; 32]; |
| 1493 | + core::ptr::write_volatile(override_addr, preference); |
1489 | 1494 | } |
1490 | 1495 | } |
1491 | 1496 |
|
1492 | 1497 | fn get_transient_override() -> [u8; 32] { |
1493 | | - // Safety: Data is consumed by Bootleby on next boot. |
1494 | | - // There are no concurrent writers possible. |
1495 | | - // Bootleby consumes and resets TRANSIENT_OVERRIDE. |
1496 | | - // The client may be verifying state set during update flows. |
1497 | | - unsafe { TRANSIENT_OVERRIDE.assume_init() } |
| 1498 | + // SAFETY: populated by the linker, getting the address is fine. |
| 1499 | + unsafe { |
| 1500 | + let override_addr = |
| 1501 | + core::ptr::addr_of_mut!(__REGION_TRANSIENT_OVERRIDE_BASE) |
| 1502 | + as *mut [u8; 32]; |
| 1503 | + core::ptr::read_volatile(override_addr) |
| 1504 | + } |
1498 | 1505 | } |
1499 | 1506 |
|
1500 | 1507 | // Preference constants are taken from bootleby:src/lib.rs |
|
0 commit comments