Support multiple flash instances in embassy-boot

* Add FlashProvider and FlashConfig traits to define flash
characteristics
* Use traits in bootloader to retrieve flash handles and for
copying data between flash instances
* Add convenience implementations for using a single flash instance.
This commit is contained in:
Ulf Lilleengen
2022-04-19 14:42:38 +02:00
parent e2ed41b383
commit 2afff617f6
8 changed files with 207 additions and 52 deletions

View File

@@ -1,5 +1,4 @@
[unstable]
namespaced-features = true
build-std = ["core"]
build-std-features = ["panic_immediate_abort"]

View File

@@ -12,7 +12,7 @@ defmt = { version = "0.3", optional = true }
defmt-rtt = { version = "0.3", optional = true }
embassy = { path = "../../embassy", default-features = false }
embassy-nrf = { path = "../../embassy-nrf", default-features = false }
embassy-nrf = { path = "../../embassy-nrf", default-features = false, features = ["nightly"] }
embassy-boot = { path = "../boot", default-features = false }
cortex-m = { version = "0.7" }
cortex-m-rt = { version = "0.7" }

View File

@@ -4,7 +4,9 @@
mod fmt;
pub use embassy_boot::{FirmwareUpdater, Partition, State, BOOT_MAGIC};
pub use embassy_boot::{
FirmwareUpdater, FlashProvider, Partition, SingleFlashProvider, State, BOOT_MAGIC,
};
use embassy_nrf::{
nvmc::{Nvmc, PAGE_SIZE},
peripherals::WDT,
@@ -62,7 +64,7 @@ impl BootLoader {
}
/// Boots the application without softdevice mechanisms
pub fn prepare<F: NorFlash + ReadNorFlash>(&mut self, flash: &mut F) -> usize {
pub fn prepare<F: FlashProvider>(&mut self, flash: &mut F) -> usize {
match self.boot.prepare_boot(flash) {
Ok(_) => self.boot.boot_address(),
Err(_) => panic!("boot prepare error!"),

View File

@@ -22,7 +22,11 @@ fn main() -> ! {
*/
let mut bl = BootLoader::default();
let start = bl.prepare(&mut WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, 5));
let start = bl.prepare(&mut SingleFlashProvider::new(&mut WatchdogFlash::start(
Nvmc::new(p.NVMC),
p.WDT,
5,
)));
unsafe { bl.load(start) }
}