aboutsummaryrefslogtreecommitdiff
path: root/embassy-boot
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-05-30 13:56:35 +0200
committerRasmus Melchior Jacobsen <[email protected]>2023-05-30 13:56:35 +0200
commit54bbb4400d02e40d142d3f2cd9186c7892374d83 (patch)
treeaf797f8f303723054d0bfdfaeec0f9533bcf353a /embassy-boot
parentc6a984f506530bc08464800abc332be9c49ac198 (diff)
Align nrf
Diffstat (limited to 'embassy-boot')
-rw-r--r--embassy-boot/nrf/src/lib.rs71
1 files changed, 17 insertions, 54 deletions
diff --git a/embassy-boot/nrf/src/lib.rs b/embassy-boot/nrf/src/lib.rs
index 710798bdb..e26b07c9f 100644
--- a/embassy-boot/nrf/src/lib.rs
+++ b/embassy-boot/nrf/src/lib.rs
@@ -3,74 +3,37 @@
3#![doc = include_str!("../README.md")] 3#![doc = include_str!("../README.md")]
4mod fmt; 4mod fmt;
5 5
6pub use embassy_boot::{AlignedBuffer, BootFlash, FirmwareUpdater, FlashConfig, Partition, SingleFlashConfig}; 6#[cfg(feature = "nightly")]
7pub use embassy_boot::FirmwareUpdater;
8pub use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareUpdaterConfig};
7use embassy_nrf::nvmc::{Nvmc, PAGE_SIZE}; 9use embassy_nrf::nvmc::{Nvmc, PAGE_SIZE};
8use embassy_nrf::peripherals::WDT; 10use embassy_nrf::peripherals::WDT;
9use embassy_nrf::wdt; 11use embassy_nrf::wdt;
10use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; 12use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash};
11 13
12/// A bootloader for nRF devices. 14/// A bootloader for nRF devices.
13pub struct BootLoader<const BUFFER_SIZE: usize = PAGE_SIZE> { 15pub struct BootLoader<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize = PAGE_SIZE> {
14 boot: embassy_boot::BootLoader, 16 boot: embassy_boot::BootLoader<ACTIVE, DFU, STATE>,
15 aligned_buf: AlignedBuffer<BUFFER_SIZE>, 17 aligned_buf: AlignedBuffer<BUFFER_SIZE>,
16} 18}
17 19
18#[cfg(target_os = "none")] 20impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>
19impl Default for BootLoader<PAGE_SIZE> { 21 BootLoader<ACTIVE, DFU, STATE, BUFFER_SIZE>
20 /// Create a new bootloader instance using parameters from linker script 22{
21 fn default() -> Self {
22 extern "C" {
23 static __bootloader_state_start: u32;
24 static __bootloader_state_end: u32;
25 static __bootloader_active_start: u32;
26 static __bootloader_active_end: u32;
27 static __bootloader_dfu_start: u32;
28 static __bootloader_dfu_end: u32;
29 }
30
31 let active = unsafe {
32 Partition::new(
33 &__bootloader_active_start as *const u32 as u32,
34 &__bootloader_active_end as *const u32 as u32,
35 )
36 };
37 let dfu = unsafe {
38 Partition::new(
39 &__bootloader_dfu_start as *const u32 as u32,
40 &__bootloader_dfu_end as *const u32 as u32,
41 )
42 };
43 let state = unsafe {
44 Partition::new(
45 &__bootloader_state_start as *const u32 as u32,
46 &__bootloader_state_end as *const u32 as u32,
47 )
48 };
49
50 trace!("ACTIVE: 0x{:x} - 0x{:x}", active.from, active.to);
51 trace!("DFU: 0x{:x} - 0x{:x}", dfu.from, dfu.to);
52 trace!("STATE: 0x{:x} - 0x{:x}", state.from, state.to);
53
54 Self::new(active, dfu, state)
55 }
56}
57
58impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
59 /// Create a new bootloader instance using the supplied partitions for active, dfu and state. 23 /// Create a new bootloader instance using the supplied partitions for active, dfu and state.
60 pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self { 24 pub fn new(config: BootLoaderConfig<ACTIVE, DFU, STATE>) -> Self {
61 Self { 25 Self {
62 boot: embassy_boot::BootLoader::new(active, dfu, state), 26 boot: embassy_boot::BootLoader::new(config),
63 aligned_buf: AlignedBuffer([0; BUFFER_SIZE]), 27 aligned_buf: AlignedBuffer([0; BUFFER_SIZE]),
64 } 28 }
65 } 29 }
66 30
67 /// Inspect the bootloader state and perform actions required before booting, such as swapping 31 /// Inspect the bootloader state and perform actions required before booting, such as swapping
68 /// firmware. 32 /// firmware.
69 pub fn prepare<F: FlashConfig>(&mut self, flash: &mut F) -> usize { 33 pub fn prepare(&mut self) {
70 match self.boot.prepare_boot(flash, &mut self.aligned_buf.0) { 34 self.boot
71 Ok(_) => self.boot.boot_address(), 35 .prepare_boot(&mut self.aligned_buf.0)
72 Err(_) => panic!("boot prepare error!"), 36 .expect("Boot prepare error");
73 }
74 } 37 }
75 38
76 /// Boots the application without softdevice mechanisms. 39 /// Boots the application without softdevice mechanisms.
@@ -79,10 +42,10 @@ impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
79 /// 42 ///
80 /// This modifies the stack pointer and reset vector and will run code placed in the active partition. 43 /// This modifies the stack pointer and reset vector and will run code placed in the active partition.
81 #[cfg(not(feature = "softdevice"))] 44 #[cfg(not(feature = "softdevice"))]
82 pub unsafe fn load(&mut self, start: usize) -> ! { 45 pub unsafe fn load(&mut self, start: u32) -> ! {
83 let mut p = cortex_m::Peripherals::steal(); 46 let mut p = cortex_m::Peripherals::steal();
84 p.SCB.invalidate_icache(); 47 p.SCB.invalidate_icache();
85 p.SCB.vtor.write(start as u32); 48 p.SCB.vtor.write(start);
86 cortex_m::asm::bootload(start as *const u32) 49 cortex_m::asm::bootload(start as *const u32)
87 } 50 }
88 51
@@ -92,7 +55,7 @@ impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
92 /// 55 ///
93 /// This modifies the stack pointer and reset vector and will run code placed in the active partition. 56 /// This modifies the stack pointer and reset vector and will run code placed in the active partition.
94 #[cfg(feature = "softdevice")] 57 #[cfg(feature = "softdevice")]
95 pub unsafe fn load(&mut self, _app: usize) -> ! { 58 pub unsafe fn load(&mut self, _app: u32) -> ! {
96 use nrf_softdevice_mbr as mbr; 59 use nrf_softdevice_mbr as mbr;
97 const NRF_SUCCESS: u32 = 0; 60 const NRF_SUCCESS: u32 = 0;
98 61