aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-04-04 22:22:25 +0200
committerRasmus Melchior Jacobsen <[email protected]>2023-04-04 22:22:25 +0200
commita77ce1088d927266a23cbc971aed6facd3b7f918 (patch)
treebe5e752bc3d192209d9da7d2694f60623961de38
parente962fe794ce3c83b094e22523d0c59264983b036 (diff)
Align chip specific boot projects with new prepare_boot() signature
-rw-r--r--embassy-boot/nrf/src/lib.rs14
-rw-r--r--embassy-boot/rp/src/lib.rs16
-rw-r--r--embassy-boot/stm32/src/lib.rs14
3 files changed, 19 insertions, 25 deletions
diff --git a/embassy-boot/nrf/src/lib.rs b/embassy-boot/nrf/src/lib.rs
index f40ae62d6..d3774d308 100644
--- a/embassy-boot/nrf/src/lib.rs
+++ b/embassy-boot/nrf/src/lib.rs
@@ -11,13 +11,12 @@ use embassy_nrf::wdt;
11use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; 11use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash};
12 12
13/// A bootloader for nRF devices. 13/// A bootloader for nRF devices.
14pub struct BootLoader { 14pub struct BootLoader<const BUFFER_SIZE: usize = PAGE_SIZE> {
15 boot: embassy_boot::BootLoader, 15 boot: embassy_boot::BootLoader,
16 magic: AlignedBuffer<4>, 16 aligned_buf: AlignedBuffer<BUFFER_SIZE>,
17 page: AlignedBuffer<PAGE_SIZE>,
18} 17}
19 18
20impl Default for BootLoader { 19impl<const BUFFER_SIZE: usize> Default for BootLoader<BUFFER_SIZE> {
21 /// Create a new bootloader instance using parameters from linker script 20 /// Create a new bootloader instance using parameters from linker script
22 fn default() -> Self { 21 fn default() -> Self {
23 extern "C" { 22 extern "C" {
@@ -56,20 +55,19 @@ impl Default for BootLoader {
56 } 55 }
57} 56}
58 57
59impl BootLoader { 58impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
60 /// Create a new bootloader instance using the supplied partitions for active, dfu and state. 59 /// Create a new bootloader instance using the supplied partitions for active, dfu and state.
61 pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self { 60 pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self {
62 Self { 61 Self {
63 boot: embassy_boot::BootLoader::new(active, dfu, state), 62 boot: embassy_boot::BootLoader::new(active, dfu, state),
64 magic: AlignedBuffer([0; 4]), 63 aligned_buf: AlignedBuffer([0; BUFFER_SIZE]),
65 page: AlignedBuffer([0; PAGE_SIZE]),
66 } 64 }
67 } 65 }
68 66
69 /// Inspect the bootloader state and perform actions required before booting, such as swapping 67 /// Inspect the bootloader state and perform actions required before booting, such as swapping
70 /// firmware. 68 /// firmware.
71 pub fn prepare<F: FlashConfig>(&mut self, flash: &mut F) -> usize { 69 pub fn prepare<F: FlashConfig>(&mut self, flash: &mut F) -> usize {
72 match self.boot.prepare_boot(flash, &mut self.magic.0, &mut self.page.0) { 70 match self.boot.prepare_boot(flash, &mut self.aligned_buf.0) {
73 Ok(_) => self.boot.boot_address(), 71 Ok(_) => self.boot.boot_address(),
74 Err(_) => panic!("boot prepare error!"), 72 Err(_) => panic!("boot prepare error!"),
75 } 73 }
diff --git a/embassy-boot/rp/src/lib.rs b/embassy-boot/rp/src/lib.rs
index 6df34133e..c163db131 100644
--- a/embassy-boot/rp/src/lib.rs
+++ b/embassy-boot/rp/src/lib.rs
@@ -5,33 +5,31 @@
5mod fmt; 5mod fmt;
6 6
7pub use embassy_boot::{AlignedBuffer, BootFlash, FirmwareUpdater, FlashConfig, Partition, SingleFlashConfig, State}; 7pub use embassy_boot::{AlignedBuffer, BootFlash, FirmwareUpdater, FlashConfig, Partition, SingleFlashConfig, State};
8use embassy_rp::flash::{Flash, ERASE_SIZE, WRITE_SIZE}; 8use embassy_rp::flash::{Flash, ERASE_SIZE};
9use embassy_rp::peripherals::{FLASH, WATCHDOG}; 9use embassy_rp::peripherals::{FLASH, WATCHDOG};
10use embassy_rp::watchdog::Watchdog; 10use embassy_rp::watchdog::Watchdog;
11use embassy_time::Duration; 11use embassy_time::Duration;
12use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; 12use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash};
13 13
14/// A bootloader for RP2040 devices. 14/// A bootloader for RP2040 devices.
15pub struct BootLoader { 15pub struct BootLoader<const BUFFER_SIZE: usize = ERASE_SIZE> {
16 boot: embassy_boot::BootLoader, 16 boot: embassy_boot::BootLoader,
17 magic: AlignedBuffer<WRITE_SIZE>, 17 aligned_buf: AlignedBuffer<BUFFER_SIZE>,
18 page: AlignedBuffer<ERASE_SIZE>,
19} 18}
20 19
21impl BootLoader { 20impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
22 /// Create a new bootloader instance using the supplied partitions for active, dfu and state. 21 /// Create a new bootloader instance using the supplied partitions for active, dfu and state.
23 pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self { 22 pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self {
24 Self { 23 Self {
25 boot: embassy_boot::BootLoader::new(active, dfu, state), 24 boot: embassy_boot::BootLoader::new(active, dfu, state),
26 magic: AlignedBuffer([0; WRITE_SIZE]), 25 aligned_buf: AlignedBuffer([0; BUFFER_SIZE]),
27 page: AlignedBuffer([0; ERASE_SIZE]),
28 } 26 }
29 } 27 }
30 28
31 /// Inspect the bootloader state and perform actions required before booting, such as swapping 29 /// Inspect the bootloader state and perform actions required before booting, such as swapping
32 /// firmware. 30 /// firmware.
33 pub fn prepare<F: FlashConfig>(&mut self, flash: &mut F) -> usize { 31 pub fn prepare<F: FlashConfig>(&mut self, flash: &mut F) -> usize {
34 match self.boot.prepare_boot(flash, self.magic.as_mut(), self.page.as_mut()) { 32 match self.boot.prepare_boot(flash, self.aligned_buf.as_mut()) {
35 Ok(_) => embassy_rp::flash::FLASH_BASE + self.boot.boot_address(), 33 Ok(_) => embassy_rp::flash::FLASH_BASE + self.boot.boot_address(),
36 Err(_) => panic!("boot prepare error!"), 34 Err(_) => panic!("boot prepare error!"),
37 } 35 }
@@ -54,7 +52,7 @@ impl BootLoader {
54 } 52 }
55} 53}
56 54
57impl Default for BootLoader { 55impl<const BUFFER_SIZE: usize> Default for BootLoader<BUFFER_SIZE> {
58 /// Create a new bootloader instance using parameters from linker script 56 /// Create a new bootloader instance using parameters from linker script
59 fn default() -> Self { 57 fn default() -> Self {
60 extern "C" { 58 extern "C" {
diff --git a/embassy-boot/stm32/src/lib.rs b/embassy-boot/stm32/src/lib.rs
index 82f712c4d..1f63fcd63 100644
--- a/embassy-boot/stm32/src/lib.rs
+++ b/embassy-boot/stm32/src/lib.rs
@@ -7,26 +7,24 @@ mod fmt;
7pub use embassy_boot::{AlignedBuffer, BootFlash, FirmwareUpdater, FlashConfig, Partition, SingleFlashConfig, State}; 7pub use embassy_boot::{AlignedBuffer, BootFlash, FirmwareUpdater, FlashConfig, Partition, SingleFlashConfig, State};
8 8
9/// A bootloader for STM32 devices. 9/// A bootloader for STM32 devices.
10pub struct BootLoader<const PAGE_SIZE: usize, const WRITE_SIZE: usize> { 10pub struct BootLoader<const BUFFER_SIZE: usize> {
11 boot: embassy_boot::BootLoader, 11 boot: embassy_boot::BootLoader,
12 magic: AlignedBuffer<WRITE_SIZE>, 12 aligned_buf: AlignedBuffer<BUFFER_SIZE>,
13 page: AlignedBuffer<PAGE_SIZE>,
14} 13}
15 14
16impl<const PAGE_SIZE: usize, const WRITE_SIZE: usize> BootLoader<PAGE_SIZE, WRITE_SIZE> { 15impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
17 /// Create a new bootloader instance using the supplied partitions for active, dfu and state. 16 /// Create a new bootloader instance using the supplied partitions for active, dfu and state.
18 pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self { 17 pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self {
19 Self { 18 Self {
20 boot: embassy_boot::BootLoader::new(active, dfu, state), 19 boot: embassy_boot::BootLoader::new(active, dfu, state),
21 magic: AlignedBuffer([0; WRITE_SIZE]), 20 aligned_buf: AlignedBuffer([0; BUFFER_SIZE]),
22 page: AlignedBuffer([0; PAGE_SIZE]),
23 } 21 }
24 } 22 }
25 23
26 /// Inspect the bootloader state and perform actions required before booting, such as swapping 24 /// Inspect the bootloader state and perform actions required before booting, such as swapping
27 /// firmware. 25 /// firmware.
28 pub fn prepare<F: FlashConfig>(&mut self, flash: &mut F) -> usize { 26 pub fn prepare<F: FlashConfig>(&mut self, flash: &mut F) -> usize {
29 match self.boot.prepare_boot(flash, self.magic.as_mut(), self.page.as_mut()) { 27 match self.boot.prepare_boot(flash, self.aligned_buf.as_mut()) {
30 Ok(_) => embassy_stm32::flash::FLASH_BASE + self.boot.boot_address(), 28 Ok(_) => embassy_stm32::flash::FLASH_BASE + self.boot.boot_address(),
31 Err(_) => panic!("boot prepare error!"), 29 Err(_) => panic!("boot prepare error!"),
32 } 30 }
@@ -49,7 +47,7 @@ impl<const PAGE_SIZE: usize, const WRITE_SIZE: usize> BootLoader<PAGE_SIZE, WRIT
49 } 47 }
50} 48}
51 49
52impl<const PAGE_SIZE: usize, const WRITE_SIZE: usize> Default for BootLoader<PAGE_SIZE, WRITE_SIZE> { 50impl<const BUFFER_SIZE: usize> Default for BootLoader<BUFFER_SIZE> {
53 /// Create a new bootloader instance using parameters from linker script 51 /// Create a new bootloader instance using parameters from linker script
54 fn default() -> Self { 52 fn default() -> Self {
55 extern "C" { 53 extern "C" {