2 Provide Boot Manager related library APIs.
4 Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef _UEFI_BOOT_MANAGER_LIB_H_
11 #define _UEFI_BOOT_MANAGER_LIB_H_
13 #include <Protocol/DriverHealth.h>
14 #include <Library/SortLib.h>
17 // Boot Manager load option library functions.
25 LoadOptionTypeSysPrep
,
27 LoadOptionTypePlatformRecovery
,
29 } EFI_BOOT_MANAGER_LOAD_OPTION_TYPE
;
32 LoadOptionNumberMax
= 0x10000,
33 LoadOptionNumberUnassigned
= LoadOptionNumberMax
34 } EFI_BOOT_MANAGER_LOAD_OPTION_NUMBER
;
37 // Common structure definition for DriverOption and BootOption
41 // Data read from UEFI NV variables
43 UINTN OptionNumber
; // #### numerical value, could be LoadOptionNumberUnassigned
44 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
; // LoadOptionTypeBoot or LoadOptionTypeDriver
45 UINT32 Attributes
; // Load Option Attributes
46 CHAR16
*Description
; // Load Option Description
47 EFI_DEVICE_PATH_PROTOCOL
*FilePath
; // Load Option Device Path
48 UINT8
*OptionalData
; // Load Option optional data to pass into image
49 UINT32 OptionalDataSize
; // Load Option size of OptionalData
55 EFI_STATUS Status
; // Status returned from boot attempt gBS->StartImage ()
56 CHAR16
*ExitData
; // Exit data returned from gBS->StartImage ()
57 UINTN ExitDataSize
; // Size of ExitData
58 } EFI_BOOT_MANAGER_LOAD_OPTION
;
61 Returns an array of load options based on the EFI variable
62 L"BootOrder"/L"DriverOrder" and the L"Boot####"/L"Driver####" variables impled by it.
63 #### is the hex value of the UINT16 in each BootOrder/DriverOrder entry.
65 @param LoadOptionCount Returns number of entries in the array.
66 @param LoadOptionType The type of the load option.
68 @retval NULL No load options exist.
69 @retval !NULL Array of load option entries.
72 EFI_BOOT_MANAGER_LOAD_OPTION
*
74 EfiBootManagerGetLoadOptions (
75 OUT UINTN
*LoadOptionCount
,
76 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
80 Free an array of load options returned from EfiBootManagerGetLoadOptions().
82 @param LoadOptions Pointer to the array of load options to free.
83 @param LoadOptionCount Number of array entries in LoadOptions.
85 @return EFI_SUCCESS LoadOptions was freed.
86 @return EFI_INVALID_PARAMETER LoadOptions is NULL.
90 EfiBootManagerFreeLoadOptions (
91 IN EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOptions
,
92 IN UINTN LoadOptionCount
96 Initialize a load option.
98 @param Option Pointer to the load option to be initialized.
99 @param OptionNumber Option number of the load option.
100 @param OptionType Type of the load option.
101 @param Attributes Attributes of the load option.
102 @param Description Description of the load option.
103 @param FilePath Device path of the load option.
104 @param OptionalData Optional data of the load option.
105 @param OptionalDataSize Size of the optional data of the load option.
107 @retval EFI_SUCCESS The load option was initialized successfully.
108 @retval EFI_INVALID_PARAMETER Option, Description or FilePath is NULL.
112 EfiBootManagerInitializeLoadOption (
113 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION
*Option
,
114 IN UINTN OptionNumber
,
115 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
,
116 IN UINT32 Attributes
,
117 IN CHAR16
*Description
,
118 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
119 IN UINT8
*OptionalData
,
120 IN UINT32 OptionalDataSize
124 Free a load option created by EfiBootManagerInitializeLoadOption()
125 or EfiBootManagerVariableToLoadOption().
127 @param LoadOption Pointer to the load option to free.
128 CONCERN: Check Boot#### instead of BootOrder, optimize, spec clarify
129 @return EFI_SUCCESS LoadOption was freed.
130 @return EFI_INVALID_PARAMETER LoadOption is NULL.
135 EfiBootManagerFreeLoadOption (
136 IN EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
140 Initialize the load option from the VariableName.
142 @param VariableName EFI Variable name which could be Boot#### or
144 @param LoadOption Pointer to the load option to be initialized
146 @retval EFI_SUCCESS The option was created
147 @retval EFI_INVALID_PARAMETER VariableName or LoadOption is NULL.
148 @retval EFI_NOT_FOUND The variable specified by VariableName cannot be found.
152 EfiBootManagerVariableToLoadOption (
153 IN CHAR16
*VariableName
,
154 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
158 Create the Boot#### or Driver#### variable from the load option.
160 @param LoadOption Pointer to the load option.
162 @retval EFI_SUCCESS The variable was created.
163 @retval Others Error status returned by RT->SetVariable.
167 EfiBootManagerLoadOptionToVariable (
168 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
172 This function will register the new Boot####, Driver#### or SysPrep#### option.
173 After the *#### is updated, the *Order will also be updated.
175 @param Option Pointer to load option to add. If on input
176 Option->OptionNumber is LoadOptionNumberUnassigned,
177 then on output Option->OptionNumber is updated to
178 the number of the new Boot####,
179 Driver#### or SysPrep#### option.
180 @param Position Position of the new load option to put in the ****Order variable.
182 @retval EFI_SUCCESS The *#### have been successfully registered.
183 @retval EFI_INVALID_PARAMETER The option number exceeds 0xFFFF.
184 @retval EFI_ALREADY_STARTED The option number of Option is being used already.
185 Note: this API only adds new load option, no replacement support.
186 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used when the
187 option number specified in the Option is LoadOptionNumberUnassigned.
188 @return Status codes of gRT->SetVariable ().
193 EfiBootManagerAddLoadOptionVariable (
194 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION
*Option
,
199 Delete the load option according to the OptionNumber and OptionType.
201 Only the BootOrder/DriverOrder is updated to remove the reference of the OptionNumber.
203 @param OptionNumber Option number of the load option.
204 @param OptionType Type of the load option.
206 @retval EFI_NOT_FOUND The load option cannot be found.
207 @retval EFI_SUCCESS The load option was deleted.
211 EfiBootManagerDeleteLoadOptionVariable (
212 IN UINTN OptionNumber
,
213 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
217 Sort the load options. The DriverOrder/BootOrder variables will be re-created to
218 reflect the new order.
220 @param OptionType The type of the load option.
221 @param CompareFunction The comparator function pointer.
225 EfiBootManagerSortLoadOptionVariable (
226 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
,
227 IN SORT_COMPARE CompareFunction
231 Return the index of the load option in the load option array.
233 The function consider two load options are equal when the
234 OptionType, Attributes, Description, FilePath and OptionalData are equal.
236 @param Key Pointer to the load option to be found.
237 @param Array Pointer to the array of load options to be found.
238 @param Count Number of entries in the Array.
240 @retval -1 Key wasn't found in the Array.
241 @retval 0 ~ Count-1 The index of the Key in the Array.
245 EfiBootManagerFindLoadOption (
246 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Key
,
247 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Array
,
252 // Boot Manager hot key library functions.
261 /// Specifies options about how the key will be processed.
263 EFI_BOOT_KEY_DATA KeyData
;
265 /// The CRC-32 which should match the CRC-32 of the entire EFI_LOAD_OPTION to
266 /// which BootOption refers. If the CRC-32s do not match this value, then this key
267 /// option is ignored.
269 UINT32 BootOptionCrc
;
271 /// The Boot#### option which will be invoked if this key is pressed and the boot option
272 /// is active (LOAD_OPTION_ACTIVE is set).
276 /// The key codes to compare against those returned by the
277 /// EFI_SIMPLE_TEXT_INPUT and EFI_SIMPLE_TEXT_INPUT_EX protocols.
278 /// The number of key codes (0-3) is specified by the EFI_KEY_CODE_COUNT field in KeyOptions.
280 EFI_INPUT_KEY Keys
[3];
282 } EFI_BOOT_MANAGER_KEY_OPTION
;
286 Start the hot key service so that the key press can trigger the boot option.
288 @param HotkeyTriggered Return the waitable event and it will be signaled
289 when a valid hot key is pressed.
291 @retval EFI_SUCCESS The hot key service is started.
295 EfiBootManagerStartHotkeyService (
296 IN EFI_EVENT
*HotkeyTriggered
300 // Modifier for EfiBootManagerAddKeyOptionVariable and EfiBootManagerDeleteKeyOptionVariable
302 #define EFI_BOOT_MANAGER_SHIFT_PRESSED 0x00000001
303 #define EFI_BOOT_MANAGER_CONTROL_PRESSED 0x00000002
304 #define EFI_BOOT_MANAGER_ALT_PRESSED 0x00000004
305 #define EFI_BOOT_MANAGER_LOGO_PRESSED 0x00000008
306 #define EFI_BOOT_MANAGER_MENU_KEY_PRESSED 0x00000010
307 #define EFI_BOOT_MANAGER_SYS_REQ_PRESSED 0x00000020
311 It adds the key option variable and the key option takes affect immediately.
313 @param AddedOption Return the added key option.
314 @param BootOptionNumber The boot option number for the key option.
315 @param Modifier Key shift state.
316 @param ... Parameter list of pointer of EFI_INPUT_KEY.
318 @retval EFI_SUCCESS The key option is added.
319 @retval EFI_ALREADY_STARTED The hot key is already used by certain key option.
323 EfiBootManagerAddKeyOptionVariable (
324 OUT EFI_BOOT_MANAGER_KEY_OPTION
*AddedOption OPTIONAL
,
325 IN UINT16 BootOptionNumber
,
331 Delete the Key Option variable and unregister the hot key
333 @param DeletedOption Return the deleted key options.
334 @param Modifier Key shift state.
335 @param ... Parameter list of pointer of EFI_INPUT_KEY.
337 @retval EFI_SUCCESS The key option is deleted.
338 @retval EFI_NOT_FOUND The key option cannot be found.
342 EfiBootManagerDeleteKeyOptionVariable (
343 IN EFI_BOOT_MANAGER_KEY_OPTION
*DeletedOption OPTIONAL
,
349 Register the key option to exit the waiting of the Boot Manager timeout.
350 Platform should ensure that the continue key option isn't conflict with
351 other boot key options.
353 @param Modifier Key shift state.
354 @param ... Parameter list of pointer of EFI_INPUT_KEY.
356 @retval EFI_SUCCESS Successfully register the continue key option.
357 @retval EFI_ALREADY_STARTED The continue key option is already registered.
361 EfiBootManagerRegisterContinueKeyOption (
367 Try to boot the boot option triggered by hot key.
371 EfiBootManagerHotkeyBoot (
376 // Boot Manager boot library functions.
380 The function creates boot options for all possible bootable medias in the following order:
381 1. Removable BlockIo - The boot option only points to the removable media
382 device, like USB key, DVD, Floppy etc.
383 2. Fixed BlockIo - The boot option only points to a Fixed blockIo device,
385 3. Non-BlockIo SimpleFileSystem - The boot option points to a device supporting
386 SimpleFileSystem Protocol, but not supporting BlockIo
388 4. LoadFile - The boot option points to the media supporting
390 Reference: UEFI Spec chapter 3.3 Boot Option Variables Default Boot Behavior
392 The function won't delete the boot option not added by itself.
396 EfiBootManagerRefreshAllBootOption (
401 Attempt to boot the EFI boot option. This routine sets L"BootCurent" and
402 signals the EFI ready to boot event. If the device path for the option starts
403 with a BBS device path a legacy boot is attempted. Short form device paths are
404 also supported via this rountine. A device path starting with
405 MEDIA_HARDDRIVE_DP, MSG_USB_WWID_DP, MSG_USB_CLASS_DP gets expaned out
406 to find the first device that matches. If the BootOption Device Path
407 fails the removable media boot algorithm is attempted (\EFI\BOOTIA32.EFI,
408 \EFI\BOOTX64.EFI,... only one file type is tried per processor type)
410 @param BootOption Boot Option to try and boot.
411 On return, BootOption->Status contains the boot status:
412 EFI_SUCCESS BootOption was booted
413 EFI_UNSUPPORTED BootOption isn't supported.
414 EFI_NOT_FOUND The BootOption was not found on the system
415 Others BootOption failed with this error status
421 IN EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
425 Return the boot option corresponding to the Boot Manager Menu.
426 It may automatically create one if the boot option hasn't been created yet.
428 @param BootOption Return the Boot Manager Menu.
430 @retval EFI_SUCCESS The Boot Manager Menu is successfully returned.
431 @retval EFI_NOT_FOUND The Boot Manager Menu cannot be found.
432 @retval others Return status of gRT->SetVariable (). BootOption still points
433 to the Boot Manager Menu even the Status is not EFI_SUCCESS
438 EfiBootManagerGetBootManagerMenu (
439 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
443 Get the next possible full path pointing to the load option.
444 The routine doesn't guarantee the returned full path points to an existing
445 file, and it also doesn't guarantee the existing file is a valid load option.
446 BmGetNextLoadOptionBuffer() guarantees.
448 @param FilePath The device path pointing to a load option.
449 It could be a short-form device path.
450 @param FullPath The full path returned by the routine in last call.
451 Set to NULL in first call.
453 @return The next possible full path pointing to the load option.
454 Caller is responsible to free the memory.
456 EFI_DEVICE_PATH_PROTOCOL
*
458 EfiBootManagerGetNextLoadOptionDevicePath (
459 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
460 IN EFI_DEVICE_PATH_PROTOCOL
*FullPath
464 Get the load option by its device path.
466 @param FilePath The device path pointing to a load option.
467 It could be a short-form device path.
468 @param FullPath Return the full device path of the load option after
469 short-form device path expanding.
470 Caller is responsible to free it.
471 @param FileSize Return the load option size.
473 @return The load option buffer. Caller is responsible to free the memory.
477 EfiBootManagerGetLoadOptionBuffer (
478 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
479 OUT EFI_DEVICE_PATH_PROTOCOL
**FullPath
,
484 The function enumerates all the legacy boot options, creates them and
485 registers them in the BootOrder variable.
489 (EFIAPI
*EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION
)(
494 The function boots a legacy boot option.
498 (EFIAPI
*EFI_BOOT_MANAGER_LEGACY_BOOT
)(
499 IN EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
503 The function registers the legacy boot support capabilities.
505 @param RefreshLegacyBootOption The function pointer to create all the legacy boot options.
506 @param LegacyBoot The function pointer to boot the legacy boot option.
510 EfiBootManagerRegisterLegacyBootSupport (
511 EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION RefreshLegacyBootOption
,
512 EFI_BOOT_MANAGER_LEGACY_BOOT LegacyBoot
516 Return the platform provided boot option description for the controller.
518 @param Handle Controller handle.
519 @param DefaultDescription Default boot description provided by core.
521 @return The callee allocated description string
522 or NULL if the handler wants to use DefaultDescription.
526 (EFIAPI
*EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER
)(
527 IN EFI_HANDLE Handle
,
528 IN CONST CHAR16
*DefaultDescription
532 Register the platform provided boot description handler.
534 @param Handler The platform provided boot description handler
536 @retval EFI_SUCCESS The handler was registered successfully.
537 @retval EFI_ALREADY_STARTED The handler was already registered.
538 @retval EFI_OUT_OF_RESOURCES There is not enough resource to perform the registration.
542 EfiBootManagerRegisterBootDescriptionHandler (
543 IN EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler
547 // Boot Manager connect and disconnect library functions
551 This function will connect all the system driver to controller
552 first, and then special connect the default console, this make
553 sure all the system controller available and the platform default
558 EfiBootManagerConnectAll (
563 This function will create all handles associate with every device
564 path node. If the handle associate with one device path node can not
565 be created successfully, then still give chance to do the dispatch,
566 which load the missing drivers if possible.
568 @param DevicePathToConnect The device path which will be connected, it can be
569 a multi-instance device path
570 @param MatchingHandle Return the controller handle closest to the DevicePathToConnect
572 @retval EFI_SUCCESS All handles associate with every device path node
574 @retval EFI_OUT_OF_RESOURCES There is no resource to create new handles.
575 @retval EFI_NOT_FOUND Create the handle associate with one device path
577 @retval EFI_SECURITY_VIOLATION The user has no permission to start UEFI device
578 drivers on the DevicePath.
582 EfiBootManagerConnectDevicePath (
583 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathToConnect
,
584 OUT EFI_HANDLE
*MatchingHandle OPTIONAL
588 This function will disconnect all current system handles.
590 gBS->DisconnectController() is invoked for each handle exists in system handle buffer.
591 If handle is a bus type handle, all childrens also are disconnected recursively by
592 gBS->DisconnectController().
596 EfiBootManagerDisconnectAll (
601 // Boot Manager console library functions
615 This function will connect all the console devices base on the console
616 device variable ConIn, ConOut and ErrOut.
618 @retval EFI_DEVICE_ERROR All the consoles were not connected due to an error.
619 @retval EFI_SUCCESS Success connect any one instance of the console
620 device path base on the variable ConVarName.
624 EfiBootManagerConnectAllDefaultConsoles (
629 This function updates the console variable based on ConVarName. It can
630 add or remove one specific console device path from the variable
632 @param ConsoleType ConIn, ConOut, ErrOut, ConInDev, ConOutDev or ErrOutDev.
633 @param CustomizedConDevicePath The console device path to be added to
634 the console variable. Cannot be multi-instance.
635 @param ExclusiveDevicePath The console device path to be removed
636 from the console variable. Cannot be multi-instance.
638 @retval EFI_UNSUPPORTED The added device path is the same as a removed one.
639 @retval EFI_SUCCESS Successfully added or removed the device path from the
645 EfiBootManagerUpdateConsoleVariable (
646 IN CONSOLE_TYPE ConsoleType
,
647 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
648 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
652 Connect the console device base on the variable ConVarName, if
653 device path of the ConVarName is multi-instance device path, if
654 anyone of the instances is connected success, then this function
657 @param ConsoleType ConIn, ConOut or ErrOut.
659 @retval EFI_NOT_FOUND There is not any console devices connected
661 @retval EFI_SUCCESS Success connect any one instance of the console
662 device path base on the variable ConVarName.
667 EfiBootManagerConnectConsoleVariable (
668 IN CONSOLE_TYPE ConsoleType
672 Query all the children of VideoController and return the device paths of all the
673 children that support GraphicsOutput protocol.
675 @param VideoController PCI handle of video controller.
677 @return Device paths of all the children that support GraphicsOutput protocol.
679 EFI_DEVICE_PATH_PROTOCOL
*
681 EfiBootManagerGetGopDevicePath (
682 IN EFI_HANDLE VideoController
686 Connect the platform active active video controller.
688 @param VideoController PCI handle of video controller.
690 @retval EFI_NOT_FOUND There is no active video controller.
691 @retval EFI_SUCCESS The video controller is connected.
695 EfiBootManagerConnectVideoController (
696 EFI_HANDLE VideoController OPTIONAL
700 // Boot Manager driver health library functions.
704 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
707 /// Driver relative handles
709 EFI_HANDLE DriverHealthHandle
;
710 EFI_HANDLE ControllerHandle
;
711 EFI_HANDLE ChildHandle
;
714 /// Driver health messages of the specify Driver
716 EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
;
719 /// HII relative handles
721 EFI_HII_HANDLE HiiHandle
;
724 /// Driver Health status
726 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
727 } EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
;
730 Return all the Driver Health information.
732 When the cumulative health status of all the controllers managed by the
733 driver who produces the EFI_DRIVER_HEALTH_PROTOCOL is healthy, only one
734 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO entry is created for such
735 EFI_DRIVER_HEALTH_PROTOCOL instance.
736 Otherwise, every controller creates one EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
737 entry. Additionally every child controller creates one
738 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO entry if the driver is a bus driver.
740 @param Count Return the count of the Driver Health information.
742 @retval NULL No Driver Health information is returned.
743 @retval !NULL Pointer to the Driver Health information array.
745 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
*
747 EfiBootManagerGetDriverHealthInfo (
752 Free the Driver Health information array.
754 @param DriverHealthInfo Pointer to array of the Driver Health information.
755 @param Count Count of the array.
757 @retval EFI_SUCCESS The array is freed.
758 @retval EFI_INVALID_PARAMETER The array is NULL.
762 EfiBootManagerFreeDriverHealthInfo (
763 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
*DriverHealthInfo
,
768 Process (load and execute) the load option.
770 @param LoadOption Pointer to the load option.
772 @retval EFI_INVALID_PARAMETER The load option type is invalid,
773 or the load option file path doesn't point to a valid file.
774 @retval EFI_UNSUPPORTED The load option type is of LoadOptionTypeBoot.
775 @retval EFI_SUCCESS The load option is inactive, or successfully loaded and executed.
779 EfiBootManagerProcessLoadOption (
780 EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
784 Check whether the VariableName is a valid load option variable name
785 and return the load option type and option number.
787 @param VariableName The name of the load option variable.
788 @param OptionType Return the load option type.
789 @param OptionNumber Return the load option number.
791 @retval TRUE The variable name is valid; The load option type and
792 load option number are returned.
793 @retval FALSE The variable name is NOT valid.
797 EfiBootManagerIsValidLoadOptionVariableName (
798 IN CHAR16
*VariableName
,
799 OUT EFI_BOOT_MANAGER_LOAD_OPTION_TYPE
*OptionType OPTIONAL
,
800 OUT UINT16
*OptionNumber OPTIONAL
804 Dispatch the deferred images that are returned from all DeferredImageLoad instances.
806 @retval EFI_SUCCESS At least one deferred image is loaded successfully and started.
807 @retval EFI_NOT_FOUND There is no deferred image.
808 @retval EFI_ACCESS_DENIED There are deferred images but all of them are failed to load.
812 EfiBootManagerDispatchDeferredImages (