]> Git Repo - u-boot.git/blob - doc/develop/uefi/uefi.rst
efi_loader: Rename and move CMD_BOOTEFI_HELLO_COMPILE
[u-boot.git] / doc / develop / uefi / uefi.rst
1 .. SPDX-License-Identifier: GPL-2.0+
2 .. Copyright (c) 2018 Heinrich Schuchardt
3
4 UEFI on U-Boot
5 ==============
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
13 Development target
14 ------------------
15
16 The implementation of UEFI in U-Boot strives to reach the requirements described
17 in the "Embedded Base Boot Requirements (EBBR) Specification - Release v2.1.0"
18 [2]. The "Server Base Boot Requirements System Software on ARM Platforms" [3]
19 describes a superset of the EBBR specification and may be used as further
20 reference.
21
22 A full blown UEFI implementation would contradict the U-Boot design principle
23 "keep it small".
24
25 Building U-Boot for UEFI
26 ------------------------
27
28 The UEFI standard supports only little-endian systems. The UEFI support can be
29 activated for ARM and x86 by specifying::
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
37 loaded UEFI application [4], requires::
38
39     CONFIG_BLK=y
40     CONFIG_PARTITIONS=y
41
42 Executing a UEFI binary
43 ~~~~~~~~~~~~~~~~~~~~~~~
44
45 The bootefi command is used to start UEFI applications or to install UEFI
46 drivers. It takes two parameters::
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
53 Below you find the output of an example session starting GRUB::
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
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.
66
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 in :doc:`../../usage/fit/uefi`.
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:`../../usage/fit/howto` for an introduction to FIT images.
100
101 Configuring UEFI secure boot
102 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103
104 The UEFI specification[1] defines a secure way of executing UEFI images
105 by verifying a signature (or message digest) of image with certificates.
106 This feature on U-Boot is enabled with::
107
108     CONFIG_EFI_SECURE_BOOT=y
109
110 To make the boot sequence safe, you need to establish a chain of trust;
111 In UEFI secure boot the chain trust is defined by the following UEFI variables
112
113 * PK - Platform Key
114 * KEK - Key Exchange Keys
115 * db - white list database
116 * dbx - black list database
117
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.):
123
124 Install the required tools on your host
125
126 * openssl
127 * efitools
128 * sbsigntool
129
130 Create signing keys and the key database on your host:
131
132 The platform key
133
134 .. code-block:: bash
135
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
141
142 The key exchange keys
143
144 .. code-block:: bash
145
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
151
152 The whitelist database
153
154 .. code-block:: bash
155
156     openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=TEST_db/ \
157             -keyout db.key -out db.crt -nodes -days 365
158     cert-to-efi-sig-list -g 11111111-2222-3333-4444-123456789abc \
159             db.crt db.esl
160     sign-efi-sig-list -c KEK.crt -k KEK.key db db.esl db.auth
161
162 Copy the \*.auth files to media, say mmc, that is accessible from U-Boot.
163
164 Sign an image with one of the keys in "db" on your host
165
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
173     setenv -e -nv -bs -rt -at -i <tmpaddr>:$filesize PK
174     fatload mmc 0:1 <tmpaddr> KEK.auth
175     setenv -e -nv -bs -rt -at -i <tmpaddr>:$filesize KEK
176     fatload mmc 0:1 <tmpaddr> db.auth
177     setenv -e -nv -bs -rt -at -i <tmpaddr>:$filesize db
178
179 Set up boot parameters on your board::
180
181     efidebug boot add -b 1 HELLO mmc 0:1 /helloworld.efi.signed ""
182
183 Since kernel 5.7 there's an alternative way of loading an initrd using
184 LoadFile2 protocol if CONFIG_EFI_LOAD_FILE2_INITRD is enabled.
185 The initrd path can be specified with::
186
187     efidebug boot add -b ABE0 'kernel' mmc 0:1 Image -i mmc 0:1 initrd
188
189 Now your board can run the signed image via the boot manager (see below).
190 You can also try this sequence by running Pytest, test_efi_secboot,
191 on the sandbox
192
193 .. code-block:: bash
194
195     cd <U-Boot source directory>
196     pytest test/py/tests/test_efi_secboot/test_signed.py --bd sandbox
197
198 UEFI binaries may be signed by Microsoft using the following certificates:
199
200 * KEK: Microsoft Corporation KEK CA 2011
201   http://go.microsoft.com/fwlink/?LinkId=321185.
202 * db: Microsoft Windows Production PCA 2011
203   http://go.microsoft.com/fwlink/p/?linkid=321192.
204 * db: Microsoft Corporation UEFI CA 2011
205   http://go.microsoft.com/fwlink/p/?linkid=321194.
206
207 Using OP-TEE for EFI variables
208 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
209
210 Instead of implementing UEFI variable services inside U-Boot they can
211 also be provided in the secure world by a module for OP-TEE[1]. The
212 interface between U-Boot and OP-TEE for variable services is enabled by
213 CONFIG_EFI_MM_COMM_TEE=y.
214
215 Tianocore EDK II's standalone management mode driver for variables can
216 be linked to OP-TEE for this purpose. This module uses the Replay
217 Protected Memory Block (RPMB) of an eMMC device for persisting
218 non-volatile variables. When calling the variable services via the
219 OP-TEE API U-Boot's OP-TEE supplicant relays calls to the RPMB driver
220 which has to be enabled via CONFIG_SUPPORT_EMMC_RPMB=y.
221
222 EDK2 Build instructions
223 ***********************
224
225 .. code-block:: bash
226
227     $ git clone https://github.com/tianocore/edk2.git
228     $ git clone https://github.com/tianocore/edk2-platforms.git
229     $ cd edk2
230     $ git submodule init && git submodule update --init --recursive
231     $ cd ..
232     $ export WORKSPACE=$(pwd)
233     $ export PACKAGES_PATH=$WORKSPACE/edk2:$WORKSPACE/edk2-platforms
234     $ export ACTIVE_PLATFORM="Platform/StandaloneMm/PlatformStandaloneMmPkg/PlatformStandaloneMmRpmb.dsc"
235     $ export GCC5_AARCH64_PREFIX=aarch64-linux-gnu-
236     $ source edk2/edksetup.sh
237     $ make -C edk2/BaseTools
238     $ build -p $ACTIVE_PLATFORM -b RELEASE -a AARCH64 -t GCC5 -n `nproc`
239
240 OP-TEE Build instructions
241 *************************
242
243 .. code-block:: bash
244
245     $ git clone https://github.com/OP-TEE/optee_os.git
246     $ cd optee_os
247     $ ln -s ../Build/MmStandaloneRpmb/RELEASE_GCC5/FV/BL32_AP_MM.fd
248     $ export ARCH=arm
249     $ CROSS_COMPILE32=arm-linux-gnueabihf- make -j32 CFG_ARM64_core=y \
250         PLATFORM=<myboard> CFG_STMM_PATH=BL32_AP_MM.fd CFG_RPMB_FS=y \
251         CFG_RPMB_FS_DEV_ID=0 CFG_CORE_HEAP_SIZE=524288 CFG_RPMB_WRITE_KEY=y \
252         CFG_CORE_DYN_SHM=y CFG_RPMB_TESTKEY=y CFG_REE_FS=n \
253         CFG_CORE_ARM64_PA_BITS=48 CFG_TEE_CORE_LOG_LEVEL=1 \
254         CFG_TEE_TA_LOG_LEVEL=1 CFG_SCTLR_ALIGNMENT_CHECK=n
255
256 U-Boot Build instructions
257 *************************
258
259 Although the StandAloneMM binary comes from EDK2, using and storing the
260 variables is currently available in U-Boot only.
261
262 .. code-block:: bash
263
264     $ git clone https://github.com/u-boot/u-boot.git
265     $ cd u-boot
266     $ export CROSS_COMPILE=aarch64-linux-gnu-
267     $ export ARCH=<arch>
268     $ make <myboard>_defconfig
269     $ make menuconfig
270
271 Enable ``CONFIG_OPTEE``, ``CONFIG_CMD_OPTEE_RPMB`` and ``CONFIG_EFI_MM_COMM_TEE``
272
273 .. warning::
274
275     - Your OP-TEE platform port must support Dynamic shared memory, since that's
276       the only kind of memory U-Boot supports for now.
277
278 [1] https://optee.readthedocs.io/en/latest/building/efi_vars/stmm.html
279
280 .. _uefi_capsule_update_ref:
281
282 Enabling UEFI Capsule Update feature
283 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284
285 Support has been added for the UEFI capsule update feature which
286 enables updating the U-Boot image using the UEFI firmware management
287 protocol (FMP). The capsules are not passed to the firmware through
288 the UpdateCapsule runtime service. Instead, capsule-on-disk
289 functionality is used for fetching capsules from the EFI System
290 Partition (ESP) by placing capsule files under the directory::
291
292     \EFI\UpdateCapsule
293
294 The directory is checked for capsules only within the
295 EFI system partition on the device specified in the active boot option,
296 which is determined by BootXXXX variable in BootNext, or if not, the highest
297 priority one within BootOrder. Any BootXXXX variables referring to devices
298 not present are ignored when determining the active boot option.
299
300 Please note that capsules will be applied in the alphabetic order of
301 capsule file names.
302
303 Creating a capsule file
304 ***********************
305
306 A capsule file can be created by using tools/mkeficapsule.
307 To build this tool, enable::
308
309     CONFIG_TOOLS_MKEFICAPSULE=y
310     CONFIG_TOOLS_LIBCRYPTO=y
311
312 Run the following command
313
314 .. code-block:: console
315
316     $ mkeficapsule \
317       --index <index> --instance 0 \
318       --guid <image GUID> \
319       <capsule_file_name>
320
321 Capsule with firmware version
322 *****************************
323
324 The UEFI specification does not define the firmware versioning mechanism.
325 EDK II reference implementation inserts the FMP Payload Header right before
326 the payload. It coutains the fw_version and lowest supported version,
327 EDK II reference implementation uses these information to implement the
328 firmware versioning and anti-rollback protection, the firmware version and
329 lowest supported version is stored into EFI non-volatile variable.
330
331 In U-Boot, the firmware versioning is implemented utilizing
332 the FMP Payload Header same as EDK II reference implementation,
333 reads the FMP Payload Header and stores the firmware version into
334 "FmpStateXXXX" EFI non-volatile variable. XXXX indicates the image index,
335 since FMP protocol handles multiple image indexes.
336
337 To add the fw_version into the FMP Payload Header,
338 add --fw-version option in mkeficapsule tool.
339
340 .. code-block:: console
341
342     $ mkeficapsule \
343       --index <index> --instance 0 \
344       --guid <image GUID> \
345       --fw-version 5 \
346       <capsule_file_name>
347
348 If the --fw-version option is not set, FMP Payload Header is not inserted
349 and fw_version is set as 0.
350
351 Capsule Generation through binman
352 *********************************
353
354 Support has also been added to generate capsules during U-Boot build
355 through binman. This requires the platform's DTB to be populated with
356 the capsule entry nodes for binman. The capsules then can be generated
357 by specifying the capsule parameters as properties in the capsule
358 entry node.
359
360 Check the test/py/tests/test_efi_capsule/capsule_gen_binman.dts file
361 as reference for how a typical binman node for capsule generation
362 looks like. For generating capsules as part of the platform's build, a
363 capsule node would then have to be included into the platform's
364 devicetree.
365
366 A typical binman node for generating a capsule would look like::
367
368         capsule {
369                 filename = "u-boot.capsule";
370                 efi-capsule {
371                         image-index = <0x1>;
372                         image-guid = "09d7cf52-0720-4710-91d1-08469b7fe9c8";
373
374                         u-boot {
375                         };
376                 };
377         };
378
379 In the above example, a capsule file named u-boot.capsule will be
380 generated with u-boot.bin as it's input payload. The capsule
381 generation parameters like image-index and image-guid are being
382 specified as properties. Similarly, other properties like the private
383 and public key certificate can be specified for generating signed
384 capsules. Refer :ref:`etype_efi_capsule` for documentation about the
385 efi-capsule binman entry type, which describes all the properties that
386 can be specified.
387
388 Dumping capsule headers
389 ***********************
390
391 The mkeficapsule tool also provides a command-line option to dump the
392 contents of the capsule header. This is a useful functionality when
393 trying to understand the structure of a capsule and is also used in
394 capsule verification. This feature is used in testing the capsule
395 contents in binman's test framework.
396
397 To check the contents of the capsule headers, the mkeficapsule command
398 can be used.
399
400 .. code-block:: console
401
402     $ mkeficapsule --dump-capsule \
403       <capsule_file_name>
404
405 Performing the update
406 *********************
407
408 Put capsule files under the directory mentioned above.
409 Then, following the UEFI specification, you'll need to set
410 the EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED
411 bit in OsIndications variable with
412
413 .. code-block:: console
414
415     => setenv -e -nv -bs -rt -v OsIndications =0x0000000000000004
416
417 Since U-Boot doesn't currently support SetVariable at runtime, its value
418 won't be taken over across the reboot. If this is the case, you can skip
419 this feature check with the Kconfig option (CONFIG_EFI_IGNORE_OSINDICATIONS)
420 set.
421
422 A few values need to be defined in the board file for performing the
423 capsule update. These values are defined in the board file by
424 initialisation of a structure which provides information needed for
425 capsule updates. The following structures have been defined for
426 containing the image related information
427
428 .. code-block:: c
429
430         struct efi_fw_image {
431                 efi_guid_t image_type_id;
432                 u16 *fw_name;
433                 u8 image_index;
434         };
435
436         struct efi_capsule_update_info {
437                 const char *dfu_string;
438                 struct efi_fw_image *images;
439         };
440
441
442 A string is defined which is to be used for populating the
443 dfu_alt_info variable. This string is used by the function
444 set_dfu_alt_info. Instead of taking the variable from the environment,
445 the capsule update feature requires that the variable be set through
446 the function, since that is more robust. Allowing the user to change
447 the location of the firmware updates is not a very secure
448 practice. Getting this information from the firmware itself is more
449 secure, assuming the firmware has been verified by a previous stage
450 boot loader.
451
452 Dynamic Firmware Update GUIDs
453 *****************************
454
455 The image_type_id contains a GUID value which is specific to the image
456 and board being updated, that is to say it should uniquely identify the
457 board model (and revision if relevant) and image pair. Traditionally,
458 these GUIDs are generated manually and hardcoded on a per-board basis,
459 however this scheme makes it difficult to scale up to support many
460 boards.
461
462 To address this, v5 GUIDs can be used to generate board-specific GUIDs
463 at runtime, based on the board's devicetree root compatible
464 (e.g. "qcom,qrb5165-rb5").
465
466 These strings are combined with the fw_image name to generate GUIDs for
467 each image. Support for dynamic UUIDs can be enabled by generating a new
468 namespace UUID and setting EFI_CAPSULE_NAMESPACE_GUID to it. Dynamic GUID
469 generation is only enabled if the image_type_id property is unset for your
470 firmware images, this is to avoid breaking existing boards with hardcoded
471 GUIDs.
472
473 The mkeficapsule tool can be used to determine the GUIDs for a particular
474 board and image. It can be found in the tools directory.
475
476 Firmware update images
477 **********************
478
479 The firmware images structure defines the GUID values, image index
480 values and the name of the images that are to be updated through
481 the capsule update feature. These values are to be defined as part of
482 an array. These GUID values would be used by the Firmware Management
483 Protocol(FMP) to populate the image descriptor array and also
484 displayed as part of the ESRT table. The image index values defined in
485 the array should be one greater than the dfu alt number that
486 corresponds to the firmware image. So, if the dfu alt number for an
487 image is 2, the value of image index in the fw_images array for that
488 image should be 3. The dfu alt number can be obtained by running the
489 following command::
490
491     dfu list
492
493 When the FWU Multi Bank Update feature is enabled on the platform, the
494 image index is used only to identify the image index with the image
495 GUID. The image index would not correspond to the dfu alt number. This
496 is because the FWU feature supports multiple partitions(banks) of
497 updatable images, and the actual dfu alt number to which the image is
498 to be written to is determined at runtime, based on the value of the
499 update bank to which the image is to be written. For more information
500 on the FWU Multi Bank Update feature, please refer to
501 :doc:`/develop/uefi/fwu_updates`.
502
503 When using the FMP for FIT images, the image index value needs to be
504 set to 1.
505
506 Finally, the capsule update can be initiated by rebooting the board.
507
508 An example of setting the values in the struct efi_fw_image and
509 struct efi_capsule_update_info is shown below
510
511 .. code-block:: c
512
513         struct efi_fw_image fw_images[] = {
514                 {
515                         .image_type_id = DEVELOPERBOX_UBOOT_IMAGE_GUID,
516                         .fw_name = u"DEVELOPERBOX-UBOOT",
517                         .image_index = 1,
518                 },
519                 {
520                         .image_type_id = DEVELOPERBOX_FIP_IMAGE_GUID,
521                         .fw_name = u"DEVELOPERBOX-FIP",
522                         .image_index = 2,
523                 },
524                 {
525                         .image_type_id = DEVELOPERBOX_OPTEE_IMAGE_GUID,
526                         .fw_name = u"DEVELOPERBOX-OPTEE",
527                         .image_index = 3,
528                 },
529         };
530
531         struct efi_capsule_update_info update_info = {
532                 .dfu_string = "mtd nor1=u-boot.bin raw 200000 100000;"
533                                 "fip.bin raw 180000 78000;"
534                                 "optee.bin raw 500000 100000",
535                 .images = fw_images,
536         };
537
538 Platforms must declare a variable update_info of type struct
539 efi_capsule_update_info as shown in the example above. The platform
540 will also define a fw_images array which contains information of all
541 the firmware images that are to be updated through capsule update
542 mechanism. The dfu_string is the string that is to be set as
543 dfu_alt_info. In the example above, the image index to be set for
544 u-boot.bin binary is 0x1, for fip.bin is 0x2 and for optee.bin is 0x3.
545
546 As an example, for generating the capsule for the optee.bin image, the
547 following command can be issued
548
549 .. code-block:: bash
550
551     $ ./tools/mkeficapsule \
552       --index 0x3 --instance 0 \
553       --guid c1b629f1-ce0e-4894-82bf-f0a38387e630 \
554       optee.bin optee.capsule
555
556
557 Enabling Capsule Authentication
558 *******************************
559
560 The UEFI specification defines a way of authenticating the capsule to
561 be updated by verifying the capsule signature. The capsule signature
562 is computed and prepended to the capsule payload at the time of
563 capsule generation. This signature is then verified by using the
564 public key stored as part of the X509 certificate. This certificate is
565 in the form of an efi signature list (esl) file, which is embedded in
566 a device tree.
567
568 The capsule authentication feature can be enabled through the
569 following config, in addition to the configs listed above for capsule
570 update::
571
572     CONFIG_EFI_CAPSULE_AUTHENTICATE=y
573
574 The public and private keys used for the signing process are generated
575 and used by the steps highlighted below.
576
577 1. Install utility commands on your host
578        * openssl
579        * efitools
580
581 2. Create signing keys and certificate files on your host
582
583 .. code-block:: console
584
585     $ openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=CRT/ \
586         -keyout CRT.key -out CRT.crt -nodes -days 365
587     $ cert-to-efi-sig-list CRT.crt CRT.esl
588
589 3. Run the following command to create and sign the capsule file
590
591 .. code-block:: console
592
593     $ mkeficapsule --monotonic-count 1 \
594       --private-key CRT.key \
595       --certificate CRT.crt \
596       --index 1 --instance 0 \
597       [--fit | --raw | --guid <guid-string] \
598       <image_blob> <capsule_file_name>
599
600 4. Insert the signature list into a device tree in the following format::
601
602     {
603             signature {
604                     capsule-key = [ <binary of signature list> ];
605             }
606             ...
607     }
608
609 You can perform step-4 through the Kconfig symbol
610 CONFIG_EFI_CAPSULE_CRT_FILE. This symbol points to the signing key
611 generated in step-2. As part of U-Boot build, the ESL certificate file will
612 be generated from the signing key and automatically get embedded into the
613 platform's dtb.
614
615 Anti-rollback Protection
616 ************************
617
618 Anti-rollback prevents unintentional installation of outdated firmware.
619 To enable anti-rollback, you must add the lowest-supported-version property
620 to dtb and specify --fw-version when creating a capsule file with the
621 mkeficapsule tool.
622 When executing capsule update, U-Boot checks if fw_version is greater than
623 or equal to lowest-supported-version. If fw_version is less than
624 lowest-supported-version, the update will fail.
625 For example, if lowest-supported-version is set to 7 and you run capsule
626 update using a capsule file with --fw-version of 5, the update will fail.
627 When the --fw-version in the capsule file is updated, lowest-supported-version
628 in the dtb might be updated accordingly.
629
630 If user needs to enforce anti-rollback to any older version,
631 the lowest-supported-version property in dtb must be always updated manually.
632
633 Note that the lowest-supported-version property specified in U-Boot's control
634 device tree can be changed by U-Boot fdt command.
635 Secure systems should not enable this command.
636
637 To insert the lowest supported version into a dtb
638
639 .. code-block:: console
640
641     $ dtc -@ -I dts -O dtb -o version.dtbo version.dtso
642     $ fdtoverlay -i orig.dtb -o new.dtb -v version.dtbo
643
644 where version.dtso looks like::
645
646     /dts-v1/;
647     /plugin/;
648     &{/} {
649             firmware-version {
650                     image1 {
651                             image-type-id = "09D7CF52-0720-4710-91D1-08469B7FE9C8";
652                             image-index = <1>;
653                             lowest-supported-version = <3>;
654                     };
655             };
656     };
657
658 The properties of image-type-id and image-index must match the value
659 defined in the efi_fw_image array as image_type_id and image_index.
660
661 Porting Capsule Updates to new boards
662 *************************************
663
664 It is important, when using a reference board as a starting point for a custom
665 board, that certain steps are taken to properly support Capsule Updates.
666
667 Capsule GUIDs need to be unique for each firmware and board. That is, if two
668 firmwares are built from the same source but result in different binaries
669 because they are built for different boards, they should have different GUIDs.
670 Therefore it is important when creating support for a new board, new GUIDs are
671 defined in the board's header file.  *DO NOT* reuse capsule GUIDs.
672
673 Executing the boot manager
674 ~~~~~~~~~~~~~~~~~~~~~~~~~~
675
676 The UEFI specification foresees to define boot entries and boot sequence via
677 UEFI variables. Booting according to these variables is possible via::
678
679     bootefi bootmgr [fdt address]
680
681 As of U-Boot v2020.10 UEFI variables cannot be set at runtime. The U-Boot
682 command 'efidebug' can be used to set the variables.
683
684 UEFI HTTP Boot
685 ~~~~~~~~~~~~~~
686
687 HTTP Boot provides the capability for system deployment and configuration
688 over the network. HTTP Boot can be activated by specifying::
689
690     CONFIG_EFI_HTTP_BOOT
691
692 Enabling that will automatically select::
693
694     CONFIG_CMD_DNS
695     CONFIG_CMD_WGET
696     CONFIG_BLKMAP
697
698 Set up the load option specifying the target URI::
699
700     efidebug boot add -u 1 netinst http://foo/bar
701
702 When this load option is selected as boot selection, resolve the
703 host ip address by dns, then download the file with wget.
704 If the downloaded file extension is .iso or .img file, efibootmgr tries to
705 mount the image and boot with the default file(e.g. EFI/BOOT/BOOTAA64.EFI).
706 If the downloaded file is PE-COFF image, load the downloaded file and
707 start it.
708
709 The current implementation tries to resolve the IP address as a host name.
710 If the uri is like "http://192.168.1.1/foobar",
711 the dns process tries to resolve the host "192.168.1.1" and it will
712 end up with "host not found".
713
714 We need to preset the "httpserverip" environment variable to proceed the wget::
715
716     setenv httpserverip 192.168.1.1
717
718 Executing the built in hello world application
719 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
720
721 A hello world UEFI application can be built with::
722
723     CONFIG_BOOTEFI_HELLO_COMPILE=y
724
725 It can be embedded into the U-Boot binary with::
726
727     CONFIG_CMD_BOOTEFI_HELLO=y
728
729 The bootefi command is used to start the embedded hello world application::
730
731     bootefi hello [fdt address]
732
733 Below you find the output of an example session::
734
735     => bootefi hello ${fdtcontroladdr}
736     ## Starting EFI application at 01000000 ...
737     WARNING: using memory device/image path, this may confuse some payloads!
738     Hello, world!
739     Running on UEFI 2.7
740     Have SMBIOS table
741     Have device tree
742     Load options: root=/dev/sdb3 init=/sbin/init rootwait ro
743     ## Application terminated, r = 0
744
745 The environment variable fdtcontroladdr points to U-Boot's internal device tree
746 (if available).
747
748 Executing the built-in self-test
749 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
750
751 An UEFI self-test suite can be embedded in U-Boot by building with::
752
753     CONFIG_CMD_BOOTEFI_SELFTEST=y
754
755 For testing the UEFI implementation the bootefi command can be used to start the
756 self-test::
757
758     bootefi selftest [fdt address]
759
760 The environment variable 'efi_selftest' can be used to select a single test. If
761 it is not provided all tests are executed except those marked as 'on request'.
762 If the environment variable is set to 'list' a list of all tests is shown.
763
764 Below you can find the output of an example session::
765
766     => setenv efi_selftest simple network protocol
767     => bootefi selftest
768     Testing EFI API implementation
769     Selected test: 'simple network protocol'
770     Setting up 'simple network protocol'
771     Setting up 'simple network protocol' succeeded
772     Executing 'simple network protocol'
773     DHCP Discover
774     DHCP reply received from 192.168.76.2 (52:55:c0:a8:4c:02)
775       as broadcast message.
776     Executing 'simple network protocol' succeeded
777     Tearing down 'simple network protocol'
778     Tearing down 'simple network protocol' succeeded
779     Boot services terminated
780     Summary: 0 failures
781     Preparing for reset. Press any key.
782
783 The UEFI life cycle
784 -------------------
785
786 After the U-Boot platform has been initialized the UEFI API provides two kinds
787 of services:
788
789 * boot services
790 * runtime services
791
792 The API can be extended by loading UEFI drivers which come in two variants:
793
794 * boot drivers
795 * runtime drivers
796
797 UEFI drivers are installed with U-Boot's bootefi command. With the same command
798 UEFI applications can be executed.
799
800 Loaded images of UEFI drivers stay in memory after returning to U-Boot while
801 loaded images of applications are removed from memory.
802
803 An UEFI application (e.g. an operating system) that wants to take full control
804 of the system calls ExitBootServices. After a UEFI application calls
805 ExitBootServices
806
807 * boot services are not available anymore
808 * timer events are stopped
809 * the memory used by U-Boot except for runtime services is released
810 * the memory used by boot time drivers is released
811
812 So this is a point of no return. Afterwards the UEFI application can only return
813 to U-Boot by rebooting.
814
815 The UEFI object model
816 ---------------------
817
818 UEFI offers a flexible and expandable object model. The objects in the UEFI API
819 are devices, drivers, and loaded images. These objects are referenced by
820 handles.
821
822 The interfaces implemented by the objects are referred to as protocols. These
823 are identified by GUIDs. They can be installed and uninstalled by calling the
824 appropriate boot services.
825
826 Handles are created by the InstallProtocolInterface or the
827 InstallMultipleProtocolinterfaces service if NULL is passed as handle.
828
829 Handles are deleted when the last protocol has been removed with the
830 UninstallProtocolInterface or the UninstallMultipleProtocolInterfaces service.
831
832 Devices offer the EFI_DEVICE_PATH_PROTOCOL. A device path is the concatenation
833 of device nodes. By their device paths all devices of a system are arranged in a
834 tree.
835
836 Drivers offer the EFI_DRIVER_BINDING_PROTOCOL. This protocol is used to connect
837 a driver to devices (which are referenced as controllers in this context).
838
839 Loaded images offer the EFI_LOADED_IMAGE_PROTOCOL. This protocol provides meta
840 information about the image and a pointer to the unload callback function.
841
842 The UEFI events
843 ---------------
844
845 In the UEFI terminology an event is a data object referencing a notification
846 function which is queued for calling when the event is signaled. The following
847 types of events exist:
848
849 * periodic and single shot timer events
850 * exit boot services events, triggered by calling the ExitBootServices() service
851 * virtual address change events
852 * memory map change events
853 * read to boot events
854 * reset system events
855 * system table events
856 * events that are only triggered programmatically
857
858 Events can be created with the CreateEvent service and deleted with CloseEvent
859 service.
860
861 Events can be assigned to an event group. If any of the events in a group is
862 signaled, all other events in the group are also set to the signaled state.
863
864 The UEFI driver model
865 ---------------------
866
867 A driver is specific for a single protocol installed on a device. To install a
868 driver on a device the ConnectController service is called. In this context
869 controller refers to the device for which the driver is installed.
870
871 The relevant drivers are identified using the EFI_DRIVER_BINDING_PROTOCOL. This
872 protocol has three functions:
873
874 * supported - determines if the driver is compatible with the device
875 * start - installs the driver by opening the relevant protocol with
876   attribute EFI_OPEN_PROTOCOL_BY_DRIVER
877 * stop - uninstalls the driver
878
879 The driver may create child controllers (child devices). E.g. a driver for block
880 IO devices will create the device handles for the partitions. The child
881 controllers  will open the supported protocol with the attribute
882 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
883
884 A driver can be detached from a device using the DisconnectController service.
885
886 U-Boot devices mapped as UEFI devices
887 -------------------------------------
888
889 Some of the U-Boot devices are mapped as UEFI devices
890
891 * block IO devices
892 * console
893 * graphical output
894 * network adapter
895
896 As of U-Boot 2018.03 the logic for doing this is hard coded.
897
898 The development target is to integrate the setup of these UEFI devices with the
899 U-Boot driver model [5]. So when a U-Boot device is discovered a handle should
900 be created and the device path protocol and the relevant IO protocol should be
901 installed. The UEFI driver then would be attached by calling ConnectController.
902 When a U-Boot device is removed DisconnectController should be called.
903
904 UEFI devices mapped as U-Boot devices
905 -------------------------------------
906
907 UEFI drivers binaries and applications may create new (virtual) devices, install
908 a protocol and call the ConnectController service. Now the matching UEFI driver
909 is determined by iterating over the implementations of the
910 EFI_DRIVER_BINDING_PROTOCOL.
911
912 It is the task of the UEFI driver to create a corresponding U-Boot device and to
913 proxy calls for this U-Boot device to the controller.
914
915 In U-Boot 2018.03 this has only been implemented for block IO devices.
916
917 UEFI uclass
918 ~~~~~~~~~~~
919
920 An UEFI uclass driver (lib/efi_driver/efi_uclass.c) has been created that
921 takes care of initializing the UEFI drivers and providing the
922 EFI_DRIVER_BINDING_PROTOCOL implementation for the UEFI drivers.
923
924 A linker created list is used to keep track of the UEFI drivers. To create an
925 entry in the list the UEFI driver uses the U_BOOT_DRIVER macro specifying
926 UCLASS_EFI_LOADER as the ID of its uclass, e.g::
927
928     /* Identify as UEFI driver */
929     U_BOOT_DRIVER(efi_block) = {
930         .name  = "EFI block driver",
931         .id    = UCLASS_EFI_LOADER,
932         .ops   = &driver_ops,
933     };
934
935 The available operations are defined via the structure struct efi_driver_ops::
936
937     struct efi_driver_ops {
938         const efi_guid_t *protocol;
939         const efi_guid_t *child_protocol;
940         int (*bind)(efi_handle_t handle, void *interface);
941     };
942
943 When the supported() function of the EFI_DRIVER_BINDING_PROTOCOL is called the
944 uclass checks if the protocol GUID matches the protocol GUID of the UEFI driver.
945 In the start() function the bind() function of the UEFI driver is called after
946 checking the GUID.
947 The stop() function of the EFI_DRIVER_BINDING_PROTOCOL disconnects the child
948 controllers created by the UEFI driver and the UEFI driver. (In U-Boot v2013.03
949 this is not yet completely implemented.)
950
951 UEFI block IO driver
952 ~~~~~~~~~~~~~~~~~~~~
953
954 The UEFI block IO driver supports devices exposing the EFI_BLOCK_IO_PROTOCOL.
955
956 When connected it creates a new U-Boot block IO device with interface type
957 UCLASS_EFI_LOADER, adds child controllers mapping the partitions, and installs
958 the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL on these. This can be used together with the
959 software iPXE to boot from iSCSI network drives [4].
960
961 This driver is only available if U-Boot is configured with::
962
963     CONFIG_BLK=y
964     CONFIG_PARTITIONS=y
965
966 Miscellaneous
967 -------------
968
969 Load file 2 protocol
970 ~~~~~~~~~~~~~~~~~~~~
971
972 The load file 2 protocol can be used by the Linux kernel to load the initial
973 RAM disk. U-Boot can be configured to provide an implementation with::
974
975     EFI_LOAD_FILE2_INITRD=y
976
977 When the option is enabled the user can add the initrd path with the efidebug
978 command.
979
980 Load options Boot#### have a FilePathList[] member.  The first element of
981 the array (FilePathList[0]) is the EFI binary to execute.  When an initrd
982 is specified the Device Path for the initrd is denoted by a VenMedia node
983 with the EFI_INITRD_MEDIA_GUID. Each entry of the array is terminated by the
984 'end of entire device path' subtype (0xff). If a user wants to define multiple
985 initrds, those must by separated by the 'end of this instance' identifier of
986 the end node (0x01).
987
988 So our final format of the FilePathList[] is::
989
990     Loaded image - end node (0xff) - VenMedia - initrd_1 - [end node (0x01) - initrd_n ...] - end node (0xff)
991
992 Links
993 -----
994
995 * [1] http://uefi.org/specifications - UEFI specifications
996 * [2] https://github.com/ARM-software/ebbr/releases/download/v2.1.0/ebbr-v2.1.0.pdf -
997   Embedded Base Boot Requirements (EBBR) Specification - Release v2.1.0
998 * [3] https://developer.arm.com/docs/den0044/latest/server-base-boot-requirements-system-software-on-arm-platforms-version-11 -
999   Server Base Boot Requirements System Software on ARM Platforms - Version 1.1
1000 * [4] :doc:`iscsi`
1001 * [5] :doc:`../driver-model/index`
This page took 0.081439 seconds and 4 git commands to generate.