Raspberry-Pi-4-Boot-Security
Raspberry-Pi-4-Boot-Security
Raspberry Pi Ltd
Colophon
© 2020-2023 Raspberry Pi Ltd (formerly Raspberry Pi (Trading) Ltd.)
This documentation is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND)
licence.
build-date: 2023-06-28
build-version: githash: fc34cc2-clean
RPL reserves the right to make any enhancements, improvements, corrections or any other modifications to the
RESOURCES or any products described in them at any time and without further notice.
The RESOURCES are intended for skilled users with suitable levels of design knowledge. Users are solely responsible for
their selection and use of the RESOURCES and any application of the products described in them. User agrees to
indemnify and hold RPL harmless against all liabilities, costs, damages or other losses arising out of their use of the
RESOURCES.
RPL grants users permission to use the RESOURCES solely in conjunction with the Raspberry Pi products. All other use of
the RESOURCES is prohibited. No licence is granted to any other RPL or other third party intellectual property right.
HIGH RISK ACTIVITIES. Raspberry Pi products are not designed, manufactured or intended for use in hazardous
environments requiring fail safe performance, such as in the operation of nuclear facilities, aircraft navigation or
communication systems, air traffic control, weapons systems or safety-critical applications (including life support
systems and other medical devices), in which the failure of the products could lead directly to death, personal injury or
severe physical or environmental damage (“High Risk Activities”). RPL specifically disclaims any express or implied
warranty of fitness for High Risk Activities and accepts no liability for use or inclusions of Raspberry Pi products in High
Risk Activities.
Raspberry Pi products are provided subject to RPL’s Standard Terms. RPL’s provision of the RESOURCES does not
expand or otherwise modify RPL’s Standard Terms including but not limited to the disclaimers and warranties expressed
in them.
Scope of document
This document applies to the following Raspberry Pi products:
* * *
Introduction
This white paper describes Raspberry Pi Ltd’s approach to boot security on the Raspberry Pi 4 family of devices, based on
the BCM2711 system on a chip (SoC).
Goals
Raspberry Pi Ltd’s goals for boot security are as follows:
• Enable industrial customers to ensure that a Raspberry Pi 4 only runs software authorised by them.
• Ensure customers have full control of the operating system (OS) image and sign it with their own RSA private key.
• Avoid centralised code-signing servers — the OS image and signing tools are open source and are run by the
customer.
• The RSA read-only memory (ROM) keys are public, so no shared secrets can be exposed by, for example, decapping
or JTAG access. The private RSA key for signing bootloader firmware is kept secure inside Raspberry Pi Ltd and is
not released to customers.
Limitations
Limited hardware support is offered on the BCM2711 SoC:
• Instructions on making and installing signed images; this is covered in a separate document.
• Encrypting the boot partition.
• Creating a security-enhanced version of Raspberry Pi OS.
Goals 3
Raspberry Pi 4 Boot Security
The stepping revision of the chip is etched on the top of the chip itself, as a subfield of the part number. Alternatively, once
booted you can determine the stepping using the following command:
This will return 0x27110010 for BCM2711B0, 0x27110011 for BCM2711B1, or 0x27110020 for BCM2711C0.
NOTE
Raspberry Pi Compute Module 4 and Raspberry Pi 400 are only available with the C0 or newer stepping. Older
BCM2711-based devices may or may not use the B0, B1, or C0 stepping, which may limit the applicability of the
security process.
• Signed boot images provide a chain of trust from the ROM to the kernel and the initramfs initial ramdisk, including
graphics processing unit firmware and configuration data.
• The boot image files are file allocation table (FAT) disk image files containing the normal files from the boot partition
as a single atomic file. These are loaded as a ramdisk loopback file system by the bootloader.
• Signed boot images can be loaded from any boot mode, e.g. network boot.
• OS updates are supported by downloading a new boot.img file, which is effectively an atomic update.
• Signed boot is enabled via OTP as part of the customer’s usual Raspberry Pi CM4 provisioning process. Once
enabled, signed boot cannot be switched off.
• EEPROM code is signed by Raspberry Pi Ltd and verified by RSA key in the ROM. There is no ability on the BCM2711
to countersign the Raspberry Pi Ltd code with a customer key.
• In secure boot mode the bootloader does check the hash of the VL805 USB hub firmware, but please note that the
VL805 ROM itself does not support code signing of its firmware.
The diagram below shows the root of trust for the secure boot process.
• The device boots, and if secure boot is enabled in the OTP, the ROM in the BCM2711 will verify the second-stage
bootloader against each boot ROM key in order, taking into account whether the key has been previously revoked by
comparing it against the OTP revocation bits.
• If the verification succeeds then the Bootsys in SPI EEPROM is executed; if not, the boot will be halted.
• Bootsys verifies that the customer key in SPI EEPROM matches the hash of the key stored in the OTP.
• Bootsys verifies the SPI EEPROM config against the customer key.
• Bootsys now executes Bootmain.
• Bootmain does some setup, then loads the boot.img into a ramdisk.
• Bootmain verifies the boot.img against the boot.sig file.
• Bootmain loads the start.elf file from the ramdisk and runs it.
• start.elf loads the Linux kernel and associated device trees and overlays from the ramdisk, and the main Linux
boot is started.
The individual parts of each process are covered in detail in the next sections.
If secure boot is enabled in the OTP, then the ROM will verify the second-stage bootloader/recovery.bin image against
the ROM keys before launching it.
• The signature only applies to the second-stage executable. There is no check for the entire EEPROM image.
• The ROM also checks the signature of recovery.bin when loaded via usbboot (rpiboot).
• The new bootloader that supports signed boot will be signed with the signed-boot ROM key. It is possible to revoke
the ROM development key by setting an OTP bit, which effectively revokes all previous bootloader releases on that
board.
Before loading the start.elf file, the second-stage bootloader loads additional resources, e.g. the VLI universal serial bus
(USB) firmware. These resources are considered to be immutable, and if signed boot is enabled (via OTP) then the
SHA256 hash of the resource is checked as it is read into memory. This is compared against SHA256 hashes generated
at build time and compiled into the bootcode.bin binary. Since bootcode.bin has already been verified by the ROM, the
compiled hashes can be trusted.
During this development stage, a key is programmed into the EEPROM, which is then made read-only. This improves
security for trivial file transfer protocol (TFTP) boot or for kiosk-type applications where a USB or Secure Digital (SD) card
may be accessible. However, it would be susceptible to replacement of the EEPROM, so this must be assumed to be
physically secure. In short, secure boot is suitable for environments where physical access to the board is restricted, as
well as for developing signing for test purposes.
You can develop the signed boot process to this stage using the following steps:
• Customer builds and signs boot.img with their RSA private key.
• The EEPROM image is updated to include the customer’s RSA public key.
• The EEPROM image is flashed using the Raspberry Pi CM4 provisioning process, and EEPROM write protect is
enabled.
Even this level of signing would not protect against the replacement of the Raspberry Pi CM4 or the SoC itself in an end
device. If this is a potential concern, the customer may wish to use customer OTP rows to store a decryption key to
decode, for example, the rootfs file system.
Features include:
• Permanently enables signed boot: only signed boot images can be loaded once set up.
• Revokes the ROM 'development key': it is not possible to downgrade the SPI EEPROM bootloader to an older or non-
secure version.
• An SHA256 digest of the customer’s public key is written to OTP and validates the customer’s RSA public key in the
EEPROM.
• The bootloader EEPROM configuration must be signed with the customer’s private key, which restricts which boot
modes will be tried.
• If the EEPROM public key or configuration is not valid then the boot stops.
Once security flags are set during the Raspberry Pi CM4 EEPROM flashing process, they cannot be unset.
Implementation details
boot.img
The boot.img file is a disk image of up to 180MB of a raw block device containing a FAT file system which is mounted as
a ramdisk/loopback file system. If signed boot is required then the RSA signature is verified before the bootloader mounts
the ramdisk.
In secure boot mode, the bootloader only looks for boot.img or boot.sig when scanning through the currently available
set of bootable media, i.e. SD, USB, NVMe, network or RPIBOOT, as defined by BOOT_ORDER. Once it finds a matching file,
it reads the entire file into memory, verifies the signature, and if everything is as expected, it mounts the file contents as a
ramdisk. If boot.img or boot.sig is not found, then that particular BOOT_ORDER is treated as 'firmware not found', and
the bootloader moves to the next boot mode.
Scripts in the usbboot repository are provided to automate the process of creating a .img file from a directory of source
files (start.elf, kernel, etc). rpi-eeprom-config has been updated to provide support for signing the EEPROM
configuration and storing the RSA public key in the EEPROM image.
If the 'tryboot' flag is set on a reboot (sudo reboot "0 tryboot"), then the bootloader will search for tryboot.img instead
of boot.img. This allows signed boot images to be tested before being activated.
The source for boot.img is a directory containing the files from the boot partition of Raspberry Pi OS. To reduce the load
time, files that are not relevant for the given board (e.g. unused kernel images) can be left out. Since the boot image is just
a single file, it is easy to update it to a new version.
The bootloader verifies that start.elf supports ramdisk images before executing it. If not, a version compatibility error
message is displayed, and booting stops. The firmware compatibility flags are encoded in a special section of the .elf
file, and in future the boot image scripts will also verify this to avoid accidentally creating non-bootable image files.
boot.img 7
Raspberry Pi 4 Boot Security
Several GPIO pins can be used for nRPIBOOT on Raspberry Pi 4 and 400: pins 2, 4, 5, 6, 7, and 8. There is an additional
constraint in that any HAT (Hardware Attached on Top) or GPIO-connected device being used should not pull the selected
pin low by default, as this will enable nRPIBOOT rather than SD card booting.
The recommended GPIO pin is GPIO8 (SPI CE0), which is not pulled low by default. Once chosen, the GPIO to be used as
the boot selector is stored in the OTP, and is set using recovery.bin.
Please refer to the GPIO section in the BCM2711 datasheet for more details on default GPIO allocations.
More information
Performance
The overhead of verifying a minimal boot.img (about 9MB) is approximately 3.5 seconds, which directly influences the
boot time. Most of this is the CPU overhead of the SHA256 calculation, and hence unavoidable.
The details of making these changes to your operating system, should they be required, are outside the scope of this
white paper, but can be found via a web search.
3. Which secure boot-related keys can and cannot be set by the customer?
The boot ROM contains four keys that are secured by Raspberry Pi Ltd and cannot be changed by the customer.
Only two are currently used. All of these keys can be revoked using OTP. The customer can set a key in EEPROM that
is used for signing the customer image. This key is protected by a hash in OTP.
4. How is secure boot mode enabled and persisted in the device’s configuration?
Flags in the BCM2711 on-board OTP.
Performance 9
Raspberry Pi 4 Boot Security
10. Is there a hardware random number generator, and if so what is the entropy source for it?
There is a hardware RNG, but no implementation details are available.
12. Which external or internal non-volatile memories, such as flash, does the BCM2711 support?
SPI EEPROM and SD/EMMC are supported by the boot ROM for loading the second stage. Secure boot disables the
SD/EMMC ROM boot mode.
13. Does the chip support execute-in-place from external non-volatile memory?
No.
Other
There is a buildroot-based secure boot example in the Raspberry Pi Ltd GitHub repository. It should be possible to simply
copy and paste the bash commands and see secure boot working by following these instructions:
Other 10