Commit 6caf50cfd02b139e5c1217fd0deff849a3fd0af5
1 parent
4d7adfd3
secure-boot: Update example to use the raspberrypi-secure-boot buildroot example
Showing
2 changed files
with
51 additions
and
43 deletions
Readme.md
| ... | ... | @@ -128,9 +128,7 @@ Be careful not to overwrite `bootcode.bin` or `bootcode4.bin` with the executabl |
| 128 | 128 | |
| 129 | 129 | <a name="secure-boot"></a> |
| 130 | 130 | ## Secure Boot |
| 131 | -Secure Boot requires the latest stable bootloader image. | |
| 132 | -WARNING: If the `revoke_devkey` option is used to revoke the ROM development key then it will | |
| 133 | -not be possible to downgrade to a bootloader older than 2022-01-06 OR disable secure-boot mode. | |
| 131 | +Secure Boot requires a recent bootloader stable image e.g. the version in this repository. | |
| 134 | 132 | |
| 135 | 133 | ### Tutorial |
| 136 | 134 | 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. |
| ... | ... | @@ -156,57 +154,58 @@ openssl genrsa 2048 > private.pem |
| 156 | 154 | * Please see the [secure boot MSD guide](secure-boot-msd/README.md) for instructions about to mount the EMMC via USB mass-storage once secure-boot has been enabled. |
| 157 | 155 | |
| 158 | 156 | ## Secure Boot - image creation |
| 159 | -Secure boot requires a `boot.img` FAT image to be created. This plus a signature file (boot.sig) | |
| 160 | -must be placed in the boot partition of the Raspberry Pi. | |
| 157 | +Secure Boot requires self-contained ramdisk (`boot.img`) FAT image to be created containing the GPU | |
| 158 | +firmware, kernel and any other dependencies that would normally be loaded from the boot partition. | |
| 161 | 159 | |
| 162 | -The contents of the `boot.img` are the files normally present in the Raspberry Pi OS boot | |
| 163 | -partition i.e. firmware, DTBs and kernel image. However, in order to reduce boot time | |
| 164 | -it is advisable to remove unused files e.g. firmware or kernel images for Pi models. | |
| 160 | +This plus a signature file (boot.sig) must be placed in the boot partition of the Raspberry Pi | |
| 161 | +or network download location. | |
| 165 | 162 | |
| 166 | -The firmware must be new enough to support secure boot. The latest firmware APT | |
| 167 | -package supports secure boot. To download the firmware files directly. | |
| 168 | - | |
| 169 | -`git clone --depth 1 --branch stable https://github.com/raspberrypi/firmware` | |
| 170 | - | |
| 171 | -A helper script (`make-boot-image`) is provided to automate the image creation process. This | |
| 172 | -script depends upon the `mkfs.fat` and `losetup` tools and only runs on Linux. | |
| 163 | +The `boot.img` file should contain:- | |
| 164 | +* The kernel | |
| 165 | +* Device tree overlays | |
| 166 | +* GPU firmware (start.elf and fixup.dat) | |
| 167 | +* Linux initramfs containing the application OR scripts to mount/create an encrypted file-system. | |
| 173 | 168 | |
| 174 | -### Root File System | |
| 175 | -Normally, the Kernel modules and overlays for a secure-boot system would be provided | |
| 176 | -in an [initramfs](https://www.raspberrypi.com/documentation/computers/config_txt.html#initramfs) | |
| 177 | -and built with [buildroot](https://buildroot.org/) or [yocto](https://www.yoctoproject.org/). | |
| 169 | +Secure boot is only responsible for loading a verified Linux kernel and initramfs. It does NOT | |
| 170 | +verify the integrity of other file-systems or provide file-system encryption. This would normally be | |
| 171 | +implemented using standard Linux tools such as [LUKS](https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup). | |
| 172 | +and controlled by scripts / systemd services in an initramfs. | |
| 178 | 173 | |
| 179 | -This ensures that all of the kernel modules and device tree dependencies are covered | |
| 180 | -by the secure-boot signature. | |
| 174 | +### Building `boot.img` using buildroot | |
| 181 | 175 | |
| 182 | -Since the `initramfs` is part of the `boot.img` it is possible to replace GPU firmware, | |
| 183 | -kernel and dependencies in a single file update. | |
| 176 | +The `secure-boot-example` directory contains a simple `boot.img` example with working HDMI, | |
| 177 | +network, UART console and common tools in an initramfs. | |
| 184 | 178 | |
| 185 | -Alternatively, for test/development the following instructions explain how a normal | |
| 186 | -Raspberry Pi OS install can be modified to be booted with the secure-boot loader. | |
| 179 | +This was generated from the [raspberrypi-signed-boot](https://github.com/raspberrypi/buildroot/blob/raspberrypi-signed-boot/README.md) | |
| 180 | +buildroot config. Whilst not a generic fully featured configuration it should be relatively | |
| 181 | +straightforward to cherry-pick the `raspberrypi-secure-boot` package and helper scripts into | |
| 182 | +other buildroot configurations. | |
| 187 | 183 | |
| 188 | -#### Clone the Raspberry Pi OS boot files | |
| 189 | -Copy the contents of `/boot` to a local directory called `secure-boot-files` | |
| 184 | +### Manual boot image creation | |
| 185 | +For other systems or manual image creation a helper script `make-boot-image` in the tools | |
| 186 | +directory is provided. | |
| 190 | 187 | |
| 191 | -#### Set the kernel root device | |
| 192 | -Since the boot file-system for the firmware is now in a signed disk image the OS cannot write to this. | |
| 193 | -Therefore, any changes to `cmdline.txt` must be made before the `boot.img` file is signed. | |
| 188 | +To run:- | |
| 189 | +* Copy the source firmware + other files into a temporary directory (`temp`) | |
| 190 | +* Run `make-boot-image -d temp -O boot.img` | |
| 191 | +* Run `rpi-eeprom-digest -i boot.img -o boot.sig -k private-key.PEM` | |
| 194 | 192 | |
| 195 | -* Verify that `cmdline.txt` in `secure-boot-files` points to the correct UUID for the root file-system. | |
| 196 | - Alternatively, for testing, you can specify the root device name e.g. `root=/dev/mmcblk0p2`. | |
| 197 | - | |
| 198 | -* Remove `init-resize.sh` from `cmdline.txt` | |
| 193 | +`make-boot-image` depends upon the `mkfs.fat` and `losetup` Linux tools. | |
| 199 | 194 | |
| 195 | +#### Minimum firmware version | |
| 196 | +The firmware must be new enough to support secure boot. The latest firmware APT | |
| 197 | +package supports secure boot. To download the firmware files directly. | |
| 200 | 198 | |
| 201 | -#### Create the boot image | |
| 202 | -The `-b` product argument (pi4,pi400,cm4) tells the script to discard files which are not required by that product. This makes the image smaller and reduces the time taken to calculate the hash of the image file thereby reducing the boot time. | |
| 203 | 199 | ```bash |
| 204 | -sudo ../tools/make-boot-image -d secure-boot-files -o boot.img -b pi4 | |
| 200 | +git clone --depth 1 --branch stable https://github.com/raspberrypi/firmware | |
| 205 | 201 | ``` |
| 206 | 202 | |
| 207 | -The maximum supported size for boot.img is currently 96 megabytes. | |
| 203 | +To check the version information within a `start4.elf` firmware file run | |
| 204 | +```bash | |
| 205 | +strings start4.elf | grep VC_BUILD_ | |
| 206 | +``` | |
| 208 | 207 | |
| 209 | -#### Verify the boot image | |
| 208 | +#### Verifying a boot image | |
| 210 | 209 | To verify that the boot image has been created correctly use losetup to mount the .img file. |
| 211 | 210 | |
| 212 | 211 | ```bash |
| ... | ... | @@ -224,7 +223,7 @@ losetup -d ${LOOP} |
| 224 | 223 | rmdir boot-mount |
| 225 | 224 | ``` |
| 226 | 225 | |
| 227 | -#### Sign the boot image | |
| 226 | +#### Signing the boot image | |
| 228 | 227 | For secure-boot, `rpi-eeprom-digest` extends the current `.sig` format of |
| 229 | 228 | sha256 + timestamp to include an hex format RSA bit PKCS#1 v1.5 signature. The key length |
| 230 | 229 | must be 2048 bits. |
| ... | ... | @@ -232,6 +231,15 @@ must be 2048 bits. |
| 232 | 231 | ```bash |
| 233 | 232 | ../tools/rpi-eeprom-digest -i boot.img -o boot.sig -k "${KEY_FILE}" |
| 234 | 233 | ``` |
| 234 | + | |
| 235 | +To verify the signature of an existing image set the `PUBLIC_KEY_FILE` environment variable | |
| 236 | +to the path of the public key file in PEM format. | |
| 237 | + | |
| 238 | +```bash | |
| 239 | +../tools/rpi-eeprom-digest -i boot.img -k "${PUBLIC_KEY_FILE}" -v boot.sig | |
| 240 | +``` | |
| 241 | + | |
| 242 | + | |
| 235 | 243 | #### Hardware security modules |
| 236 | 244 | `rpi-eeprom-digest` is a shell script that wraps a call to `openssl dgst -sign`. |
| 237 | 245 | If the private key is stored within a hardware security module instead of | ... | ... |
secure-boot-example/README.md
| ... | ... | @@ -28,7 +28,7 @@ more information. |
| 28 | 28 | * A Raspberry Pi Compute Module 4 |
| 29 | 29 | * Micro USB cable for `rpiboot` connection |
| 30 | 30 | * USB serial cable (for debug logs) |
| 31 | -* Linux or Cygwin (Windows 10) | |
| 31 | +* Linux, WSL or Cygwin (Windows 10) | |
| 32 | 32 | * OpenSSL |
| 33 | 33 | * Python3 |
| 34 | 34 | * Python `cryptodomex` |
| ... | ... | @@ -101,7 +101,7 @@ cd .. |
| 101 | 101 | ``` |
| 102 | 102 | |
| 103 | 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. | |
| 104 | +However, once the [OTP secure-boot flags](../secure-boot-recovery/README.md#locking-secure-boot-mode) are set then `SIGNED_BOOT` is permanently enabled and cannot be overridden via the EEPROM config. | |
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | ### Update the signature for the example OS image |
| ... | ... | @@ -154,5 +154,5 @@ For example: |
| 154 | 154 | * Power cycle the CM4 IO board. |
| 155 | 155 | * The system should now boot into the OS. |
| 156 | 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. | |
| 157 | +The secure-boot example image can be rebuilt and modified using buildroot. See [raspberrypi-signed-boot buildroot](https://github.com/raspberrypi/buildroot/blob/raspberrypi-signed-boot/README.md) | |
| 158 | 158 | ... | ... |