blob: 0a2286d039d98cf7221f3d57e9cc7056fe032228 [file] [log] [blame]
Sughosh Ganuf4d15942020-12-30 19:27:12 +05301.. SPDX-License-Identifier: GPL-2.0+
2.. Copyright (C) 2020, Linaro Limited
3
4Enabling UEFI Capsule Update feature
5------------------------------------
6
7Support has been added for the UEFI capsule update feature which
8enables updating the U-Boot image using the UEFI firmware management
9protocol (fmp). The capsules are not passed to the firmware through
10the UpdateCapsule runtime service. Instead, capsule-on-disk
11functionality is used for fetching the capsule from the EFI System
12Partition (ESP) by placing the capsule file under the
13\EFI\UpdateCapsule directory.
14
15Currently, support has been added on the QEMU ARM64 virt platform for
16updating the U-Boot binary as a raw image when the platform is booted
17in non-secure mode, i.e. with CONFIG_TFABOOT disabled. For this
18configuration, the QEMU platform needs to be booted with
19'secure=off'. The U-Boot binary placed on the first bank of the NOR
20flash at offset 0x0. The U-Boot environment is placed on the second
21NOR flash bank at offset 0x4000000.
22
23The capsule update feature is enabled with the following configuration
24settings::
25
26 CONFIG_MTD=y
27 CONFIG_FLASH_CFI_MTD=y
28 CONFIG_CMD_MTDPARTS=y
29 CONFIG_CMD_DFU=y
30 CONFIG_DFU_MTD=y
31 CONFIG_PCI_INIT_R=y
32 CONFIG_EFI_CAPSULE_ON_DISK=y
33 CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT=y
34 CONFIG_EFI_CAPSULE_FIRMWARE=y
35 CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
36 CONFIG_EFI_CAPSULE_FMP_HEADER=y
37
38In addition, the following config needs to be disabled(QEMU ARM specific)::
39
40 CONFIG_TFABOOT
41
Masami Hiramatsu3f238ee2021-06-04 18:45:21 +090042The capsule file can be generated by using the tools/mkeficapsule::
Sughosh Ganuf4d15942020-12-30 19:27:12 +053043
Masami Hiramatsu3f238ee2021-06-04 18:45:21 +090044 $ mkeficapsule --raw <u-boot.bin> --index 1 <capsule_file_name>
Sughosh Ganuf4d15942020-12-30 19:27:12 +053045
46As per the UEFI specification, the capsule file needs to be placed on
47the EFI System Partition, under the \EFI\UpdateCapsule directory. The
48EFI System Partition can be a virtio-blk-device.
49
50Before initiating the firmware update, the efi variables BootNext,
51BootXXXX and OsIndications need to be set. The BootXXXX variable needs
52to be pointing to the EFI System Partition which contains the capsule
53file. The BootNext, BootXXXX and OsIndications variables can be set
54using the following commands::
55
Ilias Apalodimas773c0902021-03-17 21:55:01 +020056 => efidebug boot add -b 0 Boot0000 virtio 0:1 <capsule_file_name>
Sughosh Ganuf4d15942020-12-30 19:27:12 +053057 => efidebug boot next 0
58 => setenv -e -nv -bs -rt -v OsIndications =0x04
59 => saveenv
60
61Finally, the capsule update can be initiated with the following
62command::
63
64 => efidebug capsule disk-update
65
66The updated U-Boot image will be booted on subsequent boot.
67
68Enabling Capsule Authentication
69^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70
71The UEFI specification defines a way of authenticating the capsule to
72be updated by verifying the capsule signature. The capsule signature
73is computed and prepended to the capsule payload at the time of
74capsule generation. This signature is then verified by using the
75public key stored as part of the X509 certificate. This certificate is
76in the form of an efi signature list (esl) file, which is embedded as
77part of the platform's device tree blob using the mkeficapsule
78utility.
79
80On the QEMU virt platforms, the device-tree is generated on the fly
81based on the devices configured. This device tree is then passed on to
82the various software components booting on the platform, including
83U-Boot. Therefore, on the QEMU virt platform, the signatute is
84embedded on an overlay. This overlay is then applied at runtime to the
85base platform device-tree. Steps needed for embedding the esl file in
86the overlay are highlighted below.
87
88The capsule authentication feature can be enabled through the
89following config, in addition to the configs listed above for capsule
90update::
91
92 CONFIG_EFI_CAPSULE_AUTHENTICATE=y
93
94The public and private keys used for the signing process are generated
95and used by the steps highlighted below::
96
97 1. Install utility commands on your host
98 * OPENSSL
99 * efitools
100
101 2. Create signing keys and certificate files on your host
102
103 $ openssl req -x509 -sha256 -newkey rsa:2048 -subj /CN=CRT/ \
104 -keyout CRT.key -out CRT.crt -nodes -days 365
105 $ cert-to-efi-sig-list CRT.crt CRT.esl
106
107 $ openssl x509 -in CRT.crt -out CRT.cer -outform DER
108 $ openssl x509 -inform DER -in CRT.cer -outform PEM -out CRT.pub.pem
109
110 $ openssl pkcs12 -export -out CRT.pfx -inkey CRT.key -in CRT.crt
111 $ openssl pkcs12 -in CRT.pfx -nodes -out CRT.pem
112
113The capsule file can be generated by using the GenerateCapsule.py
114script in EDKII::
115
116 $ ./BaseTools/BinWrappers/PosixLike/GenerateCapsule -e -o \
117 <capsule_file_name> --monotonic-count <val> --fw-version \
118 <val> --lsv <val> --guid \
119 e2bb9c06-70e9-4b14-97a3-5a7913176e3f --verbose \
120 --update-image-index <val> --signer-private-cert \
121 /path/to/CRT.pem --trusted-public-cert \
122 /path/to/CRT.pub.pem --other-public-cert /path/to/CRT.pub.pem \
123 <u-boot.bin>
124
125Place the capsule generated in the above step on the EFI System
126Partition under the EFI/UpdateCapsule directory
127
128For embedding the public key certificate, the following steps need to
129be followed::
130
131 1. Generate a skeleton overlay dts file, with a single fragment
132 node and an empty __overlay__ node
133
134 A typical skeleton overlay file will look like this
135
136 /dts-v1/;
137 /plugin/;
138
139 / {
140 fragment@0 {
141 target-path = "/";
142 __overlay__ {
143 };
144 };
145 };
146
147
148 2. Convert the dts to a corresponding dtb with the following
149 command
150 ./scripts/dtc/dtc -@ -I dts -O dtb -o <ov_dtb_file_name> \
151 <dts_file>
152
153 3. Run the dtb file generated above through the mkeficapsule tool
154 in U-Boot
155 ./tools/mkeficapsule -O <pub_key.esl> -D <ov_dtb>
156
157Running the above command results in the creation of a 'signature'
158node in the dtb, under which the public key is stored as a
159'capsule-key' property. The '-O' option is to be used since the
160public key certificate(esl) file is being embedded in an overlay.
161
162The dtb file embedded with the certificate is now to be placed on an
163EFI System Partition. This would then be loaded and "merged" with the
164base platform flattened device-tree(dtb) at runtime.
165
166Build U-Boot with the following steps(QEMU ARM64)::
167
168 $ make qemu_arm64_defconfig
169 $ make menuconfig
170 Disable CONFIG_TFABOOT
171 Enable CONFIG_EFI_CAPSULE_AUTHENTICATE
172 Enable all configs needed for capsule update(listed above)
173 $ make all
174
175Boot the platform and perform the following steps on the U-Boot
176command line::
177
178 1. Enable capsule authentication by setting the following env
179 variable
180
181 => setenv capsule_authentication_enabled 1
182 => saveenv
183
184 2. Load the overlay dtb to memory and merge it with the base fdt
185
186 => fatload virtio 0:1 <$fdtovaddr> EFI/<ov_dtb_file>
187 => fdt addr $fdtcontroladdr
188 => fdt resize <size_of_ov_dtb_file>
189 => fdt apply <$fdtovaddr>
190
191 3. Set the following environment and UEFI boot variables
192
193 => setenv -e -nv -bs -rt -v OsIndications =0x04
Ilias Apalodimas773c0902021-03-17 21:55:01 +0200194 => efidebug boot add -b 0 Boot0000 virtio 0:1 <capsule_file_name>
Sughosh Ganuf4d15942020-12-30 19:27:12 +0530195 => efidebug boot next 0
196 => saveenv
197
198 4. Finally, the capsule update can be initiated with the following
199 command
200
201 => efidebug capsule disk-update
202
203On subsequent reboot, the platform should boot the updated U-Boot binary.