Commit 4a21a619f229327c43f658b82c7afae6b927bed0

Authored by Tim Gover
1 parent 1ae3d7ec

docs: Update mass-storage gadget + secure-boot

* Remove the reference to LEDs flashing with mass-storage-gadget
  because this code was removed.
* Mention LUKS / rpi-otp-private-key in the secure-boot section.
* Add a link to the PIP
* Drop reference to make-boot-image - just use buildroot.
Readme.md
@@ -91,6 +91,9 @@ the minimal set of files required from the boot partition. @@ -91,6 +91,9 @@ the minimal set of files required from the boot partition.
91 91
92 This section describes how to diagnose common `rpiboot` failures for Compute Modules. Whilst `rpiboot` is tested on every Compute Module during manufacture the system relies on multiple hardware and software elements. The aim of this guide is to make it easier to identify which component is failing. 92 This section describes how to diagnose common `rpiboot` failures for Compute Modules. Whilst `rpiboot` is tested on every Compute Module during manufacture the system relies on multiple hardware and software elements. The aim of this guide is to make it easier to identify which component is failing.
93 93
  94 +### Product Information Portal
  95 +The [Product Information Portal](https://pip.raspberrypi.com/) contains the official documentation for hardware revision changes for Raspberry Pi computers.
  96 +
94 ### Hardware 97 ### Hardware
95 * Inspect the Compute Module pins and connector for signs of damage and verify that the socket is free from debris. 98 * Inspect the Compute Module pins and connector for signs of damage and verify that the socket is free from debris.
96 * Check that the Compute Module is fully inserted. 99 * Check that the Compute Module is fully inserted.
@@ -157,7 +160,7 @@ openssl genrsa 2048 > private.pem @@ -157,7 +160,7 @@ openssl genrsa 2048 > private.pem
157 Secure Boot requires self-contained ramdisk (`boot.img`) FAT image to be created containing the GPU 160 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 firmware, kernel and any other dependencies that would normally be loaded from the boot partition.
159 162
160 -This plus a signature file (boot.sig) must be placed in the boot partition of the Raspberry Pi 163 +This plus a signature file (`boot.sig`) must be placed in the boot partition of the Raspberry Pi
161 or network download location. 164 or network download location.
162 165
163 The `boot.img` file should contain:- 166 The `boot.img` file should contain:-
@@ -166,10 +169,39 @@ The `boot.img` file should contain:- @@ -166,10 +169,39 @@ The `boot.img` file should contain:-
166 * GPU firmware (start.elf and fixup.dat) 169 * GPU firmware (start.elf and fixup.dat)
167 * Linux initramfs containing the application OR scripts to mount/create an encrypted file-system. 170 * Linux initramfs containing the application OR scripts to mount/create an encrypted file-system.
168 171
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. 172 +
  173 +### Disk encryption
  174 +Secure-boot loads the `boot.img` from an unencrypted FAT / EFI boot partition and is responsible for
  175 +loading the Kernel + initramfs. There is no support in the firmware or ROM for full-disk encryption.
  176 +
  177 +If a custom OS image needs to use an encrypted file-system then this would normally be implement
  178 +via scripts within the initramfs.
  179 +
  180 +Raspberry Pi computers do not have a secure enclave, however, it's possible to store a 256 bit
  181 +[device specific private key](https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#device-specific-private-key)
  182 +in OTP. The key is accessible to any process with access to `/dev/vcio` (`vcmailbox`) so the
  183 +secure-boot OS must ensure that access to this interface is restricted.
  184 +
  185 +**It's not possible to prevent code kernel code from accessing OTP directly**
  186 +
  187 +See also:-
  188 +* [LUKS](https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup)
  189 +* [cryptsetup FAQ](https://gitlab.com/cryptsetup/cryptsetup/-/wikis/FrequentlyAskedQuestions)
  190 +* [rpi-otp-private-key](../tools/rpi-otp-private-key)
  191 +
  192 +Example script which uses a device-specific private key to create/mount an encrypted file-system.
  193 +```bash
  194 +export BLK_DEV=/dev/mmcblk0p3
  195 +export KEY_FILE=$(mktemp -d)/key.bin
  196 +rpi-otp-private-key -b > "${KEY_FILE}"
  197 +cryptsetup luksFormat --key-file="${KEY_FILE}" --key-size=256 --type=luks2 ${BLK_DEV}
  198 +
  199 +cryptsetup luksOpen ${BLK_DEV} encrypted-disk --key-file="${KEY_FILE}"
  200 +mkfs /dev/mapper/encrypted-disk
  201 +mkdir -p /mnt/application-data
  202 +mount /dev/mapper/encrypted-disk /mnt/application-data
  203 +rm "${KEY_FILE}"
  204 +```
173 205
174 ### Building `boot.img` using buildroot 206 ### Building `boot.img` using buildroot
175 207
@@ -181,17 +213,6 @@ buildroot config. Whilst not a generic fully featured configuration it should be @@ -181,17 +213,6 @@ buildroot config. Whilst not a generic fully featured configuration it should be
181 straightforward to cherry-pick the `raspberrypi-secure-boot` package and helper scripts into 213 straightforward to cherry-pick the `raspberrypi-secure-boot` package and helper scripts into
182 other buildroot configurations. 214 other buildroot configurations.
183 215
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.  
187 -  
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`  
192 -  
193 -`make-boot-image` depends upon the `mkfs.fat` and `losetup` Linux tools.  
194 -  
195 #### Minimum firmware version 216 #### Minimum firmware version
196 The firmware must be new enough to support secure boot. The latest firmware APT 217 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. 218 package supports secure boot. To download the firmware files directly.
@@ -205,7 +226,7 @@ To check the version information within a `start4.elf` firmware file run @@ -205,7 +226,7 @@ To check the version information within a `start4.elf` firmware file run
205 strings start4.elf | grep VC_BUILD_ 226 strings start4.elf | grep VC_BUILD_
206 ``` 227 ```
207 228
208 -#### Verifying a boot image 229 +#### Verifying the contents of a `boot.img` file
209 To verify that the boot image has been created correctly use losetup to mount the .img file. 230 To verify that the boot image has been created correctly use losetup to mount the .img file.
210 231
211 ```bash 232 ```bash
mass-storage-gadget/README.md
@@ -7,6 +7,21 @@ USB mass storage devices using the Linux gadget-fs drivers. @@ -7,6 +7,21 @@ USB mass storage devices using the Linux gadget-fs drivers.
7 This allows Raspberry Pi Imager to be run on the host computer 7 This allows Raspberry Pi Imager to be run on the host computer
8 and write OS images to the Compute Module block devices. 8 and write OS images to the Compute Module block devices.
9 9
  10 +## Running
  11 +To run load the USB MSD device drivers via RPIBOOT run
  12 +```bash
  13 +cd mass-storage-gadget
  14 +../rpiboot -d .
  15 +
  16 +```
  17 +N.B. This takes a few seconds longer to initialise than the
  18 +previous mass storage implementation. However, the write speed
  19 +should be much faster now that all of the file-system code
  20 +is running on the ARM processors.
  21 +
  22 +### Debug
  23 +The mass-storage-gadget image automatically enables a UART console for debugging (user `root` empty password).
  24 +
10 ## secure-boot 25 ## secure-boot
11 If secure-boot mode has been locked (via OTP) then both the 26 If secure-boot mode has been locked (via OTP) then both the
12 bootloader and rpiboot `bootcode4.bin` will only load `boot.img` 27 bootloader and rpiboot `bootcode4.bin` will only load `boot.img`
@@ -25,24 +40,6 @@ KEY_FILE=$HOME/private.pem @@ -25,24 +40,6 @@ KEY_FILE=$HOME/private.pem
25 ../tools/rpi-eeprom-digest -i boot.img -o boot.sig -k "${KEY_FILE}" 40 ../tools/rpi-eeprom-digest -i boot.img -o boot.sig -k "${KEY_FILE}"
26 ``` 41 ```
27 42
28 -## Running  
29 -To run load the USB MSD device drivers via RPIBOOT run  
30 -```bash  
31 -../rpiboot -d .  
32 -```  
33 -  
34 -The activity LED will flash three times once the USB MSD  
35 -devices have been initialised. A message will also be printed  
36 -to the HDMI console.  
37 -  
38 -The UART console is also enabled (user 'root' no password)  
39 -so that the user can login and debug the Compute Module.  
40 -  
41 -N.B. This takes a few seconds longer to initialise than the  
42 -previous mass storage implementation. However, the write speed  
43 -should be much faster now that all of the file-system code  
44 -is running on the ARM processors.  
45 -  
46 ## Source code 43 ## Source code
47 The buildroot configuration and supporting patches is available on 44 The buildroot configuration and supporting patches is available on
48 the [mass-storage-gadget](https://github.com/raspberrypi/buildroot/tree/mass-storage-gadget) 45 the [mass-storage-gadget](https://github.com/raspberrypi/buildroot/tree/mass-storage-gadget)
@@ -58,18 +55,3 @@ make @@ -58,18 +55,3 @@ make
58 55
59 The output is written to `output/target/images/sdcard.img` and can be copied 56 The output is written to `output/target/images/sdcard.img` and can be copied
60 to `boot.img` 57 to `boot.img`
61 -  
62 -Optional:  
63 -Load time can be reduced by optmizing the size of the sdcard.img as  
64 -follows (run as root).  
65 -  
66 -```bash  
67 -mkdir -p source-files  
68 -kpartx -av sdcard.img  
69 -mount /dev/mapper/loop0p1 source-files/  
70 -usbboot/tools/make-boot-image -d source-files/ -o boot.img  
71 -umount source-files  
72 -kpartx -dv sdcard.img  
73 -dmsetup remove /dev/mapper/loop0p1  
74 -losetup -D  
75 -```  
secure-boot-example/README.md
1 # Secure Boot Quickstart 1 # Secure Boot Quickstart
2 2
3 ## Overview 3 ## Overview
4 -Secure boot is a mechanism for verifying the integrity of the kernel image and 4 +Secure boot is a mechanism for verifying the integrity of the kernel+initramfs and
5 other files required during boot by storing them in a signed ramdisk image. 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 6 These files include the GPU firmware (start.elf etc), kernel, initrd, Device Tree
7 and overlays. 7 and overlays.
  8 +
8 Secure boot does not depend on a particular OS, nor does it provide services 9 Secure boot does not depend on a particular OS, nor does it provide services
9 -to the OS after startup. However, since secure boot will only load trusted  
10 -kernel and initrd images, the kernel/initrd can safely verify or mount an  
11 -an encrypted file system e.g. by using a TPM. 10 +to the OS after the Kernel + initramfs has started.
12 11
13 N.B. The memory for the secure ramdisk is reclaimed as soon as the CPU is started. 12 N.B. The memory for the secure ramdisk is reclaimed as soon as the CPU is started.
14 13
@@ -100,7 +99,7 @@ cd .. @@ -100,7 +99,7 @@ cd ..
100 ./rpiboot -d secure-boot-recovery 99 ./rpiboot -d secure-boot-recovery
101 ``` 100 ```
102 101
103 -At this stage OTP has not been modified and the signed image requirement can be reverted by flashing a default, unsigned image. 102 +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 permanently enabled and cannot be overridden via the EEPROM config. 103 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 104
106 105
@@ -123,9 +122,9 @@ load the OS. @@ -123,9 +122,9 @@ load the OS.
123 This example OS image is minimal Linux ramdisk image. Login as `root` with the empty password. 122 This example OS image is minimal Linux ramdisk image. Login as `root` with the empty password.
124 123
125 ### Mount the CM4 SD/EMMC after enabling secure-boot 124 ### 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 - 125 +Now that `SIGNED_BOOT` is enabled the bootloader will only load images signed with private key generated earlier.
  126 +To boot the Compute Module in mass storage mode a signed version of this code must be generated.
  127 +
129 **This signed image should not be made available for download because it gives access to the EMMC as a block device.** 128 **This signed image should not be made available for download because it gives access to the EMMC as a block device.**
130 129
131 130
@@ -155,4 +154,3 @@ For example: @@ -155,4 +154,3 @@ For example:
155 * The system should now boot into the OS. 154 * The system should now boot into the OS.
156 155
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) 156 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 -