Align nrf
This commit is contained in:
parent
c6a984f506
commit
54bbb4400d
@ -3,74 +3,37 @@
|
|||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.md")]
|
||||||
mod fmt;
|
mod fmt;
|
||||||
|
|
||||||
pub use embassy_boot::{AlignedBuffer, BootFlash, FirmwareUpdater, FlashConfig, Partition, SingleFlashConfig};
|
#[cfg(feature = "nightly")]
|
||||||
|
pub use embassy_boot::FirmwareUpdater;
|
||||||
|
pub use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareUpdaterConfig};
|
||||||
use embassy_nrf::nvmc::{Nvmc, PAGE_SIZE};
|
use embassy_nrf::nvmc::{Nvmc, PAGE_SIZE};
|
||||||
use embassy_nrf::peripherals::WDT;
|
use embassy_nrf::peripherals::WDT;
|
||||||
use embassy_nrf::wdt;
|
use embassy_nrf::wdt;
|
||||||
use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash};
|
use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash};
|
||||||
|
|
||||||
/// A bootloader for nRF devices.
|
/// A bootloader for nRF devices.
|
||||||
pub struct BootLoader<const BUFFER_SIZE: usize = PAGE_SIZE> {
|
pub struct BootLoader<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize = PAGE_SIZE> {
|
||||||
boot: embassy_boot::BootLoader,
|
boot: embassy_boot::BootLoader<ACTIVE, DFU, STATE>,
|
||||||
aligned_buf: AlignedBuffer<BUFFER_SIZE>,
|
aligned_buf: AlignedBuffer<BUFFER_SIZE>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "none")]
|
impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>
|
||||||
impl Default for BootLoader<PAGE_SIZE> {
|
BootLoader<ACTIVE, DFU, STATE, BUFFER_SIZE>
|
||||||
/// Create a new bootloader instance using parameters from linker script
|
{
|
||||||
fn default() -> Self {
|
|
||||||
extern "C" {
|
|
||||||
static __bootloader_state_start: u32;
|
|
||||||
static __bootloader_state_end: u32;
|
|
||||||
static __bootloader_active_start: u32;
|
|
||||||
static __bootloader_active_end: u32;
|
|
||||||
static __bootloader_dfu_start: u32;
|
|
||||||
static __bootloader_dfu_end: u32;
|
|
||||||
}
|
|
||||||
|
|
||||||
let active = unsafe {
|
|
||||||
Partition::new(
|
|
||||||
&__bootloader_active_start as *const u32 as u32,
|
|
||||||
&__bootloader_active_end as *const u32 as u32,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
let dfu = unsafe {
|
|
||||||
Partition::new(
|
|
||||||
&__bootloader_dfu_start as *const u32 as u32,
|
|
||||||
&__bootloader_dfu_end as *const u32 as u32,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
let state = unsafe {
|
|
||||||
Partition::new(
|
|
||||||
&__bootloader_state_start as *const u32 as u32,
|
|
||||||
&__bootloader_state_end as *const u32 as u32,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
trace!("ACTIVE: 0x{:x} - 0x{:x}", active.from, active.to);
|
|
||||||
trace!("DFU: 0x{:x} - 0x{:x}", dfu.from, dfu.to);
|
|
||||||
trace!("STATE: 0x{:x} - 0x{:x}", state.from, state.to);
|
|
||||||
|
|
||||||
Self::new(active, dfu, state)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
|
|
||||||
/// Create a new bootloader instance using the supplied partitions for active, dfu and state.
|
/// Create a new bootloader instance using the supplied partitions for active, dfu and state.
|
||||||
pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self {
|
pub fn new(config: BootLoaderConfig<ACTIVE, DFU, STATE>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
boot: embassy_boot::BootLoader::new(active, dfu, state),
|
boot: embassy_boot::BootLoader::new(config),
|
||||||
aligned_buf: AlignedBuffer([0; BUFFER_SIZE]),
|
aligned_buf: AlignedBuffer([0; BUFFER_SIZE]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inspect the bootloader state and perform actions required before booting, such as swapping
|
/// Inspect the bootloader state and perform actions required before booting, such as swapping
|
||||||
/// firmware.
|
/// firmware.
|
||||||
pub fn prepare<F: FlashConfig>(&mut self, flash: &mut F) -> usize {
|
pub fn prepare(&mut self) {
|
||||||
match self.boot.prepare_boot(flash, &mut self.aligned_buf.0) {
|
self.boot
|
||||||
Ok(_) => self.boot.boot_address(),
|
.prepare_boot(&mut self.aligned_buf.0)
|
||||||
Err(_) => panic!("boot prepare error!"),
|
.expect("Boot prepare error");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Boots the application without softdevice mechanisms.
|
/// Boots the application without softdevice mechanisms.
|
||||||
@ -79,10 +42,10 @@ impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
|
|||||||
///
|
///
|
||||||
/// 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: usize) -> ! {
|
pub unsafe fn load(&mut self, start: u32) -> ! {
|
||||||
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 as u32);
|
p.SCB.vtor.write(start);
|
||||||
cortex_m::asm::bootload(start as *const u32)
|
cortex_m::asm::bootload(start as *const u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +55,7 @@ impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
|
|||||||
///
|
///
|
||||||
/// 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(feature = "softdevice")]
|
#[cfg(feature = "softdevice")]
|
||||||
pub unsafe fn load(&mut self, _app: usize) -> ! {
|
pub unsafe fn load(&mut self, _app: u32) -> ! {
|
||||||
use nrf_softdevice_mbr as mbr;
|
use nrf_softdevice_mbr as mbr;
|
||||||
const NRF_SUCCESS: u32 = 0;
|
const NRF_SUCCESS: u32 = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user