Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | .. Copyright (c) 2018 Heinrich Schuchardt |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 3 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 4 | UEFI on U-Boot |
| 5 | ============== |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 6 | |
| 7 | The Unified Extensible Firmware Interface Specification (UEFI) [1] has become |
| 8 | the default for booting on AArch64 and x86 systems. It provides a stable API for |
| 9 | the interaction of drivers and applications with the firmware. The API comprises |
| 10 | access to block storage, network, and console to name a few. The Linux kernel |
| 11 | and boot loaders like GRUB or the FreeBSD loader can be executed. |
| 12 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 13 | Development target |
| 14 | ------------------ |
Heinrich Schuchardt | 9ba712d | 2019-03-28 08:09:16 +0100 | [diff] [blame] | 15 | |
Heinrich Schuchardt | dc6f3f4 | 2019-04-10 08:04:38 +0200 | [diff] [blame] | 16 | The implementation of UEFI in U-Boot strives to reach the requirements described |
| 17 | in the "Embedded Base Boot Requirements (EBBR) Specification - Release v1.0" |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 18 | [2]. The "Server Base Boot Requirements System Software on ARM Platforms" [3] |
Heinrich Schuchardt | dc6f3f4 | 2019-04-10 08:04:38 +0200 | [diff] [blame] | 19 | describes a superset of the EBBR specification and may be used as further |
| 20 | reference. |
Heinrich Schuchardt | 9ba712d | 2019-03-28 08:09:16 +0100 | [diff] [blame] | 21 | |
| 22 | A full blown UEFI implementation would contradict the U-Boot design principle |
| 23 | "keep it small". |
| 24 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 25 | Building U-Boot for UEFI |
| 26 | ------------------------ |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 27 | |
Heinrich Schuchardt | 4f3cb4d | 2018-12-30 12:54:36 +0100 | [diff] [blame] | 28 | The UEFI standard supports only little-endian systems. The UEFI support can be |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 29 | activated for ARM and x86 by specifying:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 30 | |
| 31 | CONFIG_CMD_BOOTEFI=y |
| 32 | CONFIG_EFI_LOADER=y |
| 33 | |
| 34 | in the .config file. |
| 35 | |
| 36 | Support for attaching virtual block devices, e.g. iSCSI drives connected by the |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 37 | loaded UEFI application [4], requires:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 38 | |
| 39 | CONFIG_BLK=y |
| 40 | CONFIG_PARTITIONS=y |
| 41 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 42 | Executing a UEFI binary |
| 43 | ~~~~~~~~~~~~~~~~~~~~~~~ |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 44 | |
| 45 | The bootefi command is used to start UEFI applications or to install UEFI |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 46 | drivers. It takes two parameters:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 47 | |
| 48 | bootefi <image address> [fdt address] |
| 49 | |
| 50 | * image address - the memory address of the UEFI binary |
| 51 | * fdt address - the memory address of the flattened device tree |
| 52 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 53 | Below you find the output of an example session starting GRUB:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 54 | |
| 55 | => load mmc 0:2 ${fdt_addr_r} boot/dtb |
| 56 | 29830 bytes read in 14 ms (2 MiB/s) |
| 57 | => load mmc 0:1 ${kernel_addr_r} efi/debian/grubaa64.efi |
| 58 | reading efi/debian/grubaa64.efi |
| 59 | 120832 bytes read in 7 ms (16.5 MiB/s) |
| 60 | => bootefi ${kernel_addr_r} ${fdt_addr_r} |
| 61 | |
Heinrich Schuchardt | 5f59518 | 2021-01-12 12:46:24 +0100 | [diff] [blame] | 62 | When booting from a memory location it is unknown from which file it was loaded. |
| 63 | Therefore the bootefi command uses the device path of the block device partition |
| 64 | or the network adapter and the file name of the most recently loaded PE-COFF |
| 65 | file when setting up the loaded image protocol. |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 66 | |
Cristian Ciocaltea | 2dbab87 | 2019-12-24 18:05:41 +0200 | [diff] [blame] | 67 | Launching a UEFI binary from a FIT image |
| 68 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 69 | |
| 70 | A signed FIT image can be used to securely boot a UEFI image via the |
| 71 | bootm command. This feature is available if U-Boot is configured with:: |
| 72 | |
| 73 | CONFIG_BOOTM_EFI=y |
| 74 | |
| 75 | A sample configuration is provided as file doc/uImage.FIT/uefi.its. |
| 76 | |
| 77 | Below you find the output of an example session starting GRUB:: |
| 78 | |
| 79 | => load mmc 0:1 ${kernel_addr_r} image.fit |
| 80 | 4620426 bytes read in 83 ms (53.1 MiB/s) |
| 81 | => bootm ${kernel_addr_r}#config-grub-nofdt |
| 82 | ## Loading kernel from FIT Image at 40400000 ... |
| 83 | Using 'config-grub-nofdt' configuration |
| 84 | Verifying Hash Integrity ... sha256,rsa2048:dev+ OK |
| 85 | Trying 'efi-grub' kernel subimage |
| 86 | Description: GRUB EFI Firmware |
| 87 | Created: 2019-11-20 8:18:16 UTC |
| 88 | Type: Kernel Image (no loading done) |
| 89 | Compression: uncompressed |
| 90 | Data Start: 0x404000d0 |
| 91 | Data Size: 450560 Bytes = 440 KiB |
| 92 | Hash algo: sha256 |
| 93 | Hash value: 4dbee00021112df618f58b3f7cf5e1595533d543094064b9ce991e8b054a9eec |
| 94 | Verifying Hash Integrity ... sha256+ OK |
| 95 | XIP Kernel Image (no loading done) |
| 96 | ## Transferring control to EFI (at address 404000d0) ... |
| 97 | Welcome to GRUB! |
| 98 | |
| 99 | See doc/uImage.FIT/howto.txt for an introduction to FIT images. |
| 100 | |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 101 | Configuring UEFI secure boot |
| 102 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 103 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 104 | The UEFI specification[1] defines a secure way of executing UEFI images |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 105 | by verifying a signature (or message digest) of image with certificates. |
| 106 | This feature on U-Boot is enabled with:: |
| 107 | |
| 108 | CONFIG_UEFI_SECURE_BOOT=y |
| 109 | |
| 110 | To make the boot sequence safe, you need to establish a chain of trust; |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 111 | In UEFI secure boot the chain trust is defined by the following UEFI variables |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 112 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 113 | * PK - Platform Key |
| 114 | * KEK - Key Exchange Keys |
| 115 | * db - white list database |
| 116 | * dbx - black list database |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 117 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 118 | An in depth description of UEFI secure boot is beyond the scope of this |
| 119 | document. Please, refer to the UEFI specification and available online |
| 120 | documentation. Here is a simple example that you can follow for your initial |
| 121 | attempt (Please note that the actual steps will depend on your system and |
| 122 | environment.): |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 123 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 124 | Install the required tools on your host |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 125 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 126 | * openssl |
| 127 | * efitools |
| 128 | * sbsigntool |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 129 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 130 | Create signing keys and the key database on your host: |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 131 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 132 | The platform key |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 133 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 134 | .. code-block:: bash |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 135 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 136 | openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=TEST_PK/ \ |
| 137 | -keyout PK.key -out PK.crt -nodes -days 365 |
| 138 | cert-to-efi-sig-list -g 11111111-2222-3333-4444-123456789abc \ |
| 139 | PK.crt PK.esl; |
| 140 | sign-efi-sig-list -c PK.crt -k PK.key PK PK.esl PK.auth |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 141 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 142 | The key exchange keys |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 143 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 144 | .. code-block:: bash |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 145 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 146 | openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=TEST_KEK/ \ |
| 147 | -keyout KEK.key -out KEK.crt -nodes -days 365 |
| 148 | cert-to-efi-sig-list -g 11111111-2222-3333-4444-123456789abc \ |
| 149 | KEK.crt KEK.esl |
| 150 | sign-efi-sig-list -c PK.crt -k PK.key KEK KEK.esl KEK.auth |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 151 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 152 | The whitelist database |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 153 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 154 | .. code-block:: bash |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 155 | |
Heinrich Schuchardt | abd40a8 | 2020-12-12 09:15:12 +0100 | [diff] [blame] | 156 | openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=TEST_db/ \ |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 157 | -keyout db.key -out db.crt -nodes -days 365 |
Heinrich Schuchardt | abd40a8 | 2020-12-12 09:15:12 +0100 | [diff] [blame] | 158 | cert-to-efi-sig-list -g 11111111-2222-3333-4444-123456789abc \ |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 159 | db.crt db.esl |
Heinrich Schuchardt | abd40a8 | 2020-12-12 09:15:12 +0100 | [diff] [blame] | 160 | sign-efi-sig-list -c KEK.crt -k KEK.key db db.esl db.auth |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 161 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 162 | Copy the \*.auth files to media, say mmc, that is accessible from U-Boot. |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 163 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 164 | Sign an image with one of the keys in "db" on your host |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 165 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 166 | .. code-block:: bash |
| 167 | |
| 168 | sbsign --key db.key --cert db.crt helloworld.efi |
| 169 | |
| 170 | Now in U-Boot install the keys on your board:: |
| 171 | |
| 172 | fatload mmc 0:1 <tmpaddr> PK.auth |
Heinrich Schuchardt | 2b3fbcb | 2020-08-24 08:27:49 +0200 | [diff] [blame] | 173 | setenv -e -nv -bs -rt -at -i <tmpaddr>:$filesize PK |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 174 | fatload mmc 0:1 <tmpaddr> KEK.auth |
Heinrich Schuchardt | 2b3fbcb | 2020-08-24 08:27:49 +0200 | [diff] [blame] | 175 | setenv -e -nv -bs -rt -at -i <tmpaddr>:$filesize KEK |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 176 | fatload mmc 0:1 <tmpaddr> db.auth |
Heinrich Schuchardt | 2b3fbcb | 2020-08-24 08:27:49 +0200 | [diff] [blame] | 177 | setenv -e -nv -bs -rt -at -i <tmpaddr>:$filesize db |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 178 | |
| 179 | Set up boot parameters on your board:: |
| 180 | |
| 181 | efidebug boot add 1 HELLO mmc 0:1 /helloworld.efi.signed "" |
| 182 | |
| 183 | Now your board can run the signed image via the boot manager (see below). |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 184 | You can also try this sequence by running Pytest, test_efi_secboot, |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 185 | on the sandbox |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 186 | |
Heinrich Schuchardt | 788bd90 | 2020-04-16 20:31:56 +0200 | [diff] [blame] | 187 | .. code-block:: bash |
| 188 | |
| 189 | cd <U-Boot source directory> |
| 190 | pytest.py test/py/tests/test_efi_secboot/test_signed.py --bd sandbox |
AKASHI Takahiro | b2ace87 | 2020-04-14 11:51:54 +0900 | [diff] [blame] | 191 | |
Heinrich Schuchardt | 677da1c | 2020-07-14 12:52:51 +0200 | [diff] [blame] | 192 | UEFI binaries may be signed by Microsoft using the following certificates: |
| 193 | |
| 194 | * KEK: Microsoft Corporation KEK CA 2011 |
| 195 | http://go.microsoft.com/fwlink/?LinkId=321185. |
| 196 | * db: Microsoft Windows Production PCA 2011 |
| 197 | http://go.microsoft.com/fwlink/p/?linkid=321192. |
| 198 | * db: Microsoft Corporation UEFI CA 2011 |
| 199 | http://go.microsoft.com/fwlink/p/?linkid=321194. |
| 200 | |
Ilias Apalodimas | e498dac | 2020-05-17 22:25:47 +0300 | [diff] [blame] | 201 | Using OP-TEE for EFI variables |
| 202 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 203 | |
| 204 | Instead of implementing UEFI variable services inside U-Boot they can |
| 205 | also be provided in the secure world by a module for OP-TEE[1]. The |
| 206 | interface between U-Boot and OP-TEE for variable services is enabled by |
| 207 | CONFIG_EFI_MM_COMM_TEE=y. |
| 208 | |
| 209 | Tianocore EDK II's standalone management mode driver for variables can |
| 210 | be linked to OP-TEE for this purpose. This module uses the Replay |
| 211 | Protected Memory Block (RPMB) of an eMMC device for persisting |
| 212 | non-volatile variables. When calling the variable services via the |
| 213 | OP-TEE API U-Boot's OP-TEE supplicant relays calls to the RPMB driver |
| 214 | which has to be enabled via CONFIG_SUPPORT_EMMC_RPMB=y. |
| 215 | |
| 216 | [1] https://optee.readthedocs.io/ - OP-TEE documentation |
| 217 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 218 | Executing the boot manager |
| 219 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 220 | |
Heinrich Schuchardt | ebcbfc7 | 2020-08-16 12:27:19 +0200 | [diff] [blame] | 221 | The UEFI specification foresees to define boot entries and boot sequence via |
| 222 | UEFI variables. Booting according to these variables is possible via:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 223 | |
| 224 | bootefi bootmgr [fdt address] |
| 225 | |
Heinrich Schuchardt | ebcbfc7 | 2020-08-16 12:27:19 +0200 | [diff] [blame] | 226 | As of U-Boot v2020.10 UEFI variables cannot be set at runtime. The U-Boot |
| 227 | command 'efidebug' can be used to set the variables. |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 228 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 229 | Executing the built in hello world application |
| 230 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 231 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 232 | A hello world UEFI application can be built with:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 233 | |
| 234 | CONFIG_CMD_BOOTEFI_HELLO_COMPILE=y |
| 235 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 236 | It can be embedded into the U-Boot binary with:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 237 | |
| 238 | CONFIG_CMD_BOOTEFI_HELLO=y |
| 239 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 240 | The bootefi command is used to start the embedded hello world application:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 241 | |
| 242 | bootefi hello [fdt address] |
| 243 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 244 | Below you find the output of an example session:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 245 | |
| 246 | => bootefi hello ${fdtcontroladdr} |
| 247 | ## Starting EFI application at 01000000 ... |
| 248 | WARNING: using memory device/image path, this may confuse some payloads! |
| 249 | Hello, world! |
| 250 | Running on UEFI 2.7 |
| 251 | Have SMBIOS table |
| 252 | Have device tree |
| 253 | Load options: root=/dev/sdb3 init=/sbin/init rootwait ro |
| 254 | ## Application terminated, r = 0 |
| 255 | |
| 256 | The environment variable fdtcontroladdr points to U-Boot's internal device tree |
| 257 | (if available). |
| 258 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 259 | Executing the built-in self-test |
| 260 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 261 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 262 | An UEFI self-test suite can be embedded in U-Boot by building with:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 263 | |
| 264 | CONFIG_CMD_BOOTEFI_SELFTEST=y |
| 265 | |
| 266 | For testing the UEFI implementation the bootefi command can be used to start the |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 267 | self-test:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 268 | |
| 269 | bootefi selftest [fdt address] |
| 270 | |
| 271 | The environment variable 'efi_selftest' can be used to select a single test. If |
| 272 | it is not provided all tests are executed except those marked as 'on request'. |
| 273 | If the environment variable is set to 'list' a list of all tests is shown. |
| 274 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 275 | Below you can find the output of an example session:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 276 | |
| 277 | => setenv efi_selftest simple network protocol |
| 278 | => bootefi selftest |
| 279 | Testing EFI API implementation |
| 280 | Selected test: 'simple network protocol' |
| 281 | Setting up 'simple network protocol' |
| 282 | Setting up 'simple network protocol' succeeded |
| 283 | Executing 'simple network protocol' |
| 284 | DHCP Discover |
| 285 | DHCP reply received from 192.168.76.2 (52:55:c0:a8:4c:02) |
| 286 | as broadcast message. |
| 287 | Executing 'simple network protocol' succeeded |
| 288 | Tearing down 'simple network protocol' |
| 289 | Tearing down 'simple network protocol' succeeded |
| 290 | Boot services terminated |
| 291 | Summary: 0 failures |
| 292 | Preparing for reset. Press any key. |
| 293 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 294 | The UEFI life cycle |
| 295 | ------------------- |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 296 | |
| 297 | After the U-Boot platform has been initialized the UEFI API provides two kinds |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 298 | of services: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 299 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 300 | * boot services |
| 301 | * runtime services |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 302 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 303 | The API can be extended by loading UEFI drivers which come in two variants: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 304 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 305 | * boot drivers |
| 306 | * runtime drivers |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 307 | |
| 308 | UEFI drivers are installed with U-Boot's bootefi command. With the same command |
| 309 | UEFI applications can be executed. |
| 310 | |
| 311 | Loaded images of UEFI drivers stay in memory after returning to U-Boot while |
| 312 | loaded images of applications are removed from memory. |
| 313 | |
| 314 | An UEFI application (e.g. an operating system) that wants to take full control |
| 315 | of the system calls ExitBootServices. After a UEFI application calls |
| 316 | ExitBootServices |
| 317 | |
| 318 | * boot services are not available anymore |
| 319 | * timer events are stopped |
| 320 | * the memory used by U-Boot except for runtime services is released |
| 321 | * the memory used by boot time drivers is released |
| 322 | |
| 323 | So this is a point of no return. Afterwards the UEFI application can only return |
| 324 | to U-Boot by rebooting. |
| 325 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 326 | The UEFI object model |
| 327 | --------------------- |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 328 | |
| 329 | UEFI offers a flexible and expandable object model. The objects in the UEFI API |
| 330 | are devices, drivers, and loaded images. These objects are referenced by |
| 331 | handles. |
| 332 | |
| 333 | The interfaces implemented by the objects are referred to as protocols. These |
| 334 | are identified by GUIDs. They can be installed and uninstalled by calling the |
| 335 | appropriate boot services. |
| 336 | |
| 337 | Handles are created by the InstallProtocolInterface or the |
| 338 | InstallMultipleProtocolinterfaces service if NULL is passed as handle. |
| 339 | |
| 340 | Handles are deleted when the last protocol has been removed with the |
| 341 | UninstallProtocolInterface or the UninstallMultipleProtocolInterfaces service. |
| 342 | |
| 343 | Devices offer the EFI_DEVICE_PATH_PROTOCOL. A device path is the concatenation |
| 344 | of device nodes. By their device paths all devices of a system are arranged in a |
| 345 | tree. |
| 346 | |
| 347 | Drivers offer the EFI_DRIVER_BINDING_PROTOCOL. This protocol is used to connect |
| 348 | a driver to devices (which are referenced as controllers in this context). |
| 349 | |
| 350 | Loaded images offer the EFI_LOADED_IMAGE_PROTOCOL. This protocol provides meta |
| 351 | information about the image and a pointer to the unload callback function. |
| 352 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 353 | The UEFI events |
| 354 | --------------- |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 355 | |
| 356 | In the UEFI terminology an event is a data object referencing a notification |
| 357 | function which is queued for calling when the event is signaled. The following |
| 358 | types of events exist: |
| 359 | |
| 360 | * periodic and single shot timer events |
| 361 | * exit boot services events, triggered by calling the ExitBootServices() service |
| 362 | * virtual address change events |
| 363 | * memory map change events |
| 364 | * read to boot events |
| 365 | * reset system events |
| 366 | * system table events |
| 367 | * events that are only triggered programmatically |
| 368 | |
| 369 | Events can be created with the CreateEvent service and deleted with CloseEvent |
| 370 | service. |
| 371 | |
| 372 | Events can be assigned to an event group. If any of the events in a group is |
| 373 | signaled, all other events in the group are also set to the signaled state. |
| 374 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 375 | The UEFI driver model |
| 376 | --------------------- |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 377 | |
| 378 | A driver is specific for a single protocol installed on a device. To install a |
| 379 | driver on a device the ConnectController service is called. In this context |
| 380 | controller refers to the device for which the driver is installed. |
| 381 | |
| 382 | The relevant drivers are identified using the EFI_DRIVER_BINDING_PROTOCOL. This |
| 383 | protocol has has three functions: |
| 384 | |
| 385 | * supported - determines if the driver is compatible with the device |
| 386 | * start - installs the driver by opening the relevant protocol with |
| 387 | attribute EFI_OPEN_PROTOCOL_BY_DRIVER |
| 388 | * stop - uninstalls the driver |
| 389 | |
| 390 | The driver may create child controllers (child devices). E.g. a driver for block |
| 391 | IO devices will create the device handles for the partitions. The child |
| 392 | controllers will open the supported protocol with the attribute |
| 393 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER. |
| 394 | |
| 395 | A driver can be detached from a device using the DisconnectController service. |
| 396 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 397 | U-Boot devices mapped as UEFI devices |
| 398 | ------------------------------------- |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 399 | |
| 400 | Some of the U-Boot devices are mapped as UEFI devices |
| 401 | |
| 402 | * block IO devices |
| 403 | * console |
| 404 | * graphical output |
| 405 | * network adapter |
| 406 | |
| 407 | As of U-Boot 2018.03 the logic for doing this is hard coded. |
| 408 | |
| 409 | The development target is to integrate the setup of these UEFI devices with the |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 410 | U-Boot driver model [5]. So when a U-Boot device is discovered a handle should |
| 411 | be created and the device path protocol and the relevant IO protocol should be |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 412 | installed. The UEFI driver then would be attached by calling ConnectController. |
| 413 | When a U-Boot device is removed DisconnectController should be called. |
| 414 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 415 | UEFI devices mapped as U-Boot devices |
| 416 | ------------------------------------- |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 417 | |
| 418 | UEFI drivers binaries and applications may create new (virtual) devices, install |
| 419 | a protocol and call the ConnectController service. Now the matching UEFI driver |
| 420 | is determined by iterating over the implementations of the |
| 421 | EFI_DRIVER_BINDING_PROTOCOL. |
| 422 | |
| 423 | It is the task of the UEFI driver to create a corresponding U-Boot device and to |
| 424 | proxy calls for this U-Boot device to the controller. |
| 425 | |
| 426 | In U-Boot 2018.03 this has only been implemented for block IO devices. |
| 427 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 428 | UEFI uclass |
| 429 | ~~~~~~~~~~~ |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 430 | |
| 431 | An UEFI uclass driver (lib/efi_driver/efi_uclass.c) has been created that |
| 432 | takes care of initializing the UEFI drivers and providing the |
| 433 | EFI_DRIVER_BINDING_PROTOCOL implementation for the UEFI drivers. |
| 434 | |
| 435 | A linker created list is used to keep track of the UEFI drivers. To create an |
| 436 | entry in the list the UEFI driver uses the U_BOOT_DRIVER macro specifying |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 437 | UCLASS_EFI as the ID of its uclass, e.g:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 438 | |
| 439 | /* Identify as UEFI driver */ |
| 440 | U_BOOT_DRIVER(efi_block) = { |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 441 | .name = "EFI block driver", |
| 442 | .id = UCLASS_EFI, |
| 443 | .ops = &driver_ops, |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 444 | }; |
| 445 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 446 | The available operations are defined via the structure struct efi_driver_ops:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 447 | |
| 448 | struct efi_driver_ops { |
| 449 | const efi_guid_t *protocol; |
| 450 | const efi_guid_t *child_protocol; |
| 451 | int (*bind)(efi_handle_t handle, void *interface); |
| 452 | }; |
| 453 | |
| 454 | When the supported() function of the EFI_DRIVER_BINDING_PROTOCOL is called the |
| 455 | uclass checks if the protocol GUID matches the protocol GUID of the UEFI driver. |
| 456 | In the start() function the bind() function of the UEFI driver is called after |
| 457 | checking the GUID. |
| 458 | The stop() function of the EFI_DRIVER_BINDING_PROTOCOL disconnects the child |
| 459 | controllers created by the UEFI driver and the UEFI driver. (In U-Boot v2013.03 |
| 460 | this is not yet completely implemented.) |
| 461 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 462 | UEFI block IO driver |
| 463 | ~~~~~~~~~~~~~~~~~~~~ |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 464 | |
| 465 | The UEFI block IO driver supports devices exposing the EFI_BLOCK_IO_PROTOCOL. |
| 466 | |
| 467 | When connected it creates a new U-Boot block IO device with interface type |
| 468 | IF_TYPE_EFI, adds child controllers mapping the partitions, and installs the |
| 469 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL on these. This can be used together with the |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 470 | software iPXE to boot from iSCSI network drives [4]. |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 471 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 472 | This driver is only available if U-Boot is configured with:: |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 473 | |
| 474 | CONFIG_BLK=y |
| 475 | CONFIG_PARTITIONS=y |
| 476 | |
Heinrich Schuchardt | 71a7de4 | 2020-02-22 07:47:20 +0100 | [diff] [blame] | 477 | Miscellaneous |
| 478 | ------------- |
| 479 | |
| 480 | Load file 2 protocol |
| 481 | ~~~~~~~~~~~~~~~~~~~~ |
| 482 | |
| 483 | The load file 2 protocol can be used by the Linux kernel to load the initial |
| 484 | RAM disk. U-Boot can be configured to provide an implementation with:: |
| 485 | |
| 486 | EFI_LOAD_FILE2_INITRD=y |
| 487 | EFI_INITRD_FILESPEC=interface dev:part path_to_initrd |
| 488 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 489 | Links |
| 490 | ----- |
Heinrich Schuchardt | 1914e5b | 2018-03-02 19:58:50 +0100 | [diff] [blame] | 491 | |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 492 | * [1] http://uefi.org/specifications - UEFI specifications |
| 493 | * [2] https://github.com/ARM-software/ebbr/releases/download/v1.0/ebbr-v1.0.pdf - |
Heinrich Schuchardt | dc6f3f4 | 2019-04-10 08:04:38 +0200 | [diff] [blame] | 494 | Embedded Base Boot Requirements (EBBR) Specification - Release v1.0 |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 495 | * [3] https://developer.arm.com/docs/den0044/latest/server-base-boot-requirements-system-software-on-arm-platforms-version-11 - |
Heinrich Schuchardt | 9ba712d | 2019-03-28 08:09:16 +0100 | [diff] [blame] | 496 | Server Base Boot Requirements System Software on ARM Platforms - Version 1.1 |
Heinrich Schuchardt | 73d95c2 | 2019-07-26 06:46:08 +0200 | [diff] [blame] | 497 | * [4] :doc:`iscsi` |
| 498 | * [5] :doc:`../driver-model/index` |