From 776be79f7bb10b09e795e2ea93bb795a653c9b4c Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 24 Jun 2022 19:56:15 +0200 Subject: Move bootloader main to examples This should remove some confusion around embassy-boot-* being a library vs. a binary. The binary is now an example bootloader instead. --- examples/boot/nrf/.cargo/config.toml | 9 -------- examples/boot/nrf/Cargo.toml | 18 --------------- examples/boot/nrf/README.md | 34 ---------------------------- examples/boot/nrf/build.rs | 34 ---------------------------- examples/boot/nrf/memory-bl.x | 18 --------------- examples/boot/nrf/memory.x | 15 ------------- examples/boot/nrf/src/bin/a.rs | 43 ------------------------------------ examples/boot/nrf/src/bin/b.rs | 23 ------------------- 8 files changed, 194 deletions(-) delete mode 100644 examples/boot/nrf/.cargo/config.toml delete mode 100644 examples/boot/nrf/Cargo.toml delete mode 100644 examples/boot/nrf/README.md delete mode 100644 examples/boot/nrf/build.rs delete mode 100644 examples/boot/nrf/memory-bl.x delete mode 100644 examples/boot/nrf/memory.x delete mode 100644 examples/boot/nrf/src/bin/a.rs delete mode 100644 examples/boot/nrf/src/bin/b.rs (limited to 'examples/boot/nrf') diff --git a/examples/boot/nrf/.cargo/config.toml b/examples/boot/nrf/.cargo/config.toml deleted file mode 100644 index 8ca28df39..000000000 --- a/examples/boot/nrf/.cargo/config.toml +++ /dev/null @@ -1,9 +0,0 @@ -[target.'cfg(all(target_arch = "arm", target_os = "none"))'] -# replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips` -runner = "probe-run --chip nRF52840_xxAA" - -[build] -target = "thumbv7em-none-eabi" - -[env] -DEFMT_LOG = "trace" diff --git a/examples/boot/nrf/Cargo.toml b/examples/boot/nrf/Cargo.toml deleted file mode 100644 index 0a0b76e67..000000000 --- a/examples/boot/nrf/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -edition = "2021" -name = "embassy-boot-nrf-examples" -version = "0.1.0" - -[dependencies] -embassy = { version = "0.1.0", path = "../../../embassy", features = ["nightly"] } -embassy-nrf = { version = "0.1.0", path = "../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly", "nrf52840"] } -embassy-boot-nrf = { version = "0.1.0", path = "../../../embassy-boot/nrf" } -embassy-embedded-hal = { version = "0.1.0", path = "../../../embassy-embedded-hal" } - -defmt = { version = "0.3", optional = true } -defmt-rtt = { version = "0.3", optional = true } -panic-reset = { version = "0.1.1" } -embedded-hal = { version = "0.2.6" } - -cortex-m = "0.7.3" -cortex-m-rt = "0.7.0" diff --git a/examples/boot/nrf/README.md b/examples/boot/nrf/README.md deleted file mode 100644 index 1f25ffc05..000000000 --- a/examples/boot/nrf/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# Examples using bootloader - -Example for nRF52 demonstrating the bootloader. The example consists of application binaries, 'a' -which allows you to press a button to start the DFU process, and 'b' which is the updated -application. - - -## Prerequisites - -* `cargo-binutils` -* `cargo-flash` -* `embassy-boot-nrf` - -## Usage - - - -``` -# Use bare metal linker script -cp memory-bl.x ../../../embassy-boot/nrf/memory.x - -# Flash bootloader -cargo flash --manifest-path ../../../embassy-boot/nrf/Cargo.toml --features embassy-nrf/nrf52840 --release --chip nRF52840_xxAA -# Build 'b' -cargo build --release --bin b -# Generate binary for 'b' -cargo objcopy --release --bin b -- -O binary b.bin -``` - -# Flash `a` (which includes b.bin) - -``` -cargo flash --release --bin a --chip nRF52840_xxAA -``` diff --git a/examples/boot/nrf/build.rs b/examples/boot/nrf/build.rs deleted file mode 100644 index cd1a264c4..000000000 --- a/examples/boot/nrf/build.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! This build script copies the `memory.x` file from the crate root into -//! a directory where the linker can always find it at build time. -//! For many projects this is optional, as the linker always searches the -//! project root directory -- wherever `Cargo.toml` is. However, if you -//! are using a workspace or have a more complicated build setup, this -//! build script becomes required. Additionally, by requesting that -//! Cargo re-run the build script whenever `memory.x` is changed, -//! updating `memory.x` ensures a rebuild of the application with the -//! new memory settings. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - // Put `memory.x` in our output directory and ensure it's - // on the linker search path. - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - File::create(out.join("memory.x")) - .unwrap() - .write_all(include_bytes!("memory.x")) - .unwrap(); - println!("cargo:rustc-link-search={}", out.display()); - - // By default, Cargo will re-run a build script whenever - // any file in the project changes. By specifying `memory.x` - // here, we ensure the build script is only re-run when - // `memory.x` is changed. - println!("cargo:rerun-if-changed=memory.x"); - - println!("cargo:rustc-link-arg-bins=--nmagic"); - println!("cargo:rustc-link-arg-bins=-Tlink.x"); -} diff --git a/examples/boot/nrf/memory-bl.x b/examples/boot/nrf/memory-bl.x deleted file mode 100644 index 8a32b905f..000000000 --- a/examples/boot/nrf/memory-bl.x +++ /dev/null @@ -1,18 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - FLASH : ORIGIN = 0x00000000, LENGTH = 24K - BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K - ACTIVE : ORIGIN = 0x00007000, LENGTH = 64K - DFU : ORIGIN = 0x00017000, LENGTH = 68K - RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); - -__bootloader_active_start = ORIGIN(ACTIVE); -__bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE); - -__bootloader_dfu_start = ORIGIN(DFU); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); diff --git a/examples/boot/nrf/memory.x b/examples/boot/nrf/memory.x deleted file mode 100644 index 3a54ca460..000000000 --- a/examples/boot/nrf/memory.x +++ /dev/null @@ -1,15 +0,0 @@ -MEMORY -{ - /* NOTE 1 K = 1 KiBi = 1024 bytes */ - BOOTLOADER : ORIGIN = 0x00000000, LENGTH = 24K - BOOTLOADER_STATE : ORIGIN = 0x00006000, LENGTH = 4K - FLASH : ORIGIN = 0x00007000, LENGTH = 64K - DFU : ORIGIN = 0x00017000, LENGTH = 68K - RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 32K -} - -__bootloader_state_start = ORIGIN(BOOTLOADER_STATE); -__bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE); - -__bootloader_dfu_start = ORIGIN(DFU); -__bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU); diff --git a/examples/boot/nrf/src/bin/a.rs b/examples/boot/nrf/src/bin/a.rs deleted file mode 100644 index 0b9715e49..000000000 --- a/examples/boot/nrf/src/bin/a.rs +++ /dev/null @@ -1,43 +0,0 @@ -#![no_std] -#![no_main] -#![macro_use] -#![feature(generic_associated_types)] -#![feature(type_alias_impl_trait)] - -use embassy_boot_nrf::FirmwareUpdater; -use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; -use embassy_nrf::nvmc::Nvmc; -use embassy_nrf::Peripherals; -use panic_reset as _; - -static APP_B: &[u8] = include_bytes!("../../b.bin"); - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let mut button = Input::new(p.P0_11, Pull::Up); - let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); - //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); - //let mut button = Input::new(p.P1_02, Pull::Up); - - let nvmc = Nvmc::new(p.NVMC); - let mut nvmc = BlockingAsync::new(nvmc); - - let mut updater = FirmwareUpdater::default(); - loop { - led.set_low(); - button.wait_for_any_edge().await; - if button.is_low() { - let mut offset = 0; - for chunk in APP_B.chunks(4096) { - let mut buf: [u8; 4096] = [0; 4096]; - buf[..chunk.len()].copy_from_slice(chunk); - updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); - offset += chunk.len(); - } - updater.update(&mut nvmc).await.unwrap(); - led.set_high(); - cortex_m::peripheral::SCB::sys_reset(); - } - } -} diff --git a/examples/boot/nrf/src/bin/b.rs b/examples/boot/nrf/src/bin/b.rs deleted file mode 100644 index a06c20f8b..000000000 --- a/examples/boot/nrf/src/bin/b.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![no_std] -#![no_main] -#![macro_use] -#![feature(generic_associated_types)] -#![feature(type_alias_impl_trait)] - -use embassy::time::{Duration, Timer}; -use embassy_nrf::gpio::{Level, Output, OutputDrive}; -use embassy_nrf::Peripherals; -use panic_reset as _; - -#[embassy::main] -async fn main(_s: embassy::executor::Spawner, p: Peripherals) { - let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); - //let mut led = Output::new(p.P1_10, Level::Low, OutputDrive::Standard); - - loop { - led.set_high(); - Timer::after(Duration::from_millis(300)).await; - led.set_low(); - Timer::after(Duration::from_millis(300)).await; - } -} -- cgit