You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58-25Lines changed: 58 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,44 +1,79 @@
1
-
# ec-slimloader**OUTDATED**
1
+
# ec-slimloader
2
2
3
-
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.
3
+
A light-weight bootloader written in Rust with a fail-safe NOR-flash backed state journal.
4
+
This framework can run on any platform if support for the platform is implemented.
5
+
It is only opinionated with regards to how the state is stored.
4
6
5
-
Currently this bootloader can only be used on the IMXRT600 series of chipsets from NXP.
7
+
Currently only supports the NXP IMXRT685S and IMXRT633S where it acts as a stage-two bootloader and copies the program to application RAM.
8
+
Also contains a tool for signing images, flashing them to the device, setting fuses (or shadow registers) containing crypto keys,
9
+
and an example application to showcase the bootloaders A/B state functionality for this family of chipsets.
6
10
7
11
## Organisation
8
12
9
-
This repository is split up into four parts:
10
-
* ec-slimloader: the binary project which forms the second stage bootloader
11
-
* 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.
12
-
* 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.
13
-
* example: an example application image that uses the state-journal to select alternative images to execute.
13
+
This repository is split up into three parts:
14
+
* libs: library crates that implement the core functionality.
15
+
* examples/rt685s: example binary applications that be run on the RT685S evaluation kit.
16
+
* bootloader-tool: a command-line utility only used to perform operations related to the NXP RT685S platform.
17
+
It uses 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.
18
+
This tool is not relevant if you want to use `ec-slimloader` with any other platform.
14
19
15
-
## Memory layout
16
-
This repository has default configuration files detailing the used memory layout. This layout will probably will need to be adapted for your specific usecase.
20
+
The libraries are split out as follows:
21
+
* ec-slimloader: general library crate providing a basic structure to build your bootloader binary application.
22
+
* ec-slimloader-state: library crate with all code relating to managing the state journal. Used by both the bootloader and the application to change which image slot should be booted.
23
+
* ec-slimloader-imxrt: library crate implementing support for the NXP IMXRT685S and IMXRT633S.
24
+
* imxrt-rom: library crate implementing Rust support for the NXP ROM API which provides access to fuses and allows calling into a verification routine for images.
25
+
26
+
## How it works
27
+
Assuming your platform is already supported, you can define:
28
+
* a region of NOR-flash memory containing at least 2 pages for the bootloader state.
29
+
* at least two regions of any memory that will fit an application image.
30
+
31
+
Using the library crate for your platform (like `ec-slimloader-imxrt`) you can then implement your own bootloader binary by calling the `start` function in the `ec-slimloader` library crate.
32
+
33
+
The `ec-slimloader` crate will handle for you:
34
+
* it will read from the state journal what image slot will be booted.
35
+
* on subsequent reboots, it will fall back to your defined backup slot if you do not mark your current application image as `confirmed`.
36
+
37
+
However, some aspects are handled by the platform support crate (and can differ from project-to-project):
38
+
* how application images are loaded. For `ec-slimloader-imxrt` images are copied to RAM in a quite chip-specific way. Typically for other platforms you might want to swap images between on-chip NOR flash and external NOR flash. The latter method is not implemented in this repository (yet).
39
+
* how application images are verified. By default the images themselves are not checked at all. `ec-slimloader-imxrt` leverages the native NXP authentication routines to check image integrity.
40
+
* how application images are bootloaded, or in other words are jumped to. This differs for cortex-m or RISCV processors.
41
+
42
+
Even when using `ec-slimloader-imxrt`, you will still have to implement a few details:
43
+
* from what memory is the `ec-slimloader` started, and what memory range is used for the bootloader data?
44
+
* which memory regions are mapped to be state journal and mapped to be a image slot 0, 1, etc.?
45
+
* what is a valid memory range for the application?
46
+
47
+
Finally, your application needs to also work with the state journal to:
48
+
* after writing a new application image to a slot, marking that image slot as to be booted in the state journal.
49
+
* after rebooting, mark the current image slot from which the application is running as `confirmed`.
50
+
If the application does not do this, the bootloader will load the old 'backup' image and mark the current boot as `failed`.
51
+
52
+
For a full tour on how to use this framework, please refer to the `examples/rt685s` folder.
17
53
18
54
## Quick guide
19
55
This guide details how to use this repository on the NXP MIMXRT685S-EVK. First step is compiling the bootloader and application:
20
56
21
57
```bash
22
-
pushdec-slimloader
58
+
pushdexamples/rt685s
23
59
cargo build --release --features defmt
24
60
popd
25
-
pushd examples/rt685s-application
26
-
cargo build --release
27
-
popd
28
61
```
29
62
30
63
In general, the bootloader-tool is a `clap` supported CLI application with for each subcommand a full `--help`:
31
64
```
65
+
popd bootloader-tool
32
66
cargo run -- --help
33
-
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.22s
34
69
Running `target/debug/bootloader-tool --help`
35
70
Usage: bootloader-tool [OPTIONS] [COMMAND]
36
71
37
72
Commands:
38
73
generate Generate keys and certificates
39
74
sign Sign binaries for flashing or OTA
40
75
download Download binaries to the device
41
-
run Run binaries, setting the shadow registers, by going through the bootloader chain for testing purposes
76
+
run Run binaries by going through the bootloader chain for testing purposes
42
77
fuse Burn fuse registers with key material and settings
43
78
help Print this message or the help of the given subcommand(s)
44
79
@@ -50,41 +85,39 @@ Options:
50
85
51
86
For now we need to prepare our testing setup by generating the key material:
52
87
```bash
53
-
cd bootloader-tool
54
88
cargo run -- generate certificates
55
89
cargo run -- generate otp
56
90
```
57
91
58
92
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.
59
-
We are working on a setup to also support external HSM integration.
60
93
61
94
Now we have everything ready to start flashing.
62
95
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:
63
96
64
97
```bash
65
-
cargo run -- sign bootloader -i ../target/thumbv8m.main-none-eabihf/release/ec-slimloader
98
+
cargo run -- sign bootloader -i ../examples/rt685s/target/thumbv8m.main-none-eabihf/release/example-bootloader
66
99
```
67
100
68
101
We can now flash the FCB:
69
102
70
103
```bash
71
-
cargo run -- download prelude --prelude-path ../target/thumbv8m.main-none-eabihf/release/ec-slimloader.prelude.elf
104
+
cargo run -- download prelude --prelude-path ../examples/rt685s/target/thumbv8m.main-none-eabihf/release/example-bootloader/ec-slimloader.prelude.elf
72
105
```
73
106
74
107
And we can flash the application into *both slots*:
75
108
```bash
76
-
cargo run -- download application -i ../examples/rt685s-application/target/thumbv8m.main-none-eabihf/release/example-application --slot 0
77
-
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:
81
114
```bash
82
-
cargo run -- download bootloader -i ../target/thumbv8m.main-none-eabihf/release/ec-slimloader
115
+
cargo run -- download bootloader -i ../examples/rt685s/target/thumbv8m.main-none-eabihf/release/example-bootloader
83
116
```
84
117
85
-
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:
118
+
To flash & attach to the application, assuming you have a bootloader and FCB already flashed:
86
119
```bash
87
-
cargo run -- run application -i ../examples/rt685s-application/target/thumbv8m.main-none-eabihf/release/example-application
120
+
cargo run -- run application -i ../examples/rt685s/target/thumbv8m.main-none-eabihf/release/example-application
88
121
```
89
122
90
123
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`.
Copy file name to clipboardExpand all lines: bootloader-tool/README.md
+13-12Lines changed: 13 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This binary provides support for signing, downloading and running bootloaders via the secure pathway on the NXP RT6xx family of chips. It automates the signing process, as well as setting up the chip temporarily for running signed binaries. Note: It does not blow any fuses, unless using the `fuse` command, and any boot configuration changes made are erased on a power cycle.
4
4
5
-
**Note**: the RT6xx chipset enters a FAULT condition when image verification fails. You might need to periodically powercycle your board until the complete chain runs successfully. (TODO why?)
5
+
**Note**: the RT6xx chipset enters a FAULT condition when image verification fails in the ROM bootloader. You might need to periodically powercycle your board until the complete chain runs successfully.
6
6
7
7
## Installation
8
8
@@ -35,13 +35,13 @@ cargo run -- generate otp
35
35
36
36
Then, assuming you have a bootloader and application ready (see the example folder to quickly build something that runs on the RT685S EVK), you can use the following to flash an application to slot 0:
37
37
38
-
```
39
-
cargo run -- run application --input-path ./example/application/target/thumbv8m.main-none-eabihf/release/example-application
38
+
```bash
39
+
cargo run -- run application --input-path ../examples/rt685s/target/thumbv8m.main-none-eabihf/release/example-application
40
40
```
41
41
42
42
And then flash the bootloader to test that it works:
43
-
```
44
-
cargo run -- run bootloader --input-path ./example/bootloader/target/thumbv8m.main-none-eabihf/release/example-bootloader
43
+
```bash
44
+
cargo run -- run bootloader --input-path ../examples/rt685s/target/thumbv8m.main-none-eabihf/release/example-bootloader
45
45
```
46
46
47
47
**Note**: initially flashing the application causes the target to lock up, and you might need to powercycle before
0 commit comments