Commit 6af4fdef00d56c1d8c485ee8b9eb78e951d20a10
Committed by
Tim Gover
1 parent
69bec5e8
secure-boot-example: Add step by step example / quick start
The secure-boot-example/boot.img has been replaced with the mass-storage-gadget Linux OS image because it already supported login, hdmi and ethernet.
Showing
6 changed files
with
162 additions
and
6 deletions
Readme.md
| @@ -91,6 +91,9 @@ Secure Boot requires the latest stable bootloader image. | @@ -91,6 +91,9 @@ Secure Boot requires the latest stable bootloader image. | ||
| 91 | WARNING: If the `revoke_devkey` option is used to revoke the ROM development key then it will | 91 | WARNING: If the `revoke_devkey` option is used to revoke the ROM development key then it will |
| 92 | not be possible to downgrade to a bootloader older than 2022-01-06 OR disable secure-boot mode. | 92 | not be possible to downgrade to a bootloader older than 2022-01-06 OR disable secure-boot mode. |
| 93 | 93 | ||
| 94 | +### Tutorial | ||
| 95 | +Creating a secure-boot system from scratch can be quite complex. The [secure-boot tutorial](secure-boot-example/README.md) uses a minimal example OS image to demonstrate how the Raspberry Pi specific aspects of secure-boot work. | ||
| 96 | + | ||
| 94 | ### Host setup | 97 | ### Host setup |
| 95 | Secure boot require a 2048 bit RSA asymmetric keypair and the Python `pycrytodomex` module to sign the EEPROM config and boot image. | 98 | Secure boot require a 2048 bit RSA asymmetric keypair and the Python `pycrytodomex` module to sign the EEPROM config and boot image. |
| 96 | 99 |
secure-boot-example/README.md
| 1 | -This directory contains an example secure boot image signed with the example private key in this directory. | 1 | +# Secure-boot quickstart |
| 2 | + | ||
| 3 | +## Overview | ||
| 4 | +Secure-boot is a mechanism for verifying the integrity of the kernel image and | ||
| 5 | +other files required during boot by storing them in a signed ramdisk image. | ||
| 6 | +These files include the GPU firmware (start.elf etc), Kernel, initrd, device-tree tree | ||
| 7 | +and overlays. | ||
| 8 | +Secure-boot does not depend on particular OS, nor does it provide services | ||
| 9 | +to the OS after startup. However, since the secure-boot will only load trusted | ||
| 10 | +kernel + initrd images the kernel/initrd can safely verify or mount an | ||
| 11 | +an encrypted file-system e.g. by using a TPM. | ||
| 12 | + | ||
| 13 | +N.B The memory for the secure ramdisk is reclaimed as soon as the CPU is started. | ||
| 14 | + | ||
| 15 | +## Example OS | ||
| 16 | +This example includes a simple buildroot image for Compute Module 4 in order | ||
| 17 | +to demonstrate secure-boot on a simple but functional OS. | ||
| 18 | + | ||
| 19 | +The example does NOT modify the OTP or make other permanent changes to the system | ||
| 20 | +and the code-signing can be disabled by reflashing the default bootloader EEPROM. | ||
| 21 | + | ||
| 22 | +The tutorial does not cover how to create the `boot.img` file or permanently | ||
| 23 | +require secure-boot in OTP. Please see the top level [README](../Readme.md#building) and | ||
| 24 | +[secure-boot-recovery/README](../secure-boot-recovery/README.md) guides for | ||
| 25 | +more information. | ||
| 26 | + | ||
| 27 | +### Requirements for running this example | ||
| 28 | +* A Raspberry Pi Compute Module 4 | ||
| 29 | +* Micro USB cable for `rpiboot` connection | ||
| 30 | +* USB serial cable (for debug logs) | ||
| 31 | +* Linux or Cygwin (Windows 10) | ||
| 32 | +* OpenSSL | ||
| 33 | +* Python3 | ||
| 34 | +* Python `cryptodomex` | ||
| 35 | + | ||
| 36 | +```bash | ||
| 37 | +python3 -m pip install pycryptodomex | ||
| 38 | +# or | ||
| 39 | +pip install pycryptodomex | ||
| 40 | +``` | ||
| 41 | + | ||
| 42 | +### Clean configuration | ||
| 43 | +Before starting it's advisable to create a fresh clone of the `usbboot` repo | ||
| 44 | +to ensure that there are no stale configuration files. | ||
| 45 | + | ||
| 46 | +```bash | ||
| 47 | +git clone https://github.com/raspberrypi/usbboot secure-boot | ||
| 48 | +cd secure-boot | ||
| 49 | +make | ||
| 50 | +``` | ||
| 51 | +See the top-level [README](../Readme.md) for build instructions. | ||
| 52 | + | ||
| 53 | +### Hardware setup for `rpiboot` mode | ||
| 54 | +Prepare the Compute Module for `rpiboot` mode. | ||
| 55 | + | ||
| 56 | +* Set the `nRPIBOOT` jumper which is labelled `Fit jumper to disable eMMC Boot' on the Compute Module 4 IO board. | ||
| 57 | +* Connect the micro USB cable to the `USB slave` port on the CM4 IO board. | ||
| 58 | +* Power cycle the CM4 IO board. | ||
| 59 | +* Connect the USB serial adapter to [GPIO 14/15](https://www.raspberrypi.com/documentation/computers/os.html#gpio-and-the-40-pin-header) on the 40-pin header. | ||
| 60 | + | ||
| 61 | +### Reset the Compute Module EEPROM | ||
| 62 | +Enable `rpiboot` mode and flash the latest EEPROM image | ||
| 63 | +```bash | ||
| 64 | +./rpiboot -d recovery | ||
| 65 | +``` | ||
| 66 | + | ||
| 67 | +### Boot the example image | ||
| 68 | +Enable `rpiboot` mode and load the OS via `rpiboot` without enabling code-signing. | ||
| 69 | +```bash | ||
| 70 | +./rpiboot -d secure-boot-example | ||
| 71 | +``` | ||
| 72 | +The OS should load and show activity on the boot UART and HDMI console. | ||
| 73 | + | ||
| 74 | +### Generate a signing key | ||
| 75 | +Secure-boot requires a 2048 bit RSA private key. You can either use a pre-existing | ||
| 76 | +key or generate an specific key for this example. The `KEY_FILE` environment variable | ||
| 77 | +used in the following instructions must contain the absolute path to the RSA private key in | ||
| 78 | +PEM format. | ||
| 79 | + | ||
| 80 | +```bash | ||
| 81 | +openssl genrsa 2048 > private.pem | ||
| 82 | +export KEY_FILE=$(pwd)/private.pem | ||
| 83 | +``` | ||
| 84 | + | ||
| 85 | +**In a production environment it's essential that this key-file is stored privately and securely.** | ||
| 86 | + | ||
| 87 | +### Update the EEPROM to require signed OS images | ||
| 88 | +Enable `rpiboot` mode and flash the bootloader EEPROM with updated setting enables code-signing. | ||
| 89 | + | ||
| 90 | +The `boot.conf` file sets the `SIGNED_BOOT` property `1` which instructs the bootloader to only | ||
| 91 | +load files (firmware, kernel, overlays etc) from `boot.img` instead of the normal boot partition and verify the `boot.img` signature `boot.sig` using the public key in the EEPROM. | ||
| 92 | + | ||
| 93 | +The `update-pieeprom.sh` generates the signed `pieeprom.bin` image. | ||
| 94 | + | ||
| 95 | +```bash | ||
| 96 | +cd secure-boot-recovery | ||
| 97 | +# Generate the signed EEPROM image. | ||
| 98 | +../tools/update-pieeprom.sh -k "${KEY_FILE}" | ||
| 99 | +cd .. | ||
| 100 | +./rpiboot -d secure-boot-recovery | ||
| 101 | +``` | ||
| 102 | + | ||
| 103 | +At this stage OTP has not been modified and the signed image requirement can be reverted by flashing a default, unsigned image. | ||
| 104 | +However, once the [OTP secure-boot flags](../secure-boot-recovery/README.md#locking-secure-boot-mode) are set then `SIGNED_BOOT` is permenantely enabled and cannot be overriden via the EEPROM config. | ||
| 105 | + | ||
| 106 | + | ||
| 107 | +### Update the signature for the example OS image | ||
| 108 | +```bash | ||
| 109 | +cd secure-boot-example | ||
| 110 | +../tools/rpi-eeprom-digest -i boot.img -o boot.sig -k "${KEY_FILE}" | ||
| 111 | +cd .. | ||
| 112 | +``` | ||
| 113 | + | ||
| 114 | +### Launch the signed OS image | ||
| 115 | +Enable `rpiboot` mode and run the example OS as before. However, if the | ||
| 116 | +`boot.sig` signature does not match `boot.img` the bootloader will refuse to | ||
| 117 | +load the OS. | ||
| 2 | 118 | ||
| 3 | -To sign the image with a different key run | ||
| 4 | ```bash | 119 | ```bash |
| 120 | +./rpiboot -d secure-boot-example | ||
| 121 | +``` | ||
| 122 | + | ||
| 123 | +This example OS image is minimal Linux ramdisk image. Login as `root` with the empty password. | ||
| 124 | + | ||
| 125 | +### Mount the CM4 SD/EMMC after enabling secure-boot | ||
| 126 | +Now that `SIGNED_BOOT` is enabled the bootloader will only load images signed with private key generated earlier. | ||
| 127 | +To boot the Compute Module in mass-storage mode a signed version of this code must be generated. | ||
| 128 | + | ||
| 129 | +**This signed-image should not be made available for download because it gives access to the EMMC as a block device** | ||
| 130 | + | ||
| 131 | + | ||
| 132 | +#### Sign the mass storage firmware image | ||
| 133 | +Sign the mass-storage drivers in the `secure-boot-msd` directory. Please see the [top level README](../Readme.md#compute-module-4-extensions) for a description of the different `usbboot` firmware drivers. | ||
| 134 | +```bash | ||
| 135 | +cd secure-boot-msd | ||
| 5 | ../tools/rpi-eeprom-digest -i boot.img -o boot.sig -k "${KEY_FILE}" | 136 | ../tools/rpi-eeprom-digest -i boot.img -o boot.sig -k "${KEY_FILE}" |
| 137 | +cd .. | ||
| 6 | ``` | 138 | ``` |
| 7 | 139 | ||
| 8 | -Clearly, product releases should never be signed with `example-private.pem`. | 140 | +#### Enable MSD mode. |
| 141 | +A new mass-storage device should now be visible on the host-OS. On Linux check `dmesg` for something like '/dev/sda' | ||
| 142 | +```bash | ||
| 143 | +./rpiboot -d secure-boot-msd | ||
| 144 | +``` | ||
| 145 | + | ||
| 146 | +### Loading `boot.img` from SD/EMMC. | ||
| 147 | +The bootloader can load a ramdisk `boot.img` from any of the bootable modes defined by the [BOOT_ORDER](https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#BOOT_ORDER) EEPROM config setting. | ||
| 148 | + | ||
| 149 | +For example. | ||
| 150 | + | ||
| 151 | +* Boot the CM4 in MSD mode as explained in the previous step. | ||
| 152 | +* Copy the `boot.img` and `boot.sig` files from the `secure-boot-example` stage to the mass-storage-drive. No other files are required. | ||
| 153 | +* Remove the `nRPIBOOT` jumper. | ||
| 154 | +* Power cycle the CM4 IO board. | ||
| 155 | +* The system should now boot into the OS. | ||
| 156 | + | ||
| 157 | +N.B. The example image is currently the same as the `mass-storage-gadget so the EMMC/SD will appear as block devices on the host PC if the micro USB cable is still connected. | ||
| 158 | + |
secure-boot-example/boot.img
No preview for this file type
secure-boot-example/boot.sig
| 1 | -f2557e1745433a570d9f2f0d9f69b7ca3123d2be20425c0fd80c5ffbec0cba69 | ||
| 2 | -ts: 1645529528 | ||
| 3 | -rsa2048: b4e1467691c03a1faf467166d4d1439704fb52cd8fd8b8016f6bd144fb750a80dbb933ea85e352c080f9cccd170cdd71565d00b4e80d6d8ec6374aa5826eb5470b17a8bb47a3ef5ad111cd253092c9dca3488c73d653a3ed04c92fab08e142908e2f7f5e393d65a2e1cb8e7748d3f75ae66d904e1ff253e4e28ed58b66e93bac4e88ea4b544353310f103bf6e2cbd59df9df0e2d548f71219d8d1aeeb101dc5a3d507d87b26ae656d00b14554af30bc2ba18b76783c3666db1743bd210b3f31e4ee49743ba04bd27e05d7c1d244c4066dc312ec793cda30f93f3031b8394206b1cd488d8589040392a3a5186332c134be1a6c25b72212fed12ff4bb7032fa5ea | 1 | +087d95cc403464a5d2385a0832c912fffb084799952c207a0867d8269acb1c55 |
| 2 | +ts: 1652640519 | ||
| 3 | +rsa2048: d97c850205fde305a24e12ea4c31994d57c95f394b83cc62e2878ab122f3b4688a0a577acb7de74f800866c6676cba1d646cb7e3b4e2ea30786aa193326db6461776d30264a4e7ef9f5465a8e4c31129515305ffa4ca91499372d663b18e3f7505e4d1a83fd930df8296bee056d1ec823bc8909a836e2ae21d131ed33779665abfc2d0b47b66f109246b89a6d4b8ee8df8334d6ef7e910b5624c299fcb16efb62d43d7b228d2ef770d0326132b97d54a8d2afbbf09bf53034f2c1f3c748a619437cd523c5c6a706d12fc2e3e285ec7d3b65be16c1ed33e47faf6565ab13cee4a01682ecc70d10c683c193caf02a6a2380572aa590f06be13481f365c0e686a78 |
secure-boot-example/bootcode4.bin
0 → 100644
No preview for this file type
secure-boot-example/config.txt
0 → 100644