Align examples

This commit is contained in:
Rasmus Melchior Jacobsen 2023-05-30 14:03:31 +02:00
parent c2aca45b8d
commit 36e00caf4d
18 changed files with 108 additions and 65 deletions

View File

@ -42,7 +42,9 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>
/// ///
/// This modifies the stack pointer and reset vector and will run code placed in the active partition. /// This modifies the stack pointer and reset vector and will run code placed in the active partition.
#[cfg(not(feature = "softdevice"))] #[cfg(not(feature = "softdevice"))]
pub unsafe fn load(&mut self, start: u32) -> ! { pub unsafe fn load(self, start: u32) -> ! {
core::mem::drop(self.boot);
let mut p = cortex_m::Peripherals::steal(); let mut p = cortex_m::Peripherals::steal();
p.SCB.invalidate_icache(); p.SCB.invalidate_icache();
p.SCB.vtor.write(start); p.SCB.vtor.write(start);

View File

@ -42,7 +42,9 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>
/// # Safety /// # Safety
/// ///
/// This modifies the stack pointer and reset vector and will run code placed in the active partition. /// This modifies the stack pointer and reset vector and will run code placed in the active partition.
pub unsafe fn load(&mut self, start: u32) -> ! { pub unsafe fn load(self, start: u32) -> ! {
core::mem::drop(self.boot);
trace!("Loading app at 0x{:x}", start); trace!("Loading app at 0x{:x}", start);
#[allow(unused_mut)] #[allow(unused_mut)]
let mut p = cortex_m::Peripherals::steal(); let mut p = cortex_m::Peripherals::steal();

View File

@ -38,7 +38,9 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>
/// # Safety /// # Safety
/// ///
/// This modifies the stack pointer and reset vector and will run code placed in the active partition. /// This modifies the stack pointer and reset vector and will run code placed in the active partition.
pub unsafe fn load(&mut self, start: u32) -> ! { pub unsafe fn load(self, start: u32) -> ! {
core::mem::drop(self.boot);
trace!("Loading app at 0x{:x}", start); trace!("Loading app at 0x{:x}", start);
#[allow(unused_mut)] #[allow(unused_mut)]
let mut p = cortex_m::Peripherals::steal(); let mut p = cortex_m::Peripherals::steal();

View File

@ -3,12 +3,13 @@
#![macro_use] #![macro_use]
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
use embassy_boot_nrf::FirmwareUpdater; use embassy_boot_nrf::{FirmwareUpdater, FirmwareUpdaterConfig};
use embassy_embedded_hal::adapter::BlockingAsync; use embassy_embedded_hal::adapter::BlockingAsync;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
use embassy_nrf::nvmc::Nvmc; use embassy_nrf::nvmc::Nvmc;
use embassy_nrf::wdt::{self, Watchdog}; use embassy_nrf::wdt::{self, Watchdog};
use embassy_sync::mutex::Mutex;
use panic_reset as _; use panic_reset as _;
static APP_B: &[u8] = include_bytes!("../../b.bin"); static APP_B: &[u8] = include_bytes!("../../b.bin");
@ -45,9 +46,10 @@ async fn main(_spawner: Spawner) {
}; };
let nvmc = Nvmc::new(p.NVMC); let nvmc = Nvmc::new(p.NVMC);
let mut nvmc = BlockingAsync::new(nvmc); let nvmc = Mutex::new(BlockingAsync::new(nvmc));
let mut updater = FirmwareUpdater::default(); let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc);
let mut updater = FirmwareUpdater::new(config);
loop { loop {
led.set_low(); led.set_low();
button.wait_for_any_edge().await; button.wait_for_any_edge().await;
@ -56,11 +58,11 @@ async fn main(_spawner: Spawner) {
for chunk in APP_B.chunks(4096) { for chunk in APP_B.chunks(4096) {
let mut buf: [u8; 4096] = [0; 4096]; let mut buf: [u8; 4096] = [0; 4096];
buf[..chunk.len()].copy_from_slice(chunk); buf[..chunk.len()].copy_from_slice(chunk);
updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); updater.write_firmware(offset, &buf).await.unwrap();
offset += chunk.len(); offset += chunk.len();
} }
let mut magic = [0; 4]; let mut magic = [0; 4];
updater.mark_updated(&mut nvmc, &mut magic).await.unwrap(); updater.mark_updated(&mut magic).await.unwrap();
led.set_high(); led.set_high();
cortex_m::peripheral::SCB::sys_reset(); cortex_m::peripheral::SCB::sys_reset();
} }

View File

@ -20,6 +20,7 @@ embedded-hal = { version = "0.2.6" }
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.0" cortex-m-rt = "0.7.0"
embedded-storage = "0.3.0"
[features] [features]
default = ["panic-reset"] default = ["panic-reset"]

View File

@ -9,6 +9,9 @@ use embassy_rp::flash::Flash;
use embassy_rp::gpio::{Level, Output}; use embassy_rp::gpio::{Level, Output};
use embassy_rp::watchdog::Watchdog; use embassy_rp::watchdog::Watchdog;
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};
use embassy_sync::blocking_mutex::Mutex;
use core::cell::RefCell;
use embedded_storage::nor_flash::NorFlash;
#[cfg(feature = "panic-probe")] #[cfg(feature = "panic-probe")]
use panic_probe as _; use panic_probe as _;
#[cfg(feature = "panic-reset")] #[cfg(feature = "panic-reset")]
@ -26,9 +29,11 @@ async fn main(_s: Spawner) {
let mut watchdog = Watchdog::new(p.WATCHDOG); let mut watchdog = Watchdog::new(p.WATCHDOG);
watchdog.start(Duration::from_secs(8)); watchdog.start(Duration::from_secs(8));
let mut flash: Flash<_, FLASH_SIZE> = Flash::new_blocking(p.FLASH); let flash: Flash<_, FLASH_SIZE> = Flash::new(p.FLASH);
let flash = Mutex::new(RefCell::new(flash));
let mut updater = FirmwareUpdater::default(); let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash);
let mut updater = BlockingFirmwareUpdater::new(config);
Timer::after(Duration::from_secs(5)).await; Timer::after(Duration::from_secs(5)).await;
watchdog.feed(); watchdog.feed();
@ -36,8 +41,8 @@ async fn main(_s: Spawner) {
let mut offset = 0; let mut offset = 0;
let mut buf: AlignedBuffer<4096> = AlignedBuffer([0; 4096]); let mut buf: AlignedBuffer<4096> = AlignedBuffer([0; 4096]);
defmt::info!("preparing update"); defmt::info!("preparing update");
let mut writer = updater let writer = updater
.prepare_update_blocking(&mut flash) .prepare_update()
.map_err(|e| defmt::warn!("E: {:?}", defmt::Debug2Format(&e))) .map_err(|e| defmt::warn!("E: {:?}", defmt::Debug2Format(&e)))
.unwrap(); .unwrap();
defmt::info!("writer created, starting write"); defmt::info!("writer created, starting write");
@ -45,13 +50,13 @@ async fn main(_s: Spawner) {
buf.0[..chunk.len()].copy_from_slice(chunk); buf.0[..chunk.len()].copy_from_slice(chunk);
defmt::info!("writing block at offset {}", offset); defmt::info!("writing block at offset {}", offset);
writer writer
.write_block_blocking(offset, &buf.0[..], &mut flash, 256) .write(offset, &buf.0[..])
.unwrap(); .unwrap();
offset += chunk.len(); offset += chunk.len() as u32;
} }
watchdog.feed(); watchdog.feed();
defmt::info!("firmware written, marking update"); defmt::info!("firmware written, marking update");
updater.mark_updated_blocking(&mut flash, &mut buf.0[..1]).unwrap(); updater.mark_updated(&mut buf.0[..1]).unwrap();
Timer::after(Duration::from_secs(2)).await; Timer::after(Duration::from_secs(2)).await;
led.set_low(); led.set_low();
defmt::info!("update marked, resetting"); defmt::info!("update marked, resetting");

View File

@ -4,7 +4,8 @@
#[cfg(feature = "defmt-rtt")] #[cfg(feature = "defmt-rtt")]
use defmt_rtt::*; use defmt_rtt::*;
use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater, FirmwareUpdaterConfig};
use embassy_sync::mutex::Mutex;
use embassy_embedded_hal::adapter::BlockingAsync; use embassy_embedded_hal::adapter::BlockingAsync;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput; use embassy_stm32::exti::ExtiInput;
@ -18,7 +19,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin");
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default()); let p = embassy_stm32::init(Default::default());
let flash = Flash::new_blocking(p.FLASH); let flash = Flash::new_blocking(p.FLASH);
let mut flash = BlockingAsync::new(flash); let flash = Mutex::new(BlockingAsync::new(flash));
let button = Input::new(p.PC13, Pull::Up); let button = Input::new(p.PC13, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI13); let mut button = ExtiInput::new(button, p.EXTI13);
@ -26,17 +27,18 @@ async fn main(_spawner: Spawner) {
let mut led = Output::new(p.PA5, Level::Low, Speed::Low); let mut led = Output::new(p.PA5, Level::Low, Speed::Low);
led.set_high(); led.set_high();
let mut updater = FirmwareUpdater::default(); let config = FirmwareUpdaterConfig::from_linkerfile(&flash);
let mut updater = FirmwareUpdater::new(config);
button.wait_for_falling_edge().await; button.wait_for_falling_edge().await;
let mut offset = 0; let mut offset = 0;
for chunk in APP_B.chunks(2048) { for chunk in APP_B.chunks(2048) {
let mut buf: [u8; 2048] = [0; 2048]; let mut buf: [u8; 2048] = [0; 2048];
buf[..chunk.len()].copy_from_slice(chunk); buf[..chunk.len()].copy_from_slice(chunk);
updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); updater.write_firmware(offset, &buf).await.unwrap();
offset += chunk.len(); offset += chunk.len();
} }
let mut magic = AlignedBuffer([0; WRITE_SIZE]); let mut magic = AlignedBuffer([0; WRITE_SIZE]);
updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap(); updater.mark_updated(magic.as_mut()).await.unwrap();
led.set_low(); led.set_low();
cortex_m::peripheral::SCB::sys_reset(); cortex_m::peripheral::SCB::sys_reset();
} }

View File

@ -4,7 +4,7 @@
#[cfg(feature = "defmt-rtt")] #[cfg(feature = "defmt-rtt")]
use defmt_rtt::*; use defmt_rtt::*;
use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig};
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput; use embassy_stm32::exti::ExtiInput;
use embassy_stm32::flash::{Flash, WRITE_SIZE}; use embassy_stm32::flash::{Flash, WRITE_SIZE};
@ -16,7 +16,8 @@ static APP_B: &[u8] = include_bytes!("../../b.bin");
#[embassy_executor::main] #[embassy_executor::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default()); let p = embassy_stm32::init(Default::default());
let mut flash = Flash::new_blocking(p.FLASH); let flash = Flash::new_blocking(p.FLASH);
let flash = Mutex::new(RefCell::new(flash));
let button = Input::new(p.PC13, Pull::Down); let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13); let mut button = ExtiInput::new(button, p.EXTI13);
@ -24,20 +25,21 @@ async fn main(_spawner: Spawner) {
let mut led = Output::new(p.PB7, Level::Low, Speed::Low); let mut led = Output::new(p.PB7, Level::Low, Speed::Low);
led.set_high(); led.set_high();
let mut updater = FirmwareUpdater::default(); let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash);
let mut writer = updater.prepare_update_blocking(&mut flash).unwrap(); let mut updater = BlockingFirmwareUpdater::new(config);
let mut writer = updater.prepare_update().unwrap();
button.wait_for_rising_edge().await; button.wait_for_rising_edge().await;
let mut offset = 0; let mut offset = 0;
let mut buf = AlignedBuffer([0; 4096]); let mut buf = AlignedBuffer([0; 4096]);
for chunk in APP_B.chunks(4096) { for chunk in APP_B.chunks(4096) {
buf.as_mut()[..chunk.len()].copy_from_slice(chunk); buf.as_mut()[..chunk.len()].copy_from_slice(chunk);
writer writer
.write_block_blocking(offset, buf.as_ref(), &mut flash, chunk.len()) .write(offset, buf.as_ref())
.unwrap(); .unwrap();
offset += chunk.len(); offset += chunk.len();
} }
let mut magic = AlignedBuffer([0; WRITE_SIZE]); let mut magic = AlignedBuffer([0; WRITE_SIZE]);
updater.mark_updated_blocking(&mut flash, magic.as_mut()).unwrap(); updater.mark_updated(magic.as_mut()).unwrap();
led.set_low(); led.set_low();
cortex_m::peripheral::SCB::sys_reset(); cortex_m::peripheral::SCB::sys_reset();
} }

View File

@ -4,7 +4,7 @@
#[cfg(feature = "defmt-rtt")] #[cfg(feature = "defmt-rtt")]
use defmt_rtt::*; use defmt_rtt::*;
use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; use embassy_boot_stm32::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig};
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput; use embassy_stm32::exti::ExtiInput;
use embassy_stm32::flash::{Flash, WRITE_SIZE}; use embassy_stm32::flash::{Flash, WRITE_SIZE};
@ -16,7 +16,8 @@ static APP_B: &[u8] = include_bytes!("../../b.bin");
#[embassy_executor::main] #[embassy_executor::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default()); let p = embassy_stm32::init(Default::default());
let mut flash = Flash::new_blocking(p.FLASH); let flash = Flash::new_blocking(p.FLASH);
let flash = Mutex::new(RefCell::new(flash));
let button = Input::new(p.PC13, Pull::Down); let button = Input::new(p.PC13, Pull::Down);
let mut button = ExtiInput::new(button, p.EXTI13); let mut button = ExtiInput::new(button, p.EXTI13);
@ -24,21 +25,21 @@ async fn main(_spawner: Spawner) {
let mut led = Output::new(p.PB14, Level::Low, Speed::Low); let mut led = Output::new(p.PB14, Level::Low, Speed::Low);
led.set_high(); led.set_high();
let mut updater = FirmwareUpdater::default(); let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash);
let mut updater = BlockingFirmwareUpdater::new(config);
let mut writer = updater.prepare_update_blocking(&mut flash).unwrap(); let mut writer = updater.prepare_update().unwrap();
button.wait_for_rising_edge().await; button.wait_for_rising_edge().await;
let mut offset = 0; let mut offset = 0;
let mut buf = AlignedBuffer([0; 4096]); let mut buf = AlignedBuffer([0; 4096]);
for chunk in APP_B.chunks(4096) { for chunk in APP_B.chunks(4096) {
buf.as_mut()[..chunk.len()].copy_from_slice(chunk); buf.as_mut()[..chunk.len()].copy_from_slice(chunk);
writer writer
.write_block_blocking(offset, buf.as_ref(), &mut flash, 4096) .write(offset, buf.as_ref())
.unwrap(); .unwrap();
offset += chunk.len(); offset += chunk.len();
} }
let mut magic = AlignedBuffer([0; WRITE_SIZE]); let mut magic = AlignedBuffer([0; WRITE_SIZE]);
updater.mark_updated_blocking(&mut flash, magic.as_mut()).unwrap(); updater.mark_updated(magic.as_mut()).unwrap();
led.set_low(); led.set_low();
cortex_m::peripheral::SCB::sys_reset(); cortex_m::peripheral::SCB::sys_reset();
} }

View File

@ -4,7 +4,7 @@
#[cfg(feature = "defmt-rtt")] #[cfg(feature = "defmt-rtt")]
use defmt_rtt::*; use defmt_rtt::*;
use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater, FirmwareUpdaterConfig};
use embassy_embedded_hal::adapter::BlockingAsync; use embassy_embedded_hal::adapter::BlockingAsync;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput; use embassy_stm32::exti::ExtiInput;
@ -19,7 +19,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin");
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default()); let p = embassy_stm32::init(Default::default());
let flash = Flash::new_blocking(p.FLASH); let flash = Flash::new_blocking(p.FLASH);
let mut flash = BlockingAsync::new(flash); let flash = Mutex::new(BlockingAsync::new(flash));
let button = Input::new(p.PB2, Pull::Up); let button = Input::new(p.PB2, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI2); let mut button = ExtiInput::new(button, p.EXTI2);
@ -28,18 +28,19 @@ async fn main(_spawner: Spawner) {
led.set_high(); led.set_high();
let mut updater = FirmwareUpdater::default(); let config = FirmwareUpdaterConfig::from_linkerfile(&flash);
let mut updater = FirmwareUpdater::new(config);
button.wait_for_falling_edge().await; button.wait_for_falling_edge().await;
let mut offset = 0; let mut offset = 0;
for chunk in APP_B.chunks(128) { for chunk in APP_B.chunks(128) {
let mut buf: [u8; 128] = [0; 128]; let mut buf: [u8; 128] = [0; 128];
buf[..chunk.len()].copy_from_slice(chunk); buf[..chunk.len()].copy_from_slice(chunk);
updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); updater.write_firmware(offset, &buf).await.unwrap();
offset += chunk.len(); offset += chunk.len();
} }
let mut magic = AlignedBuffer([0; WRITE_SIZE]); let mut magic = AlignedBuffer([0; WRITE_SIZE]);
updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap(); updater.mark_updated(magic.as_mut()).await.unwrap();
led.set_low(); led.set_low();
Timer::after(Duration::from_secs(1)).await; Timer::after(Duration::from_secs(1)).await;
cortex_m::peripheral::SCB::sys_reset(); cortex_m::peripheral::SCB::sys_reset();

View File

@ -4,7 +4,7 @@
#[cfg(feature = "defmt-rtt")] #[cfg(feature = "defmt-rtt")]
use defmt_rtt::*; use defmt_rtt::*;
use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater}; use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater, FirmwareUpdaterConfig};
use embassy_embedded_hal::adapter::BlockingAsync; use embassy_embedded_hal::adapter::BlockingAsync;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput; use embassy_stm32::exti::ExtiInput;
@ -18,7 +18,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin");
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default()); let p = embassy_stm32::init(Default::default());
let flash = Flash::new_blocking(p.FLASH); let flash = Flash::new_blocking(p.FLASH);
let mut flash = BlockingAsync::new(flash); let flash = Mutex::new(BlockingAsync::new(flash));
let button = Input::new(p.PC13, Pull::Up); let button = Input::new(p.PC13, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI13); let mut button = ExtiInput::new(button, p.EXTI13);
@ -26,13 +26,14 @@ async fn main(_spawner: Spawner) {
let mut led = Output::new(p.PB14, Level::Low, Speed::Low); let mut led = Output::new(p.PB14, Level::Low, Speed::Low);
led.set_high(); led.set_high();
let mut updater = FirmwareUpdater::default(); let config = FirmwareUpdaterConfig::from_linkerfile(&flash);
let mut updater = FirmwareUpdater::new(config);
button.wait_for_falling_edge().await; button.wait_for_falling_edge().await;
let mut offset = 0; let mut offset = 0;
for chunk in APP_B.chunks(2048) { for chunk in APP_B.chunks(2048) {
let mut buf: [u8; 2048] = [0; 2048]; let mut buf: [u8; 2048] = [0; 2048];
buf[..chunk.len()].copy_from_slice(chunk); buf[..chunk.len()].copy_from_slice(chunk);
updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); updater.write_firmware(offset, &buf).await.unwrap();
offset += chunk.len(); offset += chunk.len();
} }
let mut magic = AlignedBuffer([0; WRITE_SIZE]); let mut magic = AlignedBuffer([0; WRITE_SIZE]);

View File

@ -18,7 +18,7 @@ static APP_B: &[u8] = include_bytes!("../../b.bin");
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default()); let p = embassy_stm32::init(Default::default());
let flash = Flash::new_blocking(p.FLASH); let flash = Flash::new_blocking(p.FLASH);
let mut flash = BlockingAsync::new(flash); let mut flash = Mutex::new(BlockingAsync::new(flash));
let button = Input::new(p.PA0, Pull::Up); let button = Input::new(p.PA0, Pull::Up);
let mut button = ExtiInput::new(button, p.EXTI0); let mut button = ExtiInput::new(button, p.EXTI0);
@ -26,7 +26,8 @@ async fn main(_spawner: Spawner) {
let mut led = Output::new(p.PB9, Level::Low, Speed::Low); let mut led = Output::new(p.PB9, Level::Low, Speed::Low);
led.set_high(); led.set_high();
let mut updater = FirmwareUpdater::default(); let config = FirmwareUpdaterConfig::from_linkerfile(&flash);
let mut updater = FirmwareUpdater::new(config);
button.wait_for_falling_edge().await; button.wait_for_falling_edge().await;
//defmt::info!("Starting update"); //defmt::info!("Starting update");
let mut offset = 0; let mut offset = 0;
@ -34,11 +35,11 @@ async fn main(_spawner: Spawner) {
let mut buf: [u8; 2048] = [0; 2048]; let mut buf: [u8; 2048] = [0; 2048];
buf[..chunk.len()].copy_from_slice(chunk); buf[..chunk.len()].copy_from_slice(chunk);
// defmt::info!("Writing chunk at 0x{:x}", offset); // defmt::info!("Writing chunk at 0x{:x}", offset);
updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); updater.write_firmware(offset, &buf).await.unwrap();
offset += chunk.len(); offset += chunk.len();
} }
let mut magic = AlignedBuffer([0; WRITE_SIZE]); let mut magic = AlignedBuffer([0; WRITE_SIZE]);
updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap(); updater.mark_updated(magic.as_mut()).await.unwrap();
//defmt::info!("Marked as updated"); //defmt::info!("Marked as updated");
led.set_low(); led.set_low();
cortex_m::peripheral::SCB::sys_reset(); cortex_m::peripheral::SCB::sys_reset();

View File

@ -12,6 +12,7 @@ defmt-rtt = { version = "0.4", optional = true }
embassy-nrf = { path = "../../../../embassy-nrf", features = ["nightly"] } embassy-nrf = { path = "../../../../embassy-nrf", features = ["nightly"] }
embassy-boot-nrf = { path = "../../../../embassy-boot/nrf" } embassy-boot-nrf = { path = "../../../../embassy-boot/nrf" }
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
embassy-sync = { path = "../../../../embassy-sync" }
cortex-m-rt = { version = "0.7" } cortex-m-rt = { version = "0.7" }
cfg-if = "1.0.0" cfg-if = "1.0.0"

View File

@ -1,12 +1,15 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use core::cell::RefCell;
use cortex_m_rt::{entry, exception}; use cortex_m_rt::{entry, exception};
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
use defmt_rtt as _; use defmt_rtt as _;
use embassy_boot_nrf::*; use embassy_boot_nrf::*;
use embassy_nrf::nvmc::Nvmc; use embassy_nrf::nvmc::Nvmc;
use embassy_nrf::wdt; use embassy_nrf::wdt;
use embassy_sync::blocking_mutex::Mutex;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
@ -20,19 +23,21 @@ fn main() -> ! {
} }
*/ */
let mut bl = BootLoader::default();
let mut wdt_config = wdt::Config::default(); let mut wdt_config = wdt::Config::default();
wdt_config.timeout_ticks = 32768 * 5; // timeout seconds wdt_config.timeout_ticks = 32768 * 5; // timeout seconds
wdt_config.run_during_sleep = true; wdt_config.run_during_sleep = true;
wdt_config.run_during_debug_halt = false; wdt_config.run_during_debug_halt = false;
let start = bl.prepare(&mut SingleFlashConfig::new(&mut BootFlash::new(WatchdogFlash::start( let flash = WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, wdt_config);
Nvmc::new(p.NVMC), let flash = Mutex::new(RefCell::new(flash));
p.WDT,
wdt_config, let config = BootLoaderConfig::from_linkerfile_blocking(&flash);
)))); let active_offset = config.active.offset();
unsafe { bl.load(start) } let mut bl: BootLoader<_, _, _> = BootLoader::new(config);
bl.prepare();
unsafe { bl.load(active_offset) }
} }
#[no_mangle] #[no_mangle]

View File

@ -11,6 +11,7 @@ defmt-rtt = { version = "0.4", optional = true }
embassy-rp = { path = "../../../../embassy-rp", features = ["nightly"] } embassy-rp = { path = "../../../../embassy-rp", features = ["nightly"] }
embassy-boot-rp = { path = "../../../../embassy-boot/rp" } embassy-boot-rp = { path = "../../../../embassy-boot/rp" }
embassy-sync = { path = "../../../../embassy-sync" }
embassy-time = { path = "../../../../embassy-time", features = ["nightly"] } embassy-time = { path = "../../../../embassy-time", features = ["nightly"] }
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }

View File

@ -1,10 +1,13 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use core::cell::RefCell;
use cortex_m_rt::{entry, exception}; use cortex_m_rt::{entry, exception};
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
use defmt_rtt as _; use defmt_rtt as _;
use embassy_boot_rp::*; use embassy_boot_rp::*;
use embassy_sync::blocking_mutex::Mutex;
use embassy_time::Duration; use embassy_time::Duration;
const FLASH_SIZE: usize = 2 * 1024 * 1024; const FLASH_SIZE: usize = 2 * 1024 * 1024;
@ -21,13 +24,16 @@ fn main() -> ! {
} }
*/ */
let mut bl: BootLoader = BootLoader::default();
let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8)); let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8));
let mut flash = BootFlash::new(flash); let flash = Mutex::new(RefCell::new(flash));
let start = bl.prepare(&mut SingleFlashConfig::new(&mut flash));
core::mem::drop(flash);
unsafe { bl.load(start) } let config = BootLoaderConfig::from_linkerfile_blocking(&flash);
let active_offset = config.active.offset();
let mut bl: BootLoader<_, _, _> = BootLoader::new(config);
bl.prepare();
unsafe { bl.load(embassy_rp::flash::FLASH_BASE as u32 + active_offset) }
} }
#[no_mangle] #[no_mangle]

View File

@ -12,6 +12,7 @@ defmt-rtt = { version = "0.4", optional = true }
embassy-stm32 = { path = "../../../../embassy-stm32", features = ["nightly"] } embassy-stm32 = { path = "../../../../embassy-stm32", features = ["nightly"] }
embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32" } embassy-boot-stm32 = { path = "../../../../embassy-boot/stm32" }
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
embassy-sync = { path = "../../../../embassy-sync" }
cortex-m-rt = { version = "0.7" } cortex-m-rt = { version = "0.7" }
embedded-storage = "0.3.0" embedded-storage = "0.3.0"
embedded-storage-async = "0.4.0" embedded-storage-async = "0.4.0"

View File

@ -1,11 +1,14 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use core::cell::RefCell;
use cortex_m_rt::{entry, exception}; use cortex_m_rt::{entry, exception};
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
use defmt_rtt as _; use defmt_rtt as _;
use embassy_boot_stm32::*; use embassy_boot_stm32::*;
use embassy_stm32::flash::Flash; use embassy_stm32::flash::{Flash, BANK1_REGION};
use embassy_sync::blocking_mutex::Mutex;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
@ -19,12 +22,16 @@ fn main() -> ! {
} }
*/ */
let mut bl: BootLoader<2048> = BootLoader::default();
let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); let layout = Flash::new_blocking(p.FLASH).into_blocking_regions();
let mut flash = BootFlash::new(layout.bank1_region); let flash = Mutex::new(RefCell::new(layout.bank1_region));
let start = bl.prepare(&mut SingleFlashConfig::new(&mut flash));
core::mem::drop(flash); let config = BootLoaderConfig::from_linkerfile_blocking(&flash);
unsafe { bl.load(start) } let active_offset = config.active.offset();
let mut bl: BootLoader<_, _, _, 2048> = BootLoader::new(config);
bl.prepare();
unsafe { bl.load(BANK1_REGION.base + active_offset) }
} }
#[no_mangle] #[no_mangle]