Merge pull request 'use volatile_write instead of ASM' (#19) from use-volatile-write-instead-of-asm into main
shared-hal-ci / Check build (push) Has been cancelled
shared-hal-ci / Check formatting (push) Has been cancelled
shared-hal-ci / Check Documentation Build (push) Has been cancelled
shared-hal-ci / Clippy (push) Has been cancelled
va108xx-ci / Check build (push) Has been cancelled
va108xx-ci / Run Tests (push) Has been cancelled
va108xx-ci / Check formatting (push) Has been cancelled
va108xx-ci / Check Documentation Build (push) Has been cancelled
va108xx-ci / Clippy (push) Has been cancelled
va416xx-ci / Check build (push) Has been cancelled
va416xx-ci / Run Tests (push) Has been cancelled
va416xx-ci / Check formatting (push) Has been cancelled
va416xx-ci / Check Documentation Build (push) Has been cancelled
va416xx-ci / Clippy (push) Has been cancelled

Reviewed-on: #19
This commit was merged in pull request #19.
This commit is contained in:
2026-04-09 11:41:26 +02:00
+6 -9
View File
@@ -181,7 +181,8 @@ fn check_own_crc(
// because the address of the bootloader is 0x0, so the NULL check fails and the functions
// panics.
#[allow(clippy::zero_ptr)]
let first_four_bytes = unsafe { core::ptr::read_volatile(0x0 as *const u32) }.to_ne_bytes();
let first_four_bytes =
unsafe { core::ptr::read_volatile(BOOTLOADER_START_ADDR as *const u32) }.to_ne_bytes();
let mut digest = CRC_ALGO.digest();
digest.update(&first_four_bytes);
digest.update(unsafe {
@@ -270,14 +271,10 @@ fn boot_app(
APP_B_START_ADDR
};
unsafe {
// First 4 bytes done with inline assembly, writing to the physical address 0x0 can not
// be done without it. See https://users.rust-lang.org/t/reading-from-physical-address-0x0/117408/2.
let first_four_bytes = core::ptr::read(base_addr as *const u32);
core::arch::asm!(
"str {0}, [{1}]",
in(reg) first_four_bytes, // Input: App vector table.
in(reg) BOOTLOADER_START_ADDR as *mut u32, // Input: destination pointer
);
let first_four_bytes = core::ptr::read_volatile(base_addr as *const u32);
#[allow(clippy::zero_ptr)]
core::ptr::write_volatile(BOOTLOADER_START_ADDR as *mut u32, first_four_bytes);
core::slice::from_raw_parts_mut(
(BOOTLOADER_START_ADDR + 4) as *mut u8,
(VECTOR_TABLE_LEN - 4) as usize,