aboutsummaryrefslogtreecommitdiff
path: root/examples/boot/src/bin
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-02-09 15:07:25 +0000
committerGitHub <[email protected]>2022-02-09 15:07:25 +0000
commit3d6b8bd9832d5a29cab4aa21434663e6ea6f4488 (patch)
tree5e457a46c63f9565e82b9dd401701cbd7aba20b7 /examples/boot/src/bin
parentd91bd0b9a69b8411f2a1d58bfad5d4dce51e7110 (diff)
parente990021b9a9d3acc309c21bd4ddf3ff090bb7999 (diff)
Merge #604
604: Add embassy-boot r=lulf a=lulf Continuation of https://github.com/embassy-rs/embassy/pull/588 Embassy-boot is a simple bootloader that works together with an application to provide firmware update capabilities with a minimal risk. The bootloader consists of a platform-independent part, which implements the swap algorithm, and a platform-dependent part (currently only for nRF) that provides addition functionality such as watchdog timers softdevice support. The bootloader is intended to be configurable for different flash sizes and architectures, and only requires that embedded-storage flash traits are implemented. The nRF version can be configured programatically as a library, or using linker scripts to set the partition locations for DFU, ACTIVE and STATE * DFU: Where the next firmware version should be written. This is used by the FirmwareUpdater * ACTIVE: Where the current firmware version resides. Written by bootloader when swap magic is set * STATE: Contains the bootloader magic and the copy progress. Can be 1-N pages long (depending on how much flash you have which will determine the copy progress index size Co-authored-by: Ulf Lilleengen <[email protected]> Co-authored-by: Ulf Lilleengen <[email protected]>
Diffstat (limited to 'examples/boot/src/bin')
-rw-r--r--examples/boot/src/bin/a.rs49
-rw-r--r--examples/boot/src/bin/b.rs26
2 files changed, 75 insertions, 0 deletions
diff --git a/examples/boot/src/bin/a.rs b/examples/boot/src/bin/a.rs
new file mode 100644
index 000000000..88880e688
--- /dev/null
+++ b/examples/boot/src/bin/a.rs
@@ -0,0 +1,49 @@
1#![no_std]
2#![no_main]
3#![macro_use]
4#![feature(generic_associated_types)]
5#![feature(type_alias_impl_trait)]
6
7use embassy_boot_nrf::updater;
8use embassy_nrf::{
9 gpio::{Input, Pull},
10 gpio::{Level, Output, OutputDrive},
11 nvmc::Nvmc,
12 Peripherals,
13};
14use embassy_traits::adapter::BlockingAsync;
15use embedded_hal::digital::v2::InputPin;
16use panic_reset as _;
17
18static APP_B: &[u8] = include_bytes!("../../b.bin");
19
20#[embassy::main]
21async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
22 let mut button = Input::new(p.P0_11, Pull::Up);
23 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
24 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard);
25 //let mut button = Input::new(p.P1_02, Pull::Up);
26
27 let nvmc = Nvmc::new(p.NVMC);
28 let mut nvmc = BlockingAsync::new(nvmc);
29
30 loop {
31 button.wait_for_any_edge().await;
32 if button.is_low().unwrap() {
33 let mut updater = updater::new();
34 let mut offset = 0;
35 for chunk in APP_B.chunks(4096) {
36 let mut buf: [u8; 4096] = [0; 4096];
37 buf[..chunk.len()].copy_from_slice(chunk);
38 updater
39 .write_firmware(offset, &buf, &mut nvmc)
40 .await
41 .unwrap();
42 offset += chunk.len();
43 }
44 updater.mark_update(&mut nvmc).await.unwrap();
45 led.set_high();
46 cortex_m::peripheral::SCB::sys_reset();
47 }
48 }
49}
diff --git a/examples/boot/src/bin/b.rs b/examples/boot/src/bin/b.rs
new file mode 100644
index 000000000..18bb6330c
--- /dev/null
+++ b/examples/boot/src/bin/b.rs
@@ -0,0 +1,26 @@
1#![no_std]
2#![no_main]
3#![macro_use]
4#![feature(generic_associated_types)]
5#![feature(type_alias_impl_trait)]
6
7use embassy::time::{Duration, Timer};
8use embassy_nrf::{
9 gpio::{Level, Output, OutputDrive},
10 Peripherals,
11};
12
13use panic_reset as _;
14
15#[embassy::main]
16async fn main(_s: embassy::executor::Spawner, p: Peripherals) {
17 let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
18 //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard);
19
20 loop {
21 led.set_high();
22 Timer::after(Duration::from_millis(300)).await;
23 led.set_low();
24 Timer::after(Duration::from_millis(300)).await;
25 }
26}