nihalpasham / rustBoot

rustBoot is a standalone bootloader written entirely in `Rust`, designed to run on anything from a microcontroller to a system on chip. It can be used to boot into bare-metal firmware or Linux.
MIT License
214 stars 21 forks source link

Added support for the RP2040 board #45

Closed abhishekdhamale closed 2 years ago

abhishekdhamale commented 2 years ago

19

Added and tested both secure boot and update firmware with QSPI enabled external flash-driver on RP2040 Pico Board.

Command line output

PS C:\Users\ELCOME\Documents\RustProjects\rustBoot-Abhishek\rustBoot> cargo rp2040 build-sign-flash rustBoot
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target\debug\xtask.exe rp2040 build-sign-flash rustBoot`
$ cargo build --release
    Finished release [optimized] target(s) in 0.15s
$ cargo build --release
    Finished release [optimized] target(s) in 0.16s
$ cargo build --release
    Finished release [optimized] target(s) in 0.13s
$ py convert2bin.py
$ py signer.py
['sign.py', '--ecc256', '--sha256', 'rp2040_bootfw.bin', 'ecc256.der', '1234']
Update type:          Firmware
Input image:          rp2040_bootfw.bin
Selected cipher:      ecc256
Public key:           ecc256.der
Output image:         rp2040_bootfw_v1234_signed.bin
Not Encrypted
Calculating sha256 digest...
Signing the firmware...
Done.
Output image successfully created.
['sign.py', '--ecc256', '--sha256', 'rp2040_updtfw.bin', 'ecc256.der', '1235']
Update type:          Firmware
Input image:          rp2040_updtfw.bin
Selected cipher:      ecc256
Public key:           ecc256.der
Output image:         rp2040_updtfw_v1235_signed.bin
Not Encrypted
Calculating sha256 digest...
Signing the firmware...
Done.
Output image successfully created.
$ probe-rs-cli download --format Bin --base-address 0x10020000 --chip RP2040 rp2040_bootfw_v1234_signed.bin
     Erasing sectors ✔ [00:00:00] [##############################################################################]  4.00KiB/ 4.00KiB @ 22.56KiB/s (eta 0s )
 Programming pages   ✔ [00:00:00] [##############################################################################]  4.00KiB/ 4.00KiB @ 10.01KiB/s (eta 0s )
    Finished in 0.489s
$ probe-rs-cli download --format Bin --base-address 0x10040000 --chip RP2040 rp2040_updtfw_v1235_signed.bin
     Erasing sectors ✔ [00:00:00] [##############################################################################]  4.00KiB/ 4.00KiB @ 22.96KiB/s (eta 0s )
 Programming pages   ✔ [00:00:00] [##############################################################################]  4.00KiB/ 4.00KiB @  9.73KiB/s (eta 0s )
    Finished in 0.515s
$ cargo flash --chip RP2040 --release
    Finished release [optimized] target(s) in 0.13s
    Flashing C:\Users\ELCOME\Documents\RustProjects\rustBoot-Abhishek\rustBoot\boards\target\thumbv6m-none-eabi\release\rp2040
     Erasing sectors ✔ [00:00:00] [##############################################################################] 48.00KiB/48.00KiB @ 43.30KiB/s (eta 0s )
 Programming pages   ✔ [00:00:02] [##############################################################################] 48.00KiB/48.00KiB @  9.69KiB/s (eta 0s )
    Finished in 3.184s
nihalpasham commented 2 years ago

A couple of points:

abhishekdhamale commented 2 years ago

After implementing the suggested changes I have pushed it the same PR.

Following is the command line output.

PS C:\Users\ELCOME\Documents\RustProjects\rustBoot-Abhishek\rustBoot> cargo rp2040 build-sign-flash rustBoot
    Finished dev [unoptimized + debuginfo] target(s) in 0.37s
     Running `target\debug\xtask.exe rp2040 build-sign-flash rustBoot`
$ cargo build --release
    Finished release [optimized] target(s) in 0.42s
$ cargo build --release
    Finished release [optimized] target(s) in 0.18s
$ cargo build --release
    Finished release [optimized] target(s) in 0.20s
$ py convert2bin.py
$ py signer.py
['sign.py', '--ecc256', '--sha256', 'rp2040_bootfw.bin', 'ecc256.der', '1234']
Update type:          Firmware
Input image:          rp2040_bootfw.bin
Selected cipher:      ecc256
Public key:           ecc256.der
Output image:         rp2040_bootfw_v1234_signed.bin
Not Encrypted
Calculating sha256 digest...
Signing the firmware...
Done.
Output image successfully created.
['sign.py', '--ecc256', '--sha256', 'rp2040_updtfw.bin', 'ecc256.der', '1235']
Update type:          Firmware
Input image:          rp2040_updtfw.bin
Selected cipher:      ecc256
Public key:           ecc256.der
Output image:         rp2040_updtfw_v1235_signed.bin
Not Encrypted
Calculating sha256 digest...
Signing the firmware...
Done.
Output image successfully created.
$ probe-rs-cli download --format Bin --base-address 0x10020000 --chip RP2040 rp2040_bootfw_v1234_signed.bin
     Erasing sectors ✔ [00:00:00] [######################################################################]  4.00KiB/ 4.00KiB @ 22.90KiB/s (eta 0s )
 Programming pages   ✔ [00:00:00] [######################################################################]  4.00KiB/ 4.00KiB @  9.98KiB/s (eta 0s )
    Finished in 0.504s
$ probe-rs-cli download --format Bin --base-address 0x10040000 --chip RP2040 rp2040_updtfw_v1235_signed.bin
     Erasing sectors ✔ [00:00:00] [######################################################################]  4.00KiB/ 4.00KiB @ 21.86KiB/s (eta 0s )
 Programming pages   ✔ [00:00:00] [######################################################################]  4.00KiB/ 4.00KiB @  9.53KiB/s (eta 0s )
    Finished in 0.523s
$ cargo flash --chip RP2040 --release
    Finished release [optimized] target(s) in 0.22s
    Flashing C:\Users\ELCOME\Documents\RustProjects\rustBoot-Abhishek\rustBoot\boards\target\thumbv6m-none-eabi\release\rp2040
     Erasing sectors ✔ [00:00:00] [######################################################################] 48.00KiB/48.00KiB @ 43.53KiB/s (eta 0s )
 Programming pages   ✔ [00:00:02] [######################################################################] 48.00KiB/48.00KiB @  9.66KiB/s (eta 0s )
    Finished in 3.301s
yashwanthsinghm commented 2 years ago

I have reviewed changes ,everything looks good now.

nihalpasham commented 2 years ago

looks good. thank you @abhishekdhamale 💥