2 Provide Boot Manager related library APIs.
4 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _UEFI_BOOT_MANAGER_LIB_H_
17 #define _UEFI_BOOT_MANAGER_LIB_H_
19 #include <Protocol/DriverHealth.h>
20 #include <Library/SortLib.h>
23 // Boot Manager load option library functions.
33 } EFI_BOOT_MANAGER_LOAD_OPTION_TYPE
;
36 LoadOptionNumberMax
= 0x10000,
37 LoadOptionNumberUnassigned
= LoadOptionNumberMax
38 } EFI_BOOT_MANAGER_LOAD_OPTION_NUMBER
;
41 // Common structure definition for DriverOption and BootOption
45 // Data read from UEFI NV variables
47 UINTN OptionNumber
; // #### numerical value, could be LoadOptionNumberUnassigned
48 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
; // LoadOptionTypeBoot or LoadOptionTypeDriver
49 UINT32 Attributes
; // Load Option Attributes
50 CHAR16
*Description
; // Load Option Description
51 EFI_DEVICE_PATH_PROTOCOL
*FilePath
; // Load Option Device Path
52 UINT8
*OptionalData
; // Load Option optional data to pass into image
53 UINT32 OptionalDataSize
; // Load Option size of OptionalData
58 EFI_STATUS Status
; // Status returned from boot attempt gBS->StartImage ()
59 CHAR16
*ExitData
; // Exit data returned from gBS->StartImage ()
60 UINTN ExitDataSize
; // Size of ExitData
61 } EFI_BOOT_MANAGER_LOAD_OPTION
;
64 Returns an array of load options based on the EFI variable
65 L"BootOrder"/L"DriverOrder" and the L"Boot####"/L"Driver####" variables impled by it.
66 #### is the hex value of the UINT16 in each BootOrder/DriverOrder entry.
68 @param LoadOptionCount Returns number of entries in the array.
69 @param LoadOptionType The type of the load option.
71 @retval NULL No load options exist.
72 @retval !NULL Array of load option entries.
75 EFI_BOOT_MANAGER_LOAD_OPTION
*
77 EfiBootManagerGetLoadOptions (
78 OUT UINTN
*LoadOptionCount
,
79 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
83 Free an array of load options returned from EfiBootManagerGetLoadOptions().
85 @param LoadOptions Pointer to the array of load options to free.
86 @param LoadOptionCount Number of array entries in LoadOptions.
88 @return EFI_SUCCESS LoadOptions was freed.
89 @return EFI_INVALID_PARAMETER LoadOptions is NULL.
93 EfiBootManagerFreeLoadOptions (
94 IN EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOptions
,
95 IN UINTN LoadOptionCount
99 Initialize a load option.
101 @param Option Pointer to the load option to be initialized.
102 @param OptionNumber Option number of the load option.
103 @param OptionType Type of the load option.
104 @param Attributes Attributes of the load option.
105 @param Description Description of the load option.
106 @param FilePath Device path of the load option.
107 @param OptionalData Optional data of the load option.
108 @param OptionalDataSize Size of the optional data of the load option.
110 @retval EFI_SUCCESS The load option was initialized successfully.
111 @retval EFI_INVALID_PARAMETER Option, Description or FilePath is NULL.
115 EfiBootManagerInitializeLoadOption (
116 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION
*Option
,
117 IN UINTN OptionNumber
,
118 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
,
119 IN UINT32 Attributes
,
120 IN CHAR16
*Description
,
121 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
122 IN UINT8
*OptionalData
,
123 IN UINT32 OptionalDataSize
127 Free a load option created by EfiBootManagerInitializeLoadOption()
128 or EfiBootManagerVariableToLoadOption().
130 @param LoadOption Pointer to the load option to free.
131 CONCERN: Check Boot#### instead of BootOrder, optimize, spec clarify
132 @return EFI_SUCCESS LoadOption was freed.
133 @return EFI_INVALID_PARAMETER LoadOption is NULL.
138 EfiBootManagerFreeLoadOption (
139 IN EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
143 Initialize the load option from the VariableName.
145 @param VariableName EFI Variable name which could be Boot#### or
147 @param LoadOption Pointer to the load option to be initialized
149 @retval EFI_SUCCESS The option was created
150 @retval EFI_INVALID_PARAMETER VariableName or LoadOption is NULL.
151 @retval EFI_NOT_FOUND The variable specified by VariableName cannot be found.
155 EfiBootManagerVariableToLoadOption (
156 IN CHAR16
*VariableName
,
157 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
161 Create the Boot#### or Driver#### variable from the load option.
163 @param LoadOption Pointer to the load option.
165 @retval EFI_SUCCESS The variable was created.
166 @retval Others Error status returned by RT->SetVariable.
170 EfiBootManagerLoadOptionToVariable (
171 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
175 This function will update the Boot####/Driver#### and the BootOrder/DriverOrder
176 to add a new load option.
178 @param Option Pointer to load option to add.
179 @param Position Position of the new load option to put in the BootOrder/DriverOrder.
181 @retval EFI_SUCCESS The load option has been successfully added.
182 @retval Others Error status returned by RT->SetVariable.
186 EfiBootManagerAddLoadOptionVariable (
187 IN EFI_BOOT_MANAGER_LOAD_OPTION
*Option
,
192 Delete the load option according to the OptionNumber and OptionType.
194 Only the BootOrder/DriverOrder is updated to remove the reference of the OptionNumber.
196 @param OptionNumber Option number of the load option.
197 @param OptionType Type of the load option.
199 @retval EFI_NOT_FOUND The load option cannot be found.
200 @retval EFI_SUCCESS The load option was deleted.
204 EfiBootManagerDeleteLoadOptionVariable (
205 IN UINTN OptionNumber
,
206 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
210 Sort the load options. The DriverOrder/BootOrder variables will be re-created to
211 reflect the new order.
213 @param OptionType The type of the load option.
214 @param Comparator The comparator function pointer.
218 EfiBootManagerSortLoadOptionVariable (
219 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
,
220 IN SORT_COMPARE CompareFunction
224 // Boot Manager hot key library functions.
233 /// Specifies options about how the key will be processed.
235 EFI_BOOT_KEY_DATA KeyData
;
237 /// The CRC-32 which should match the CRC-32 of the entire EFI_LOAD_OPTION to
238 /// which BootOption refers. If the CRC-32s do not match this value, then this key
239 /// option is ignored.
241 UINT32 BootOptionCrc
;
243 /// The Boot#### option which will be invoked if this key is pressed and the boot option
244 /// is active (LOAD_OPTION_ACTIVE is set).
248 /// The key codes to compare against those returned by the
249 /// EFI_SIMPLE_TEXT_INPUT and EFI_SIMPLE_TEXT_INPUT_EX protocols.
250 /// The number of key codes (0-3) is specified by the EFI_KEY_CODE_COUNT field in KeyOptions.
252 EFI_INPUT_KEY Keys
[3];
254 } EFI_BOOT_MANAGER_KEY_OPTION
;
258 Start the hot key service so that the key press can trigger the boot option.
260 @param HotkeyTriggered Return the waitable event and it will be signaled
261 when a valid hot key is pressed.
263 @retval EFI_SUCCESS The hot key service is started.
267 EfiBootManagerStartHotkeyService (
268 IN EFI_EVENT
*HotkeyTriggered
272 // Modifier for EfiBootManagerAddKeyOptionVariable and EfiBootManagerDeleteKeyOptionVariable
274 #define EFI_BOOT_MANAGER_SHIFT_PRESSED 0x00000001
275 #define EFI_BOOT_MANAGER_CONTROL_PRESSED 0x00000002
276 #define EFI_BOOT_MANAGER_ALT_PRESSED 0x00000004
277 #define EFI_BOOT_MANAGER_LOGO_PRESSED 0x00000008
278 #define EFI_BOOT_MANAGER_MENU_KEY_PRESSED 0x00000010
279 #define EFI_BOOT_MANAGER_SYS_REQ_PRESSED 0x00000020
283 It adds the key option variable and the key option takes affect immediately.
285 @param AddedOption Return the added key option.
286 @param BootOptionNumber The boot option number for the key option.
287 @param Modifier Key shift state.
288 @param ... Parameter list of pointer of EFI_INPUT_KEY.
290 @retval EFI_SUCCESS The key option is added.
291 @retval EFI_ALREADY_STARTED The hot key is already used by certain key option.
295 EfiBootManagerAddKeyOptionVariable (
296 OUT EFI_BOOT_MANAGER_KEY_OPTION
*AddedOption
, OPTIONAL
297 IN UINT16 BootOptionNumber
,
303 Delete the Key Option variable and unregister the hot key
305 @param DeletedOption Return the deleted key options.
306 @param Modifier Key shift state.
307 @param ... Parameter list of pointer of EFI_INPUT_KEY.
309 @retval EFI_SUCCESS The key option is deleted.
310 @retval EFI_NOT_FOUND The key option cannot be found.
314 EfiBootManagerDeleteKeyOptionVariable (
315 IN EFI_BOOT_MANAGER_KEY_OPTION
*DeletedOption
, OPTIONAL
321 Register the key option to exit the waiting of the Boot Manager timeout.
322 Platform should ensure that the continue key option isn't conflict with
323 other boot key options.
325 @param Modifier Key shift state.
326 @param ... Parameter list of pointer of EFI_INPUT_KEY.
328 @retval EFI_SUCCESS Successfully register the continue key option.
329 @retval EFI_ALREADY_STARTED The continue key option is already registered.
333 EfiBootManagerRegisterContinueKeyOption (
339 Try to boot the boot option triggered by hot key.
343 EfiBootManagerHotkeyBoot (
347 // Boot Manager boot library functions.
351 The function creates boot options for all possible bootable medias in the following order:
352 1. Removable BlockIo - The boot option only points to the removable media
353 device, like USB key, DVD, Floppy etc.
354 2. Fixed BlockIo - The boot option only points to a Fixed blockIo device,
356 3. Non-BlockIo SimpleFileSystem - The boot option points to a device supporting
357 SimpleFileSystem Protocol, but not supporting BlockIo
359 4. LoadFile - The boot option points to the media supporting
361 Reference: UEFI Spec chapter 3.3 Boot Option Variables Default Boot Behavior
363 The function won't delete the boot option not added by itself.
367 EfiBootManagerRefreshAllBootOption (
372 Attempt to boot the EFI boot option. This routine sets L"BootCurent" and
373 signals the EFI ready to boot event. If the device path for the option starts
374 with a BBS device path a legacy boot is attempted. Short form device paths are
375 also supported via this rountine. A device path starting with
376 MEDIA_HARDDRIVE_DP, MSG_USB_WWID_DP, MSG_USB_CLASS_DP gets expaned out
377 to find the first device that matches. If the BootOption Device Path
378 fails the removable media boot algorithm is attempted (\EFI\BOOTIA32.EFI,
379 \EFI\BOOTX64.EFI,... only one file type is tried per processor type)
381 @param BootOption Boot Option to try and boot.
382 On return, BootOption->Status contains the boot status:
383 EFI_SUCCESS BootOption was booted
384 EFI_UNSUPPORTED BootOption isn't supported.
385 EFI_NOT_FOUND The BootOption was not found on the system
386 Others BootOption failed with this error status
392 IN EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
396 Return the Boot Manager Menu.
398 @param BootOption Return the Boot Manager Menu.
400 @retval EFI_SUCCESS The Boot Manager Menu is successfully returned.
401 @retval EFI_NOT_FOUND The Boot Manager Menu is not found.
405 EfiBootManagerGetBootManagerMenu (
406 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
410 The function enumerates all the legacy boot options, creates them and
411 registers them in the BootOrder variable.
415 (EFIAPI
*EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION
) (
420 The function boots a legacy boot option.
424 (EFIAPI
*EFI_BOOT_MANAGER_LEGACY_BOOT
) (
425 IN EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
429 The function registers the legacy boot support capabilities.
431 @param RefreshLegacyBootOption The function pointer to create all the legacy boot options.
432 @param LegacyBoot The function pointer to boot the legacy boot option.
436 EfiBootManagerRegisterLegacyBootSupport (
437 EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION RefreshLegacyBootOption
,
438 EFI_BOOT_MANAGER_LEGACY_BOOT LegacyBoot
443 // Boot Manager connect and disconnect library functions
447 This function will connect all the system driver to controller
448 first, and then special connect the default console, this make
449 sure all the system controller available and the platform default
454 EfiBootManagerConnectAll (
459 This function will create all handles associate with every device
460 path node. If the handle associate with one device path node can not
461 be created successfully, then still give one chance to do the dispatch,
462 which load the missing drivers if possible.
464 @param DevicePathToConnect The device path which will be connected, it CANNOT be
465 a multi-instance device path
466 @param MatchingHandle Return the controller handle closest to the DevicePathToConnect
468 @retval EFI_INVALID_PARAMETER DevicePathToConnect is NULL.
469 @retval EFI_NOT_FOUND Failed to create all handles associate with every device path node.
470 @retval EFI_SUCCESS Successful to create all handles associate with every device path node.
475 EfiBootManagerConnectDevicePath (
476 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathToConnect
,
477 OUT EFI_HANDLE
*MatchingHandle OPTIONAL
481 This function will disconnect all current system handles.
483 gBS->DisconnectController() is invoked for each handle exists in system handle buffer.
484 If handle is a bus type handle, all childrens also are disconnected recursively by
485 gBS->DisconnectController().
489 EfiBootManagerDisconnectAll (
495 // Boot Manager console library functions
509 This function will connect all the console devices base on the console
510 device variable ConIn, ConOut and ErrOut.
514 EfiBootManagerConnectAllDefaultConsoles (
519 This function updates the console variable based on ConVarName. It can
520 add or remove one specific console device path from the variable
522 @param ConsoleType ConIn, ConOut, ErrOut, ConInDev, ConOutDev or ErrOutDev.
523 @param CustomizedConDevicePath The console device path to be added to
524 the console variable. Cannot be multi-instance.
525 @param ExclusiveDevicePath The console device path to be removed
526 from the console variable. Cannot be multi-instance.
528 @retval EFI_UNSUPPORTED The added device path is the same as a removed one.
529 @retval EFI_SUCCESS Successfully added or removed the device path from the
535 EfiBootManagerUpdateConsoleVariable (
536 IN CONSOLE_TYPE ConsoleType
,
537 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
538 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
542 Connect the console device base on the variable ConVarName, if
543 device path of the ConVarName is multi-instance device path, if
544 anyone of the instances is connected success, then this function
547 @param ConsoleType ConIn, ConOut or ErrOut.
549 @retval EFI_NOT_FOUND There is not any console devices connected
551 @retval EFI_SUCCESS Success connect any one instance of the console
552 device path base on the variable ConVarName.
557 EfiBootManagerConnectConsoleVariable (
558 IN CONSOLE_TYPE ConsoleType
562 Query all the children of VideoController and return the device paths of all the
563 children that support GraphicsOutput protocol.
565 @param VideoController PCI handle of video controller.
567 @return Device paths of all the children that support GraphicsOutput protocol.
569 EFI_DEVICE_PATH_PROTOCOL
*
571 EfiBootManagerGetGopDevicePath (
572 IN EFI_HANDLE VideoController
576 Connect the platform active active video controller.
578 @param VideoController PCI handle of video controller.
580 @retval EFI_NOT_FOUND There is no active video controller.
581 @retval EFI_SUCCESS The video controller is connected.
585 EfiBootManagerConnectVideoController (
586 EFI_HANDLE VideoController OPTIONAL
590 // Boot Manager driver health library functions.
594 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
597 /// Driver relative handles
599 EFI_HANDLE DriverHealthHandle
;
600 EFI_HANDLE ControllerHandle
;
601 EFI_HANDLE ChildHandle
;
604 /// Driver health messages of the specify Driver
606 EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
;
609 /// HII relative handles
611 EFI_HII_HANDLE HiiHandle
;
614 /// Driver Health status
616 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
617 } EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
;
620 Return all the Driver Health information.
622 When the cumulative health status of all the controllers managed by the
623 driver who produces the EFI_DRIVER_HEALTH_PROTOCOL is healthy, only one
624 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO entry is created for such
625 EFI_DRIVER_HEALTH_PROTOCOL instance.
626 Otherwise, every controller creates one EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
627 entry. Additionally every child controller creates one
628 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO entry if the driver is a bus driver.
630 @param Count Return the count of the Driver Health information.
632 @retval NULL No Driver Health information is returned.
633 @retval !NULL Pointer to the Driver Health information array.
635 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
*
637 EfiBootManagerGetDriverHealthInfo (
642 Free the Driver Health information array.
644 @param DriverHealthInfo Pointer to array of the Driver Health information.
645 @param Count Count of the array.
647 @retval EFI_SUCCESS The array is freed.
648 @retval EFI_INVALID_PARAMETER The array is NULL.
652 EfiBootManagerFreeDriverHealthInfo (
653 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
*DriverHealthInfo
,