Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
b041d3f
Remove MBI creation in linker and use cortex-m-rt linker script, clea…
Wassasin Aug 13, 2025
7de19b9
Separated out boot_application
Wassasin Aug 13, 2025
31c8313
Added ROM API functions; fixed defmt linking
Wassasin Aug 13, 2025
0f4c29a
Added embassy-imxrt as dependency
Wassasin Aug 19, 2025
f086b74
WIP work on board impl
Wassasin Aug 21, 2025
2a49894
WIP first RC
Wassasin Aug 22, 2025
fa2d130
Write Descriptors as part of the ec-slimloader
Wassasin Aug 22, 2025
01a89ca
Fixed defmt dependency
Wassasin Aug 22, 2025
f3f2e62
Added check for IVT image type marker
Wassasin Aug 22, 2025
82c2812
Changed FLASH size to 24K
Wassasin Aug 22, 2025
2971dee
Moved ec-slimloader to subfolder
Wassasin Aug 22, 2025
c045170
Copied ec-slimloader-descriptors to this repository
Wassasin Aug 22, 2025
82debbf
Moved over to workspace
Wassasin Aug 22, 2025
76f4ef7
Bumped down to 2021 edition
Wassasin Aug 22, 2025
b1e818c
Copied bootloader-tool into this repository
Wassasin Aug 22, 2025
09749b2
WIP
Wassasin Aug 22, 2025
061748b
WIP
Wassasin Aug 22, 2025
049ec95
Load-to-ram via bootloader-tool works
Wassasin Aug 22, 2025
cb3fb47
WIP example application
Wassasin Aug 24, 2025
00d0ea0
Fixed example slot setting
Wassasin Aug 24, 2025
65bc78e
Add support for download slot (but not run slot (yet))
Wassasin Aug 24, 2025
3ea3736
Use (temporarily) embassy-imxrt branch with fixes, set clock speed to…
Wassasin Aug 26, 2025
f2e9fa4
Quick update on README
Wassasin Aug 26, 2025
945bdd8
Renamed ec-slimloader-descriptors to ec-slimloader-state
Wassasin Aug 27, 2025
5705c86
Moved example application to rt685s subfolder
Wassasin Aug 27, 2025
413eac2
Added bootloader application in example folder
Wassasin Aug 27, 2025
3f5456c
Moved some config parameters from bootloader to trait
Wassasin Aug 28, 2025
7474c53
Decoupled defmt from bootloader example
Wassasin Aug 28, 2025
a66b636
Moved .vscode to root; applied only to example
Wassasin Sep 1, 2025
c15084b
Removed runner for ec-slimloader library crate
Wassasin Sep 1, 2025
b051364
Removed example from bootloader-tool; as we are now using the ec-slim…
Wassasin Sep 1, 2025
87afc53
Cleaned up example application
Wassasin Sep 1, 2025
13064b6
Removed superfluous error handlers from application
Wassasin Sep 1, 2025
e5c40e6
Added comments to ec-slimloader; removed old stubs
Wassasin Sep 1, 2025
70535d6
Ran cargo +nightly fmt
Wassasin Sep 1, 2025
80741ee
Split ec-slimloader into ec-slimloader-imxrt and moved over to defmt-…
Wassasin Sep 1, 2025
c320942
Moved library crates into subfolder workspace
Wassasin Sep 1, 2025
c61d915
Straightened features and dependencies, start on CI
Wassasin Sep 1, 2025
8819544
Updated dependencies and made defmt feature separate
Wassasin Sep 4, 2025
d9f6692
Moved certificates to rsa3096
Wassasin Sep 4, 2025
e680bba
Enabled trustzone mode for application
Wassasin Sep 4, 2025
58a2020
Changed memory map and clocking
Wassasin Sep 4, 2025
c0765a8
Removed old descriptors, moved journal module to top level
Wassasin Sep 4, 2025
07a6769
Fixed RSA3072 certificate generation
Wassasin Sep 5, 2025
14ad8eb
Merged upstream/feature/hsm-pure-sign
Wassasin Sep 8, 2025
f8eac9d
Added reading OTP fuses and allow unsigned images to be booted in dev…
Wassasin Sep 8, 2025
f9c933a
Moved back to mainline embassy-imxrt
Wassasin Sep 9, 2025
26283d4
WIP multiple certificates
Wassasin Sep 9, 2025
800a7af
Cleaned up manual let else
Wassasin Sep 15, 2025
63c483e
Fix unit tests
Wassasin Sep 15, 2025
3f94a9f
Moved to XIP with load-to-ram mode
Wassasin Sep 15, 2025
ce58f3c
Split out imxrt-rom
Wassasin Sep 15, 2025
face6a6
WIP OTP fuses
Wassasin Sep 15, 2025
8741408
Cleaned up register/otp/shadow
Wassasin Sep 22, 2025
6fdac46
Moved OTP registers to device-driver; fixed writing of fuses
Wassasin Sep 23, 2025
59550d8
Fix dependencies and errors
Wassasin Sep 29, 2025
44b038a
Fixed OTP memory mapping, increased bootloader RAM
Wassasin Sep 29, 2025
522bece
Rename boot* registers to boot*cfg
Wassasin Sep 29, 2025
7acb07f
Added sec_boot_cfg[5] to registers
Wassasin Sep 29, 2025
aca6b83
Moved verification completely to separate module, gated by non-secure…
Wassasin Sep 30, 2025
8079c20
Fixed ./libs CI
Wassasin Sep 30, 2025
abd09c4
Work on CI pipeline
Wassasin Sep 30, 2025
ddecbaa
Moved register definitions to json because of problematic yaml depend…
Wassasin Sep 30, 2025
1c1a530
Fixed example cargo deny
Wassasin Sep 30, 2025
53c3a91
Fixed clippy warnings for bootloader-tool
Wassasin Sep 30, 2025
1bfa48c
WIP CI
Wassasin Sep 30, 2025
36c7d16
Removed superfluous files; fixed cargo +nightly fmt
Wassasin Sep 30, 2025
97f11fd
Moved device-driver manifest to temporary generated rust code to miti…
Wassasin Sep 30, 2025
e5163ce
Remove setting boot0 shadow in devmode
Wassasin Sep 30, 2025
4b3bd9e
Moved boot0 fuse values from bootloader shadow to directly in applica…
Wassasin Sep 30, 2025
0b1026a
flash.rs: update comment to match behavior
jerrysxie Oct 2, 2025
3e091e6
mbi.rs: swap major and minor
jerrysxie Oct 2, 2025
135e72c
Updated padding tests to test different paddings
jerrysxie Oct 2, 2025
783055d
Update README to reflect the state of the parts
jerrysxie Oct 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .cargo/config.toml

This file was deleted.

83 changes: 54 additions & 29 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ concurrency:
cancel-in-progress: true
name: check
jobs:

fmt:
runs-on: ubuntu-latest
name: nightly / fmt
Expand All @@ -39,8 +38,12 @@ jobs:
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- name: cargo fmt --check
- name: cargo fmt --check (libs)
run: cargo fmt --check
working-directory: "./libs"
- name: cargo fmt --check (examples)
run: cargo fmt --check
working-directory: "./examples/rt685s"

clippy:
runs-on: ubuntu-latest
Expand All @@ -65,12 +68,20 @@ jobs:
components: clippy
- name: rustup target add ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}
- name: cargo clippy
- name: cargo clippy (libs)
uses: giraffate/clippy-action@v1
with:
reporter: "github-pr-check"
clippy_flags: -- -F clippy::suspicious -D clippy::correctness -F clippy::perf -F clippy::style
github_token: ${{ secrets.GITHUB_TOKEN }}
workdir: "./libs"
- name: cargo clippy (examples)
uses: giraffate/clippy-action@v1
with:
reporter: 'github-pr-check'
clippy_flags: -- -F clippy::suspicious -F clippy::correctness -F clippy::perf -F clippy::style
reporter: "github-pr-check"
clippy_flags: -- -F clippy::suspicious -D clippy::correctness -F clippy::perf -F clippy::style
github_token: ${{ secrets.GITHUB_TOKEN }}
workdir: "./examples/rt685s"

# Enable once we have a released crate
# semver:
Expand Down Expand Up @@ -107,8 +118,14 @@ jobs:
uses: dtolnay/rust-toolchain@nightly
- name: rustup target add ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}
- name: cargo doc
- name: cargo doc (libs)
run: cargo doc --no-deps --features mimxrt685s
working-directory: "./libs"
env:
RUSTDOCFLAGS: --cfg docsrs
- name: cargo doc (examples)
run: cargo doc --no-deps
working-directory: "./examples/rt685s"
env:
RUSTDOCFLAGS: --cfg docsrs

Expand All @@ -125,15 +142,23 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true

- name: Install stable
uses: dtolnay/rust-toolchain@stable
- name: rustup target add ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}
- name: cargo install cargo-hack
uses: taiki-e/install-action@cargo-hack
# intentionally no target specifier; see https://github.com/jonhoo/rust-ci-conf/pull/4
- name: cargo hack
run: cargo hack --each-feature --exclude-all-features check

- name: rustup target add thumbv8m.main-none-eabihf
run: rustup target add thumbv8m.main-none-eabihf

- name: cargo install cargo-batch
run: cargo install --git https://github.com/embassy-rs/cargo-batch cargo --bin cargo-batch --locked

- name: cargo manual hack (libs)
run: ./ci.sh
working-directory: "./libs"

- name: cargo manual hack (examples/rt685s)
run: ./ci.sh
working-directory: "./examples/rt685s"

deny:
# cargo-deny checks licenses, advisories, sources, and bans for
Expand All @@ -152,11 +177,17 @@ jobs:
uses: dtolnay/rust-toolchain@stable
- name: rustup target add ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}
- name: cargo install cargo-deny
- name: Cargo deny (libs)
uses: EmbarkStudios/cargo-deny-action@v2
with:
log-level: warn
manifest-path: ./libs/Cargo.toml
command: check
- name: Cargo deny (examples)
uses: EmbarkStudios/cargo-deny-action@v2
with:
log-level: warn
manifest-path: ./Cargo.toml
manifest-path: ./examples/rt685s/Cargo.toml
command: check

msrv:
Expand All @@ -167,28 +198,22 @@ jobs:
strategy:
fail-fast: false
matrix:
msrv: ["1.79"] # We're relying on namespaced-features, which
# was released in 1.60
#
# We also depend on `fixed' which requires rust
# 1.71
#
# Additionally, we depend on embedded-hal-async
# which requires 1.75
#
# embassy-time requires 1.79 due to
# collapse_debuginfo
msrv: ["1.90"] # We are depending on embassy-imxrt.
target: [thumbv8m.main-none-eabihf]
name: ubuntu / ${{ matrix.msrv }}
name: ubuntu / MSRV ${{ matrix.msrv }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install ${{ matrix.msrv }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.msrv }}
toolchain: ${{ matrix.msrv }}
- name: rustup target add ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}
- name: cargo +${{ matrix.msrv }} check
- name: cargo +${{ matrix.msrv }} check (libs)
run: cargo check --features mimxrt685s
working-directory: "./libs"
- name: cargo +${{ matrix.msrv }} check (examples)
run: cargo check
working-directory: "./examples/rt685s"
30 changes: 0 additions & 30 deletions .github/workflows/nostd.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"coreConfigs": [
{
"programBinary": "target/thumbv8m.main-none-eabihf/debug/ec-slimloader",
"programBinary": "examples/rt685s/target/thumbv8m.main-none-eabihf/release/example-bootloader",
"svdFile": ".vscode/MIMXRT685S_cm33.svd",
"rttEnabled": true,
}
Expand Down
47 changes: 0 additions & 47 deletions Cargo.toml

This file was deleted.

93 changes: 91 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,92 @@
# ec-slimloader
# ec-slimloader **OUTDATED**

A light-weight stage-one bootloader for loading an app image as configured by ec-slimloader-descriptors
A light-weight stage-two bootloader written in Rust for loading an app image as configured by ec-slimloader-descriptors. Also contains a tool for signing images, flashing them to the device, setting fuses (or shadow registers) containing crypto keys, and an example application to showcase the bootloaders A/B state functionality.

Currently this bootloader can only be used on the IMXRT600 series of chipsets from NXP.

## Organisation

This repository is split up into four parts:
* ec-slimloader: the binary project which forms the second stage bootloader
* ec-slimloader-descriptors: the library crate containing a descriptor of where each image slot exists, as well as a persistent fail-safe state journal for recording the A/B bootloading state.
* bootloader-tool: a command-line utility using the NXP SPSDK tooling to generate keys, sign images, and flash them to the target device. Also integrates probe-rs and allows for attaching to the RTT buffer for displaying `defmt` output.
* example: an example application image that uses the state-journal to select alternative images to execute.

## Memory layout
This repository has default configuration files detailing the used memory layout. This layout will probably will need to be adapted for your specific usecase.

## Quick guide
This guide details how to use this repository on the NXP MIMXRT685S-EVK. First step is compiling the bootloader and application:

```bash
pushd ec-slimloader
cargo build --release --features defmt
popd
pushd examples/rt685s-application
cargo build --release
popd
```

In general, the bootloader-tool is a `clap` supported CLI application with for each subcommand a full `--help`:
```
cargo run -- --help
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
Running `target/debug/bootloader-tool --help`
Usage: bootloader-tool [OPTIONS] [COMMAND]

Commands:
generate Generate keys and certificates
sign Sign binaries for flashing or OTA
download Download binaries to the device
run Run binaries, setting the shadow registers, by going through the bootloader chain for testing purposes
fuse Burn fuse registers with key material and settings
help Print this message or the help of the given subcommand(s)

Options:
-c, --config <FILE> Configuration file path [default: ./config.toml]
-h, --help Print help
-V, --version Print version
```

For now we need to prepare our testing setup by generating the key material:
```bash
cd bootloader-tool
cargo run -- generate certificates
cargo run -- generate otp
```

This key material is only used for testing right now, and everything is put in the `./artifacts` directory. This can be configured in the `./config.toml` file.
We are working on a setup to also support external HSM integration.

Now we have everything ready to start flashing.
We can use run `run` command to immediately flash and `attach` in the same way you are familiar with from `probe-rs`. However, we need the bootloader to start up the application, and we need the FCB (we call everything in 0x0 to 0x1000 the 'prelude') to start the bootloader. We can extract the FCB from the `ec-slimloader` as it is built with the appropriate feature flags to include a FCB in the ELF file. Extraction happens as a side-product of signing:

```bash
cargo run -- sign bootloader -i ../target/thumbv8m.main-none-eabihf/release/ec-slimloader
```

We can now flash the FCB:

```bash
cargo run -- download prelude --prelude-path ../target/thumbv8m.main-none-eabihf/release/ec-slimloader.prelude.elf
```

And we can flash the application into *both slots*:
```bash
cargo run -- download application -i ../examples/rt685s-application/target/thumbv8m.main-none-eabihf/release/example-application --slot 0
cargo run -- download application -i ../examples/rt685s-application/target/thumbv8m.main-none-eabihf/release/example-application --slot 1
```

To flash & attach to the bootloader now run, whilst setting the OTP shadow registers:
```bash
cargo run -- download bootloader -i ../target/thumbv8m.main-none-eabihf/release/ec-slimloader
```

To flash & attach to the application (TODO it now is not resetting the state journal so take care), assuming you have a and FCB bootloader already flashed:
```bash
cargo run -- run application -i ../examples/rt685s-application/target/thumbv8m.main-none-eabihf/release/example-application
```

You can use the `USER_1` button to change the state journal to either `confirmed` or try the other slot in state `initial` if the current image is already `confirmed`.

You can use the `USER_2` button the reboot into the bootloader, which will set an image to `failed` if it does not verify or if it was in `attempting` without putting the state in `confirmed`.
2 changes: 2 additions & 0 deletions bootloader-tool/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[env]
RUST_LOG = "none,bootloader_tool=debug"
8 changes: 8 additions & 0 deletions bootloader-tool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/target

# Software package
/elftosb*

/binaries.tar.xz
/gpio-blinky
/*.bin
Loading