blob: db942df694f9575e6c970dd8497c04d3fe34eb77 [file] [log] [blame]
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +02001.. SPDX-License-Identifier: GPL-2.0+
2.. Copyright (c) 2018 Heinrich Schuchardt
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +01003
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +02004UEFI on U-Boot
5==============
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +01006
7The Unified Extensible Firmware Interface Specification (UEFI) [1] has become
8the default for booting on AArch64 and x86 systems. It provides a stable API for
9the interaction of drivers and applications with the firmware. The API comprises
10access to block storage, network, and console to name a few. The Linux kernel
11and boot loaders like GRUB or the FreeBSD loader can be executed.
12
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020013Development target
14------------------
Heinrich Schuchardt9ba712d2019-03-28 08:09:16 +010015
Heinrich Schuchardtdc6f3f42019-04-10 08:04:38 +020016The implementation of UEFI in U-Boot strives to reach the requirements described
17in the "Embedded Base Boot Requirements (EBBR) Specification - Release v1.0"
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020018[2]. The "Server Base Boot Requirements System Software on ARM Platforms" [3]
Heinrich Schuchardtdc6f3f42019-04-10 08:04:38 +020019describes a superset of the EBBR specification and may be used as further
20reference.
Heinrich Schuchardt9ba712d2019-03-28 08:09:16 +010021
22A full blown UEFI implementation would contradict the U-Boot design principle
23"keep it small".
24
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020025Building U-Boot for UEFI
26------------------------
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010027
Heinrich Schuchardt4f3cb4d2018-12-30 12:54:36 +010028The UEFI standard supports only little-endian systems. The UEFI support can be
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020029activated for ARM and x86 by specifying::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010030
31 CONFIG_CMD_BOOTEFI=y
32 CONFIG_EFI_LOADER=y
33
34in the .config file.
35
36Support for attaching virtual block devices, e.g. iSCSI drives connected by the
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020037loaded UEFI application [4], requires::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010038
39 CONFIG_BLK=y
40 CONFIG_PARTITIONS=y
41
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020042Executing a UEFI binary
43~~~~~~~~~~~~~~~~~~~~~~~
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010044
45The bootefi command is used to start UEFI applications or to install UEFI
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020046drivers. It takes two parameters::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010047
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 Schuchardt73d95c22019-07-26 06:46:08 +020053Below you find the output of an example session starting GRUB::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010054
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
62The environment variable 'bootargs' is passed as load options in the UEFI system
63table. The Linux kernel EFI stub uses the load options as command line
64arguments.
65
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020066Executing the boot manager
67~~~~~~~~~~~~~~~~~~~~~~~~~~
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010068
Heinrich Schuchardt4f3cb4d2018-12-30 12:54:36 +010069The UEFI specification foresees to define boot entries and boot sequence via UEFI
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020070variables. Booting according to these variables is possible via::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010071
72 bootefi bootmgr [fdt address]
73
74As of U-Boot v2018.03 UEFI variables are not persisted and cannot be set at
75runtime.
76
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020077Executing the built in hello world application
78~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010079
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020080A hello world UEFI application can be built with::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010081
82 CONFIG_CMD_BOOTEFI_HELLO_COMPILE=y
83
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020084It can be embedded into the U-Boot binary with::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010085
86 CONFIG_CMD_BOOTEFI_HELLO=y
87
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020088The bootefi command is used to start the embedded hello world application::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010089
90 bootefi hello [fdt address]
91
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +020092Below you find the output of an example session::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +010093
94 => bootefi hello ${fdtcontroladdr}
95 ## Starting EFI application at 01000000 ...
96 WARNING: using memory device/image path, this may confuse some payloads!
97 Hello, world!
98 Running on UEFI 2.7
99 Have SMBIOS table
100 Have device tree
101 Load options: root=/dev/sdb3 init=/sbin/init rootwait ro
102 ## Application terminated, r = 0
103
104The environment variable fdtcontroladdr points to U-Boot's internal device tree
105(if available).
106
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200107Executing the built-in self-test
108~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100109
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200110An UEFI self-test suite can be embedded in U-Boot by building with::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100111
112 CONFIG_CMD_BOOTEFI_SELFTEST=y
113
114For testing the UEFI implementation the bootefi command can be used to start the
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200115self-test::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100116
117 bootefi selftest [fdt address]
118
119The environment variable 'efi_selftest' can be used to select a single test. If
120it is not provided all tests are executed except those marked as 'on request'.
121If the environment variable is set to 'list' a list of all tests is shown.
122
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200123Below you can find the output of an example session::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100124
125 => setenv efi_selftest simple network protocol
126 => bootefi selftest
127 Testing EFI API implementation
128 Selected test: 'simple network protocol'
129 Setting up 'simple network protocol'
130 Setting up 'simple network protocol' succeeded
131 Executing 'simple network protocol'
132 DHCP Discover
133 DHCP reply received from 192.168.76.2 (52:55:c0:a8:4c:02)
134 as broadcast message.
135 Executing 'simple network protocol' succeeded
136 Tearing down 'simple network protocol'
137 Tearing down 'simple network protocol' succeeded
138 Boot services terminated
139 Summary: 0 failures
140 Preparing for reset. Press any key.
141
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200142The UEFI life cycle
143-------------------
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100144
145After the U-Boot platform has been initialized the UEFI API provides two kinds
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200146of services:
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100147
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200148* boot services
149* runtime services
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100150
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200151The API can be extended by loading UEFI drivers which come in two variants:
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100152
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200153* boot drivers
154* runtime drivers
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100155
156UEFI drivers are installed with U-Boot's bootefi command. With the same command
157UEFI applications can be executed.
158
159Loaded images of UEFI drivers stay in memory after returning to U-Boot while
160loaded images of applications are removed from memory.
161
162An UEFI application (e.g. an operating system) that wants to take full control
163of the system calls ExitBootServices. After a UEFI application calls
164ExitBootServices
165
166* boot services are not available anymore
167* timer events are stopped
168* the memory used by U-Boot except for runtime services is released
169* the memory used by boot time drivers is released
170
171So this is a point of no return. Afterwards the UEFI application can only return
172to U-Boot by rebooting.
173
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200174The UEFI object model
175---------------------
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100176
177UEFI offers a flexible and expandable object model. The objects in the UEFI API
178are devices, drivers, and loaded images. These objects are referenced by
179handles.
180
181The interfaces implemented by the objects are referred to as protocols. These
182are identified by GUIDs. They can be installed and uninstalled by calling the
183appropriate boot services.
184
185Handles are created by the InstallProtocolInterface or the
186InstallMultipleProtocolinterfaces service if NULL is passed as handle.
187
188Handles are deleted when the last protocol has been removed with the
189UninstallProtocolInterface or the UninstallMultipleProtocolInterfaces service.
190
191Devices offer the EFI_DEVICE_PATH_PROTOCOL. A device path is the concatenation
192of device nodes. By their device paths all devices of a system are arranged in a
193tree.
194
195Drivers offer the EFI_DRIVER_BINDING_PROTOCOL. This protocol is used to connect
196a driver to devices (which are referenced as controllers in this context).
197
198Loaded images offer the EFI_LOADED_IMAGE_PROTOCOL. This protocol provides meta
199information about the image and a pointer to the unload callback function.
200
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200201The UEFI events
202---------------
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100203
204In the UEFI terminology an event is a data object referencing a notification
205function which is queued for calling when the event is signaled. The following
206types of events exist:
207
208* periodic and single shot timer events
209* exit boot services events, triggered by calling the ExitBootServices() service
210* virtual address change events
211* memory map change events
212* read to boot events
213* reset system events
214* system table events
215* events that are only triggered programmatically
216
217Events can be created with the CreateEvent service and deleted with CloseEvent
218service.
219
220Events can be assigned to an event group. If any of the events in a group is
221signaled, all other events in the group are also set to the signaled state.
222
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200223The UEFI driver model
224---------------------
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100225
226A driver is specific for a single protocol installed on a device. To install a
227driver on a device the ConnectController service is called. In this context
228controller refers to the device for which the driver is installed.
229
230The relevant drivers are identified using the EFI_DRIVER_BINDING_PROTOCOL. This
231protocol has has three functions:
232
233* supported - determines if the driver is compatible with the device
234* start - installs the driver by opening the relevant protocol with
235 attribute EFI_OPEN_PROTOCOL_BY_DRIVER
236* stop - uninstalls the driver
237
238The driver may create child controllers (child devices). E.g. a driver for block
239IO devices will create the device handles for the partitions. The child
240controllers will open the supported protocol with the attribute
241EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
242
243A driver can be detached from a device using the DisconnectController service.
244
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200245U-Boot devices mapped as UEFI devices
246-------------------------------------
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100247
248Some of the U-Boot devices are mapped as UEFI devices
249
250* block IO devices
251* console
252* graphical output
253* network adapter
254
255As of U-Boot 2018.03 the logic for doing this is hard coded.
256
257The development target is to integrate the setup of these UEFI devices with the
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200258U-Boot driver model [5]. So when a U-Boot device is discovered a handle should
259be created and the device path protocol and the relevant IO protocol should be
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100260installed. The UEFI driver then would be attached by calling ConnectController.
261When a U-Boot device is removed DisconnectController should be called.
262
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200263UEFI devices mapped as U-Boot devices
264-------------------------------------
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100265
266UEFI drivers binaries and applications may create new (virtual) devices, install
267a protocol and call the ConnectController service. Now the matching UEFI driver
268is determined by iterating over the implementations of the
269EFI_DRIVER_BINDING_PROTOCOL.
270
271It is the task of the UEFI driver to create a corresponding U-Boot device and to
272proxy calls for this U-Boot device to the controller.
273
274In U-Boot 2018.03 this has only been implemented for block IO devices.
275
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200276UEFI uclass
277~~~~~~~~~~~
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100278
279An UEFI uclass driver (lib/efi_driver/efi_uclass.c) has been created that
280takes care of initializing the UEFI drivers and providing the
281EFI_DRIVER_BINDING_PROTOCOL implementation for the UEFI drivers.
282
283A linker created list is used to keep track of the UEFI drivers. To create an
284entry in the list the UEFI driver uses the U_BOOT_DRIVER macro specifying
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200285UCLASS_EFI as the ID of its uclass, e.g::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100286
287 /* Identify as UEFI driver */
288 U_BOOT_DRIVER(efi_block) = {
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200289 .name = "EFI block driver",
290 .id = UCLASS_EFI,
291 .ops = &driver_ops,
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100292 };
293
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200294The available operations are defined via the structure struct efi_driver_ops::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100295
296 struct efi_driver_ops {
297 const efi_guid_t *protocol;
298 const efi_guid_t *child_protocol;
299 int (*bind)(efi_handle_t handle, void *interface);
300 };
301
302When the supported() function of the EFI_DRIVER_BINDING_PROTOCOL is called the
303uclass checks if the protocol GUID matches the protocol GUID of the UEFI driver.
304In the start() function the bind() function of the UEFI driver is called after
305checking the GUID.
306The stop() function of the EFI_DRIVER_BINDING_PROTOCOL disconnects the child
307controllers created by the UEFI driver and the UEFI driver. (In U-Boot v2013.03
308this is not yet completely implemented.)
309
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200310UEFI block IO driver
311~~~~~~~~~~~~~~~~~~~~
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100312
313The UEFI block IO driver supports devices exposing the EFI_BLOCK_IO_PROTOCOL.
314
315When connected it creates a new U-Boot block IO device with interface type
316IF_TYPE_EFI, adds child controllers mapping the partitions, and installs the
317EFI_SIMPLE_FILE_SYSTEM_PROTOCOL on these. This can be used together with the
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200318software iPXE to boot from iSCSI network drives [4].
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100319
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200320This driver is only available if U-Boot is configured with::
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100321
322 CONFIG_BLK=y
323 CONFIG_PARTITIONS=y
324
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200325Links
326-----
Heinrich Schuchardt1914e5b2018-03-02 19:58:50 +0100327
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200328* [1] http://uefi.org/specifications - UEFI specifications
329* [2] https://github.com/ARM-software/ebbr/releases/download/v1.0/ebbr-v1.0.pdf -
Heinrich Schuchardtdc6f3f42019-04-10 08:04:38 +0200330 Embedded Base Boot Requirements (EBBR) Specification - Release v1.0
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200331* [3] https://developer.arm.com/docs/den0044/latest/server-base-boot-requirements-system-software-on-arm-platforms-version-11 -
Heinrich Schuchardt9ba712d2019-03-28 08:09:16 +0100332 Server Base Boot Requirements System Software on ARM Platforms - Version 1.1
Heinrich Schuchardt73d95c22019-07-26 06:46:08 +0200333* [4] :doc:`iscsi`
334* [5] :doc:`../driver-model/index`