README.uefi 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <!--
  2. SPDX-License-Identifier: GPL-2.0+
  3. Copyright (c) 2018 Heinrich Schuchardt
  4. -->
  5. # UEFI on U-Boot
  6. The Unified Extensible Firmware Interface Specification (UEFI) [1] has become
  7. the default for booting on AArch64 and x86 systems. It provides a stable API for
  8. the interaction of drivers and applications with the firmware. The API comprises
  9. access to block storage, network, and console to name a few. The Linux kernel
  10. and boot loaders like GRUB or the FreeBSD loader can be executed.
  11. ## Development target
  12. The implementation of UEFI in U-Boot strives to reach the requirements described
  13. in the "Embedded Base Boot Requirements (EBBR) Specification - Release v1.0"
  14. [4]. The "Server Base Boot Requirements System Software on ARM Platforms" [5]
  15. describes a superset of the EBBR specification and may be used as further
  16. reference.
  17. A full blown UEFI implementation would contradict the U-Boot design principle
  18. "keep it small".
  19. ## Building for UEFI
  20. The UEFI standard supports only little-endian systems. The UEFI support can be
  21. activated for ARM and x86 by specifying
  22. CONFIG_CMD_BOOTEFI=y
  23. CONFIG_EFI_LOADER=y
  24. in the .config file.
  25. Support for attaching virtual block devices, e.g. iSCSI drives connected by the
  26. loaded UEFI application [3], requires
  27. CONFIG_BLK=y
  28. CONFIG_PARTITIONS=y
  29. ### Executing a UEFI binary
  30. The bootefi command is used to start UEFI applications or to install UEFI
  31. drivers. It takes two parameters
  32. bootefi <image address> [fdt address]
  33. * image address - the memory address of the UEFI binary
  34. * fdt address - the memory address of the flattened device tree
  35. Below you find the output of an example session starting GRUB.
  36. => load mmc 0:2 ${fdt_addr_r} boot/dtb
  37. 29830 bytes read in 14 ms (2 MiB/s)
  38. => load mmc 0:1 ${kernel_addr_r} efi/debian/grubaa64.efi
  39. reading efi/debian/grubaa64.efi
  40. 120832 bytes read in 7 ms (16.5 MiB/s)
  41. => bootefi ${kernel_addr_r} ${fdt_addr_r}
  42. The environment variable 'bootargs' is passed as load options in the UEFI system
  43. table. The Linux kernel EFI stub uses the load options as command line
  44. arguments.
  45. ### Executing the boot manager
  46. The UEFI specification foresees to define boot entries and boot sequence via UEFI
  47. variables. Booting according to these variables is possible via
  48. bootefi bootmgr [fdt address]
  49. As of U-Boot v2018.03 UEFI variables are not persisted and cannot be set at
  50. runtime.
  51. ### Executing the built in hello world application
  52. A hello world UEFI application can be built with
  53. CONFIG_CMD_BOOTEFI_HELLO_COMPILE=y
  54. It can be embedded into the U-Boot binary with
  55. CONFIG_CMD_BOOTEFI_HELLO=y
  56. The bootefi command is used to start the embedded hello world application.
  57. bootefi hello [fdt address]
  58. Below you find the output of an example session.
  59. => bootefi hello ${fdtcontroladdr}
  60. ## Starting EFI application at 01000000 ...
  61. WARNING: using memory device/image path, this may confuse some payloads!
  62. Hello, world!
  63. Running on UEFI 2.7
  64. Have SMBIOS table
  65. Have device tree
  66. Load options: root=/dev/sdb3 init=/sbin/init rootwait ro
  67. ## Application terminated, r = 0
  68. The environment variable fdtcontroladdr points to U-Boot's internal device tree
  69. (if available).
  70. ### Executing the built-in self-test
  71. An UEFI self-test suite can be embedded in U-Boot by building with
  72. CONFIG_CMD_BOOTEFI_SELFTEST=y
  73. For testing the UEFI implementation the bootefi command can be used to start the
  74. self-test.
  75. bootefi selftest [fdt address]
  76. The environment variable 'efi_selftest' can be used to select a single test. If
  77. it is not provided all tests are executed except those marked as 'on request'.
  78. If the environment variable is set to 'list' a list of all tests is shown.
  79. Below you can find the output of an example session.
  80. => setenv efi_selftest simple network protocol
  81. => bootefi selftest
  82. Testing EFI API implementation
  83. Selected test: 'simple network protocol'
  84. Setting up 'simple network protocol'
  85. Setting up 'simple network protocol' succeeded
  86. Executing 'simple network protocol'
  87. DHCP Discover
  88. DHCP reply received from 192.168.76.2 (52:55:c0:a8:4c:02)
  89. as broadcast message.
  90. Executing 'simple network protocol' succeeded
  91. Tearing down 'simple network protocol'
  92. Tearing down 'simple network protocol' succeeded
  93. Boot services terminated
  94. Summary: 0 failures
  95. Preparing for reset. Press any key.
  96. ## The UEFI life cycle
  97. After the U-Boot platform has been initialized the UEFI API provides two kinds
  98. of services
  99. * boot services and
  100. * runtime services.
  101. The API can be extended by loading UEFI drivers which come in two variants
  102. * boot drivers and
  103. * runtime drivers.
  104. UEFI drivers are installed with U-Boot's bootefi command. With the same command
  105. UEFI applications can be executed.
  106. Loaded images of UEFI drivers stay in memory after returning to U-Boot while
  107. loaded images of applications are removed from memory.
  108. An UEFI application (e.g. an operating system) that wants to take full control
  109. of the system calls ExitBootServices. After a UEFI application calls
  110. ExitBootServices
  111. * boot services are not available anymore
  112. * timer events are stopped
  113. * the memory used by U-Boot except for runtime services is released
  114. * the memory used by boot time drivers is released
  115. So this is a point of no return. Afterwards the UEFI application can only return
  116. to U-Boot by rebooting.
  117. ## The UEFI object model
  118. UEFI offers a flexible and expandable object model. The objects in the UEFI API
  119. are devices, drivers, and loaded images. These objects are referenced by
  120. handles.
  121. The interfaces implemented by the objects are referred to as protocols. These
  122. are identified by GUIDs. They can be installed and uninstalled by calling the
  123. appropriate boot services.
  124. Handles are created by the InstallProtocolInterface or the
  125. InstallMultipleProtocolinterfaces service if NULL is passed as handle.
  126. Handles are deleted when the last protocol has been removed with the
  127. UninstallProtocolInterface or the UninstallMultipleProtocolInterfaces service.
  128. Devices offer the EFI_DEVICE_PATH_PROTOCOL. A device path is the concatenation
  129. of device nodes. By their device paths all devices of a system are arranged in a
  130. tree.
  131. Drivers offer the EFI_DRIVER_BINDING_PROTOCOL. This protocol is used to connect
  132. a driver to devices (which are referenced as controllers in this context).
  133. Loaded images offer the EFI_LOADED_IMAGE_PROTOCOL. This protocol provides meta
  134. information about the image and a pointer to the unload callback function.
  135. ## The UEFI events
  136. In the UEFI terminology an event is a data object referencing a notification
  137. function which is queued for calling when the event is signaled. The following
  138. types of events exist:
  139. * periodic and single shot timer events
  140. * exit boot services events, triggered by calling the ExitBootServices() service
  141. * virtual address change events
  142. * memory map change events
  143. * read to boot events
  144. * reset system events
  145. * system table events
  146. * events that are only triggered programmatically
  147. Events can be created with the CreateEvent service and deleted with CloseEvent
  148. service.
  149. Events can be assigned to an event group. If any of the events in a group is
  150. signaled, all other events in the group are also set to the signaled state.
  151. ## The UEFI driver model
  152. A driver is specific for a single protocol installed on a device. To install a
  153. driver on a device the ConnectController service is called. In this context
  154. controller refers to the device for which the driver is installed.
  155. The relevant drivers are identified using the EFI_DRIVER_BINDING_PROTOCOL. This
  156. protocol has has three functions:
  157. * supported - determines if the driver is compatible with the device
  158. * start - installs the driver by opening the relevant protocol with
  159. attribute EFI_OPEN_PROTOCOL_BY_DRIVER
  160. * stop - uninstalls the driver
  161. The driver may create child controllers (child devices). E.g. a driver for block
  162. IO devices will create the device handles for the partitions. The child
  163. controllers will open the supported protocol with the attribute
  164. EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
  165. A driver can be detached from a device using the DisconnectController service.
  166. ## U-Boot devices mapped as UEFI devices
  167. Some of the U-Boot devices are mapped as UEFI devices
  168. * block IO devices
  169. * console
  170. * graphical output
  171. * network adapter
  172. As of U-Boot 2018.03 the logic for doing this is hard coded.
  173. The development target is to integrate the setup of these UEFI devices with the
  174. U-Boot driver model. So when a U-Boot device is discovered a handle should be
  175. created and the device path protocol and the relevant IO protocol should be
  176. installed. The UEFI driver then would be attached by calling ConnectController.
  177. When a U-Boot device is removed DisconnectController should be called.
  178. ## UEFI devices mapped as U-Boot devices
  179. UEFI drivers binaries and applications may create new (virtual) devices, install
  180. a protocol and call the ConnectController service. Now the matching UEFI driver
  181. is determined by iterating over the implementations of the
  182. EFI_DRIVER_BINDING_PROTOCOL.
  183. It is the task of the UEFI driver to create a corresponding U-Boot device and to
  184. proxy calls for this U-Boot device to the controller.
  185. In U-Boot 2018.03 this has only been implemented for block IO devices.
  186. ### UEFI uclass
  187. An UEFI uclass driver (lib/efi_driver/efi_uclass.c) has been created that
  188. takes care of initializing the UEFI drivers and providing the
  189. EFI_DRIVER_BINDING_PROTOCOL implementation for the UEFI drivers.
  190. A linker created list is used to keep track of the UEFI drivers. To create an
  191. entry in the list the UEFI driver uses the U_BOOT_DRIVER macro specifying
  192. UCLASS_EFI as the ID of its uclass, e.g.
  193. /* Identify as UEFI driver */
  194. U_BOOT_DRIVER(efi_block) = {
  195. .name = "EFI block driver",
  196. .id = UCLASS_EFI,
  197. .ops = &driver_ops,
  198. };
  199. The available operations are defined via the structure struct efi_driver_ops.
  200. struct efi_driver_ops {
  201. const efi_guid_t *protocol;
  202. const efi_guid_t *child_protocol;
  203. int (*bind)(efi_handle_t handle, void *interface);
  204. };
  205. When the supported() function of the EFI_DRIVER_BINDING_PROTOCOL is called the
  206. uclass checks if the protocol GUID matches the protocol GUID of the UEFI driver.
  207. In the start() function the bind() function of the UEFI driver is called after
  208. checking the GUID.
  209. The stop() function of the EFI_DRIVER_BINDING_PROTOCOL disconnects the child
  210. controllers created by the UEFI driver and the UEFI driver. (In U-Boot v2013.03
  211. this is not yet completely implemented.)
  212. ### UEFI block IO driver
  213. The UEFI block IO driver supports devices exposing the EFI_BLOCK_IO_PROTOCOL.
  214. When connected it creates a new U-Boot block IO device with interface type
  215. IF_TYPE_EFI, adds child controllers mapping the partitions, and installs the
  216. EFI_SIMPLE_FILE_SYSTEM_PROTOCOL on these. This can be used together with the
  217. software iPXE to boot from iSCSI network drives [3].
  218. This driver is only available if U-Boot is configured with
  219. CONFIG_BLK=y
  220. CONFIG_PARTITIONS=y
  221. ## TODOs as of U-Boot 2019.04
  222. * unimplemented or incompletely implemented boot services
  223. * Exit - call unload function, unload applications only
  224. * ProtocolRegisterNotify
  225. * UnloadImage
  226. * unimplemented or incompletely implemented runtime services
  227. * SetVariable() ignores attribute EFI_VARIABLE_APPEND_WRITE
  228. * QueryVariableInfo is not implemented
  229. * unimplemented events
  230. * EVT_RUNTIME
  231. * EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
  232. * data model
  233. * manage configuration tables in a linked list
  234. * UEFI drivers
  235. * support DisconnectController for UEFI block devices.
  236. * support for CONFIG_EFI_LOADER in the sandbox (CONFIG_SANDBOX=y)
  237. * UEFI variables
  238. * persistence
  239. * runtime support
  240. * incompletely implemented protocols
  241. * support version 0x00020000 of the EFI file protocol
  242. ## Links
  243. * [1](http://uefi.org/specifications)
  244. http://uefi.org/specifications - UEFI specifications
  245. * [2](./driver-model/README.txt) doc/driver-model/README.txt - Driver model
  246. * [3](./README.iscsi) doc/README.iscsi - iSCSI booting with U-Boot and iPXE
  247. * [4](https://github.com/ARM-software/ebbr/releases/download/v1.0/ebbr-v1.0.pdf)
  248. Embedded Base Boot Requirements (EBBR) Specification - Release v1.0
  249. * [5](https://developer.arm.com/docs/den0044/latest/server-base-boot-requirements-system-software-on-arm-platforms-version-11)
  250. Server Base Boot Requirements System Software on ARM Platforms - Version 1.1