aboutsummaryrefslogtreecommitdiff
path: root/examples/boot
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2022-08-30 13:07:35 +0200
committerUlf Lilleengen <[email protected]>2022-09-02 08:25:36 +0200
commit3ca73144765411994759194a2279b567f4508be5 (patch)
tree7c2466e14eb91321d35f831384c633f9936e8977 /examples/boot
parent7542505cf903930520773f5b6b5ff239b78a8f9c (diff)
Remove generic const expressions from embassy-boot
* Remove the need for generic const expressions and use buffers provided in the flash config. * Extend embedded-storage traits to simplify generics. * Document all public APIs * Add toplevel README * Expose AlignedBuffer type for convenience. * Update examples
Diffstat (limited to 'examples/boot')
-rw-r--r--examples/boot/application/nrf/src/bin/a.rs3
-rw-r--r--examples/boot/application/stm32f3/src/bin/a.rs7
-rw-r--r--examples/boot/application/stm32f7/src/bin/a.rs7
-rw-r--r--examples/boot/application/stm32h7/Cargo.toml2
-rwxr-xr-xexamples/boot/application/stm32h7/flash-boot.sh3
-rw-r--r--examples/boot/application/stm32h7/src/bin/a.rs16
-rw-r--r--examples/boot/application/stm32l0/src/bin/a.rs7
-rw-r--r--examples/boot/application/stm32l1/src/bin/a.rs7
-rw-r--r--examples/boot/application/stm32l4/src/bin/a.rs7
-rw-r--r--examples/boot/application/stm32wl/src/bin/a.rs7
-rw-r--r--examples/boot/bootloader/nrf/src/main.rs6
-rw-r--r--examples/boot/bootloader/stm32/src/main.rs8
12 files changed, 46 insertions, 34 deletions
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs
index bd8fa3246..133a3e678 100644
--- a/examples/boot/application/nrf/src/bin/a.rs
+++ b/examples/boot/application/nrf/src/bin/a.rs
@@ -36,7 +36,8 @@ async fn main(_spawner: Spawner) {
36 updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); 36 updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap();
37 offset += chunk.len(); 37 offset += chunk.len();
38 } 38 }
39 updater.update(&mut nvmc).await.unwrap(); 39 let mut magic = [0; 4];
40 updater.mark_updated(&mut nvmc, &mut magic).await.unwrap();
40 led.set_high(); 41 led.set_high();
41 cortex_m::peripheral::SCB::sys_reset(); 42 cortex_m::peripheral::SCB::sys_reset();
42 } 43 }
diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs
index 11eecc5e2..fdbd5ab99 100644
--- a/examples/boot/application/stm32f3/src/bin/a.rs
+++ b/examples/boot/application/stm32f3/src/bin/a.rs
@@ -4,11 +4,11 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater};
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use panic_reset as _; 13use panic_reset as _;
14 14
@@ -35,7 +35,8 @@ async fn main(_spawner: Spawner) {
35 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); 35 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
36 offset += chunk.len(); 36 offset += chunk.len();
37 } 37 }
38 updater.update(&mut flash).await.unwrap(); 38 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
39 updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap();
39 led.set_low(); 40 led.set_low();
40 cortex_m::peripheral::SCB::sys_reset(); 41 cortex_m::peripheral::SCB::sys_reset();
41} 42}
diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs
index a3b66e7c9..c08880fb3 100644
--- a/examples/boot/application/stm32f7/src/bin/a.rs
+++ b/examples/boot/application/stm32f7/src/bin/a.rs
@@ -4,11 +4,11 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater};
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use panic_reset as _; 13use panic_reset as _;
14 14
@@ -35,7 +35,8 @@ async fn main(_spawner: Spawner) {
35 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); 35 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
36 offset += chunk.len(); 36 offset += chunk.len();
37 } 37 }
38 updater.update(&mut flash).await.unwrap(); 38 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
39 updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap();
39 led.set_low(); 40 led.set_low();
40 cortex_m::peripheral::SCB::sys_reset(); 41 cortex_m::peripheral::SCB::sys_reset();
41} 42}
diff --git a/examples/boot/application/stm32h7/Cargo.toml b/examples/boot/application/stm32h7/Cargo.toml
index 5669527fe..7a76a8db5 100644
--- a/examples/boot/application/stm32h7/Cargo.toml
+++ b/examples/boot/application/stm32h7/Cargo.toml
@@ -4,7 +4,7 @@ name = "embassy-boot-stm32h7-examples"
4version = "0.1.0" 4version = "0.1.0"
5 5
6[dependencies] 6[dependencies]
7embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync", features = ["defmt"] } 7embassy-sync = { version = "0.1.0", path = "../../../../embassy-sync" }
8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] } 8embassy-executor = { version = "0.1.0", path = "../../../../embassy-executor", features = ["nightly", "integrated-timers"] }
9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] } 9embassy-time = { version = "0.1.0", path = "../../../../embassy-time", features = ["nightly", "tick-32768hz"] }
10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] }
diff --git a/examples/boot/application/stm32h7/flash-boot.sh b/examples/boot/application/stm32h7/flash-boot.sh
index debdb17a7..a3003681a 100755
--- a/examples/boot/application/stm32h7/flash-boot.sh
+++ b/examples/boot/application/stm32h7/flash-boot.sh
@@ -1,8 +1,9 @@
1#!/bin/bash 1#!/bin/bash
2probe-rs-cli erase --chip STM32H743ZITx
2mv ../../bootloader/stm32/memory.x ../../bootloader/stm32/memory-old.x 3mv ../../bootloader/stm32/memory.x ../../bootloader/stm32/memory-old.x
3cp memory-bl.x ../../bootloader/stm32/memory.x 4cp memory-bl.x ../../bootloader/stm32/memory.x
4 5
5cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32f767zi --chip STM32F767ZITx --target thumbv7em-none-eabihf 6cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32h743zi --chip STM32H743ZITx --target thumbv7em-none-eabihf
6 7
7rm ../../bootloader/stm32/memory.x 8rm ../../bootloader/stm32/memory.x
8mv ../../bootloader/stm32/memory-old.x ../../bootloader/stm32/memory.x 9mv ../../bootloader/stm32/memory-old.x ../../bootloader/stm32/memory.x
diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs
index 0ecf60348..f5a8fdb61 100644
--- a/examples/boot/application/stm32h7/src/bin/a.rs
+++ b/examples/boot/application/stm32h7/src/bin/a.rs
@@ -4,11 +4,11 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater};
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use panic_reset as _; 13use panic_reset as _;
14 14
@@ -29,13 +29,17 @@ async fn main(_spawner: Spawner) {
29 let mut updater = FirmwareUpdater::default(); 29 let mut updater = FirmwareUpdater::default();
30 button.wait_for_rising_edge().await; 30 button.wait_for_rising_edge().await;
31 let mut offset = 0; 31 let mut offset = 0;
32 let mut buf: [u8; 128 * 1024] = [0; 128 * 1024]; 32 let mut buf = AlignedBuffer([0; 128 * 1024]);
33 for chunk in APP_B.chunks(128 * 1024) { 33 for chunk in APP_B.chunks(128 * 1024) {
34 buf[..chunk.len()].copy_from_slice(chunk); 34 buf.as_mut()[..chunk.len()].copy_from_slice(chunk);
35 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); 35 updater
36 .write_firmware(offset, buf.as_ref(), &mut flash, 2048)
37 .await
38 .unwrap();
36 offset += chunk.len(); 39 offset += chunk.len();
37 } 40 }
38 updater.update(&mut flash).await.unwrap(); 41 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
42 updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap();
39 led.set_low(); 43 led.set_low();
40 cortex_m::peripheral::SCB::sys_reset(); 44 cortex_m::peripheral::SCB::sys_reset();
41} 45}
diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs
index f4f1d7119..f0b0b80e3 100644
--- a/examples/boot/application/stm32l0/src/bin/a.rs
+++ b/examples/boot/application/stm32l0/src/bin/a.rs
@@ -4,11 +4,11 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater};
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_time::{Duration, Timer}; 13use embassy_time::{Duration, Timer};
14use panic_reset as _; 14use panic_reset as _;
@@ -38,7 +38,8 @@ async fn main(_spawner: Spawner) {
38 offset += chunk.len(); 38 offset += chunk.len();
39 } 39 }
40 40
41 updater.update(&mut flash).await.unwrap(); 41 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
42 updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap();
42 led.set_low(); 43 led.set_low();
43 Timer::after(Duration::from_secs(1)).await; 44 Timer::after(Duration::from_secs(1)).await;
44 cortex_m::peripheral::SCB::sys_reset(); 45 cortex_m::peripheral::SCB::sys_reset();
diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs
index f4f1d7119..f0b0b80e3 100644
--- a/examples/boot/application/stm32l1/src/bin/a.rs
+++ b/examples/boot/application/stm32l1/src/bin/a.rs
@@ -4,11 +4,11 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater};
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use embassy_time::{Duration, Timer}; 13use embassy_time::{Duration, Timer};
14use panic_reset as _; 14use panic_reset as _;
@@ -38,7 +38,8 @@ async fn main(_spawner: Spawner) {
38 offset += chunk.len(); 38 offset += chunk.len();
39 } 39 }
40 40
41 updater.update(&mut flash).await.unwrap(); 41 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
42 updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap();
42 led.set_low(); 43 led.set_low();
43 Timer::after(Duration::from_secs(1)).await; 44 Timer::after(Duration::from_secs(1)).await;
44 cortex_m::peripheral::SCB::sys_reset(); 45 cortex_m::peripheral::SCB::sys_reset();
diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs
index 178b2e04a..5119bad2e 100644
--- a/examples/boot/application/stm32l4/src/bin/a.rs
+++ b/examples/boot/application/stm32l4/src/bin/a.rs
@@ -4,11 +4,11 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater};
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use panic_reset as _; 13use panic_reset as _;
14 14
@@ -35,7 +35,8 @@ async fn main(_spawner: Spawner) {
35 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); 35 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
36 offset += chunk.len(); 36 offset += chunk.len();
37 } 37 }
38 updater.update(&mut flash).await.unwrap(); 38 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
39 updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap();
39 led.set_low(); 40 led.set_low();
40 cortex_m::peripheral::SCB::sys_reset(); 41 cortex_m::peripheral::SCB::sys_reset();
41} 42}
diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs
index c71a42654..faa650778 100644
--- a/examples/boot/application/stm32wl/src/bin/a.rs
+++ b/examples/boot/application/stm32wl/src/bin/a.rs
@@ -4,11 +4,11 @@
4 4
5#[cfg(feature = "defmt-rtt")] 5#[cfg(feature = "defmt-rtt")]
6use defmt_rtt::*; 6use defmt_rtt::*;
7use embassy_boot_stm32::FirmwareUpdater; 7use embassy_boot_stm32::{AlignedBuffer, FirmwareUpdater};
8use embassy_embedded_hal::adapter::BlockingAsync; 8use embassy_embedded_hal::adapter::BlockingAsync;
9use embassy_executor::Spawner; 9use embassy_executor::Spawner;
10use embassy_stm32::exti::ExtiInput; 10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::flash::Flash; 11use embassy_stm32::flash::{Flash, WRITE_SIZE};
12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 12use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
13use panic_reset as _; 13use panic_reset as _;
14 14
@@ -37,7 +37,8 @@ async fn main(_spawner: Spawner) {
37 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); 37 updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap();
38 offset += chunk.len(); 38 offset += chunk.len();
39 } 39 }
40 updater.update(&mut flash).await.unwrap(); 40 let mut magic = AlignedBuffer([0; WRITE_SIZE]);
41 updater.mark_updated(&mut flash, magic.as_mut()).await.unwrap();
41 //defmt::info!("Marked as updated"); 42 //defmt::info!("Marked as updated");
42 led.set_low(); 43 led.set_low();
43 cortex_m::peripheral::SCB::sys_reset(); 44 cortex_m::peripheral::SCB::sys_reset();
diff --git a/examples/boot/bootloader/nrf/src/main.rs b/examples/boot/bootloader/nrf/src/main.rs
index bc7e0755f..9031997c2 100644
--- a/examples/boot/bootloader/nrf/src/main.rs
+++ b/examples/boot/bootloader/nrf/src/main.rs
@@ -20,10 +20,8 @@ fn main() -> ! {
20 */ 20 */
21 21
22 let mut bl = BootLoader::default(); 22 let mut bl = BootLoader::default();
23 let start = bl.prepare(&mut SingleFlashProvider::new(&mut WatchdogFlash::start( 23 let start = bl.prepare(&mut SingleFlashConfig::new(&mut BootFlash::<_, 4096>::new(
24 Nvmc::new(p.NVMC), 24 &mut WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, 5),
25 p.WDT,
26 5,
27 ))); 25 )));
28 unsafe { bl.load(start) } 26 unsafe { bl.load(start) }
29} 27}
diff --git a/examples/boot/bootloader/stm32/src/main.rs b/examples/boot/bootloader/stm32/src/main.rs
index 45c511ced..bb5d3e531 100644
--- a/examples/boot/bootloader/stm32/src/main.rs
+++ b/examples/boot/bootloader/stm32/src/main.rs
@@ -5,7 +5,7 @@ use cortex_m_rt::{entry, exception};
5#[cfg(feature = "defmt")] 5#[cfg(feature = "defmt")]
6use defmt_rtt as _; 6use defmt_rtt as _;
7use embassy_boot_stm32::*; 7use embassy_boot_stm32::*;
8use embassy_stm32::flash::{Flash, ERASE_SIZE}; 8use embassy_stm32::flash::{Flash, ERASE_SIZE, ERASE_VALUE, WRITE_SIZE};
9 9
10#[entry] 10#[entry]
11fn main() -> ! { 11fn main() -> ! {
@@ -19,9 +19,11 @@ fn main() -> ! {
19 } 19 }
20 */ 20 */
21 21
22 let mut bl: BootLoader<ERASE_SIZE> = BootLoader::default(); 22 let mut bl: BootLoader<ERASE_SIZE, WRITE_SIZE> = BootLoader::default();
23 let mut flash = Flash::unlock(p.FLASH); 23 let mut flash = Flash::unlock(p.FLASH);
24 let start = bl.prepare(&mut SingleFlashProvider::new(&mut flash)); 24 let start = bl.prepare(&mut SingleFlashConfig::new(
25 &mut BootFlash::<_, ERASE_SIZE, ERASE_VALUE>::new(&mut flash),
26 ));
25 core::mem::drop(flash); 27 core::mem::drop(flash);
26 unsafe { bl.load(start) } 28 unsafe { bl.load(start) }
27} 29}