WIP: MCUBoot Readme
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
# UTAT Firmware Development Environment
|
||||
# UTAT Firmware Development MCUBoot POC
|
||||
|
||||
My firmware development environment for the University of Toronto Aerospace Team
|
||||
Documentation of the steps taken to implement MCUBoot.
|
||||
|
||||
https://docs.zephyrproject.org/latest/develop/getting_started/index.html
|
||||
## Environnment config
|
||||
Use the environment written in flake.nix by running `nix develop`
|
||||
|
||||
|
||||
## Set up Zephyr
|
||||
Zephyr is the RTOS that runs on the Nucleo G431RB development board I'm using.
|
||||
|
||||
[Getting started with Zephyr](https://docs.zephyrproject.org/latest/develop/getting_started/index.html)
|
||||
|
||||
```sh
|
||||
west init zephyrproject
|
||||
@@ -13,25 +20,85 @@ west zephyr-export
|
||||
|
||||
cd zepyhr
|
||||
west sdk install
|
||||
```
|
||||
|
||||
## MCUBoot POC Implementation
|
||||
|
||||
MCUBoot is a bootloader for Zephyr, which allows multiple firmwares to exist on a board. MCUBoot can dynamically switch which firmware is active. This is useful in the event of one firmware failing.
|
||||
|
||||
[Abstract MCUBoot Guide](https://docs.mcuboot.com/readme-zephyr.html)
|
||||
|
||||
```sh
|
||||
west build -p always -b nucleo_g431rb samples/basic/blinky
|
||||
west flash --runner pyocd # had to su root first to run this (after running nix develop)
|
||||
```
|
||||
|
||||
# MCUBoot
|
||||
cd ~/utat-dev/zephyrproject
|
||||
# Configure the DTS for partition sizes: https://docs.zephyrproject.org/latest/build/dts/intro-scope-purpose.html
|
||||
# https://docs.zephyrproject.org/latest/build/dts/api/bindings/mtd/fixed-partitions.html
|
||||
nvim "zephyr/boards/st/nucleo_g431rb/nucleo_g431rb.dts"
|
||||
|
||||
## Configure partition sizes
|
||||
|
||||
The devicetree specification file declares the hardware configuration. The flash storage needs three partitions, one for boot, and two for the two firmwares it will hold.
|
||||
|
||||
[DeviceTree Specification documentation](https://docs.zephyrproject.org/latest/build/dts/intro-scope-purpose.html)
|
||||
|
||||
[Partitioning examples](https://docs.zephyrproject.org/latest/build/dts/api/bindings/mtd/fixed-partitions.html)
|
||||
|
||||
The board I'm using has its DeviceTree Specification in `zephyr/boards/st/nucleo_g431rb/nucleo_g431rb.dts`
|
||||
|
||||
I created a partition for MCUBoot, two firmware slots, and additional storage in the flash storage.
|
||||
|
||||
```c
|
||||
&flash0 {
|
||||
partitions {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
ranges;
|
||||
|
||||
boot_partition: partition@0 {
|
||||
compatible = "zephyr,mapped-partition";
|
||||
label = "mcuboot";
|
||||
reg = <0x00000000 0x00008000>;
|
||||
};
|
||||
|
||||
slot0_partition: partition@8000 {
|
||||
compatible = "zephyr,mapped-partition";
|
||||
label = "image-0";
|
||||
reg = <0x00008000 0x00010000>;
|
||||
};
|
||||
|
||||
slot1_partition: partition@10000 {
|
||||
compatible = "zephyr,mapped-partition";
|
||||
label = "image-1";
|
||||
reg = <0x00010000 0x0018000>;
|
||||
};
|
||||
|
||||
storage_partition: partition@18000 {
|
||||
compatible = "zephyr,mapped-partition";
|
||||
label = "storage";
|
||||
reg = <0x00018000 0x00020000>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Try to build MCUBoot
|
||||
```sh
|
||||
west build -p always -b nucleo_g431rb bootloader/mcuboot/boot/zephyr
|
||||
```
|
||||
|
||||
|
||||
|
||||
old below
|
||||
```
|
||||
# Create a private key: https://docs.mcuboot.com/readme-zephyr.html
|
||||
./scripts/imgtool.py keygen -k mykey.pem -t rsa-2048
|
||||
python ./bootloader/mcuboot/scripts/imgtool.py keygen -k private.pem -t rsa-2048
|
||||
|
||||
# Create its public key
|
||||
openssl rsa -in mykey.pem -pubout > pubkey.pem
|
||||
openssl rsa -in private.pem -pubout > public.pem
|
||||
|
||||
# Set up signing: https://docs.mcuboot.com/readme-zephyr.html
|
||||
# ./bootloader/mcuboot/samples/zephyr/Makefile
|
||||
python scripts/imgtool.py sign \
|
||||
python bootloader/mcuboot/scripts/imgtool.py sign \
|
||||
--key mykey.pem \
|
||||
--header-size 0x200 \
|
||||
--align 8 \
|
||||
@@ -44,7 +111,7 @@ python scripts/imgtool.py sign \
|
||||
echo "
|
||||
|
||||
# Set the key file
|
||||
CONFIG_BOOT_SIGNATURE_KEY_FILE=pubkey.pem" >> "./zephyr/boards/st/nucleo_g431rb/nucleo_g431rb_defconfig"
|
||||
CONFIG_BOOT_SIGNATURE_KEY_FILE=public.pem" >> "./zephyr/boards/st/nucleo_g431rb/nucleo_g431rb_defconfig"
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user