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
11 #ifndef _UEFI_BOOT_MANAGER_LIB_H_
12 #define _UEFI_BOOT_MANAGER_LIB_H_
14 #include <Protocol/DriverHealth.h>
15 #include <Library/SortLib.h>
18 // Boot Manager load option library functions.
26 LoadOptionTypeSysPrep
,
28 LoadOptionTypePlatformRecovery
,
30 } EFI_BOOT_MANAGER_LOAD_OPTION_TYPE
;
33 LoadOptionNumberMax
= 0x10000,
34 LoadOptionNumberUnassigned
= LoadOptionNumberMax
35 } EFI_BOOT_MANAGER_LOAD_OPTION_NUMBER
;
38 // Common structure definition for DriverOption and BootOption
42 // Data read from UEFI NV variables
44 UINTN OptionNumber
; // #### numerical value, could be LoadOptionNumberUnassigned
45 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
; // LoadOptionTypeBoot or LoadOptionTypeDriver
46 UINT32 Attributes
; // Load Option Attributes
47 CHAR16
*Description
; // Load Option Description
48 EFI_DEVICE_PATH_PROTOCOL
*FilePath
; // Load Option Device Path
49 UINT8
*OptionalData
; // Load Option optional data to pass into image
50 UINT32 OptionalDataSize
; // Load Option size of OptionalData
56 EFI_STATUS Status
; // Status returned from boot attempt gBS->StartImage ()
57 CHAR16
*ExitData
; // Exit data returned from gBS->StartImage ()
58 UINTN ExitDataSize
; // Size of ExitData
59 } EFI_BOOT_MANAGER_LOAD_OPTION
;
62 Returns an array of load options based on the EFI variable
63 L"BootOrder"/L"DriverOrder" and the L"Boot####"/L"Driver####" variables impled by it.
64 #### is the hex value of the UINT16 in each BootOrder/DriverOrder entry.
66 @param LoadOptionCount Returns number of entries in the array.
67 @param LoadOptionType The type of the load option.
69 @retval NULL No load options exist.
70 @retval !NULL Array of load option entries.
73 EFI_BOOT_MANAGER_LOAD_OPTION
*
75 EfiBootManagerGetLoadOptions (
76 OUT UINTN
*LoadOptionCount
,
77 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
81 Free an array of load options returned from EfiBootManagerGetLoadOptions().
83 @param LoadOptions Pointer to the array of load options to free.
84 @param LoadOptionCount Number of array entries in LoadOptions.
86 @return EFI_SUCCESS LoadOptions was freed.
87 @return EFI_INVALID_PARAMETER LoadOptions is NULL.
91 EfiBootManagerFreeLoadOptions (
92 IN EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOptions
,
93 IN UINTN LoadOptionCount
97 Initialize a load option.
99 @param Option Pointer to the load option to be initialized.
100 @param OptionNumber Option number of the load option.
101 @param OptionType Type of the load option.
102 @param Attributes Attributes of the load option.
103 @param Description Description of the load option.
104 @param FilePath Device path of the load option.
105 @param OptionalData Optional data of the load option.
106 @param OptionalDataSize Size of the optional data of the load option.
108 @retval EFI_SUCCESS The load option was initialized successfully.
109 @retval EFI_INVALID_PARAMETER Option, Description or FilePath is NULL.
113 EfiBootManagerInitializeLoadOption (
114 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION
*Option
,
115 IN UINTN OptionNumber
,
116 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
,
117 IN UINT32 Attributes
,
118 IN CHAR16
*Description
,
119 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
120 IN UINT8
*OptionalData
,
121 IN UINT32 OptionalDataSize
125 Free a load option created by EfiBootManagerInitializeLoadOption()
126 or EfiBootManagerVariableToLoadOption().
128 @param LoadOption Pointer to the load option to free.
129 CONCERN: Check Boot#### instead of BootOrder, optimize, spec clarify
130 @return EFI_SUCCESS LoadOption was freed.
131 @return EFI_INVALID_PARAMETER LoadOption is NULL.
136 EfiBootManagerFreeLoadOption (
137 IN EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
141 Initialize the load option from the VariableName.
143 @param VariableName EFI Variable name which could be Boot#### or
145 @param LoadOption Pointer to the load option to be initialized
147 @retval EFI_SUCCESS The option was created
148 @retval EFI_INVALID_PARAMETER VariableName or LoadOption is NULL.
149 @retval EFI_NOT_FOUND The variable specified by VariableName cannot be found.
153 EfiBootManagerVariableToLoadOption (
154 IN CHAR16
*VariableName
,
155 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
159 Create the Boot#### or Driver#### variable from the load option.
161 @param LoadOption Pointer to the load option.
163 @retval EFI_SUCCESS The variable was created.
164 @retval Others Error status returned by RT->SetVariable.
168 EfiBootManagerLoadOptionToVariable (
169 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
173 This function will register the new Boot####, Driver#### or SysPrep#### option.
174 After the *#### is updated, the *Order will also be updated.
176 @param Option Pointer to load option to add. If on input
177 Option->OptionNumber is LoadOptionNumberUnassigned,
178 then on output Option->OptionNumber is updated to
179 the number of the new Boot####,
180 Driver#### or SysPrep#### option.
181 @param Position Position of the new load option to put in the ****Order variable.
183 @retval EFI_SUCCESS The *#### have been successfully registered.
184 @retval EFI_INVALID_PARAMETER The option number exceeds 0xFFFF.
185 @retval EFI_ALREADY_STARTED The option number of Option is being used already.
186 Note: this API only adds new load option, no replacement support.
187 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used when the
188 option number specified in the Option is LoadOptionNumberUnassigned.
189 @return Status codes of gRT->SetVariable ().
194 EfiBootManagerAddLoadOptionVariable (
195 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION
*Option
,
200 Delete the load option according to the OptionNumber and OptionType.
202 Only the BootOrder/DriverOrder is updated to remove the reference of the OptionNumber.
204 @param OptionNumber Option number of the load option.
205 @param OptionType Type of the load option.
207 @retval EFI_NOT_FOUND The load option cannot be found.
208 @retval EFI_SUCCESS The load option was deleted.
212 EfiBootManagerDeleteLoadOptionVariable (
213 IN UINTN OptionNumber
,
214 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
218 Sort the load options. The DriverOrder/BootOrder variables will be re-created to
219 reflect the new order.
221 @param OptionType The type of the load option.
222 @param CompareFunction The comparator function pointer.
226 EfiBootManagerSortLoadOptionVariable (
227 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
,
228 IN SORT_COMPARE CompareFunction
232 Return the index of the load option in the load option array.
234 The function consider two load options are equal when the
235 OptionType, Attributes, Description, FilePath and OptionalData are equal.
237 @param Key Pointer to the load option to be found.
238 @param Array Pointer to the array of load options to be found.
239 @param Count Number of entries in the Array.
241 @retval -1 Key wasn't found in the Array.
242 @retval 0 ~ Count-1 The index of the Key in the Array.
246 EfiBootManagerFindLoadOption (
247 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Key
,
248 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Array
,
253 // Boot Manager hot key library functions.
262 /// Specifies options about how the key will be processed.
264 EFI_BOOT_KEY_DATA KeyData
;
266 /// The CRC-32 which should match the CRC-32 of the entire EFI_LOAD_OPTION to
267 /// which BootOption refers. If the CRC-32s do not match this value, then this key
268 /// option is ignored.
270 UINT32 BootOptionCrc
;
272 /// The Boot#### option which will be invoked if this key is pressed and the boot option
273 /// is active (LOAD_OPTION_ACTIVE is set).
277 /// The key codes to compare against those returned by the
278 /// EFI_SIMPLE_TEXT_INPUT and EFI_SIMPLE_TEXT_INPUT_EX protocols.
279 /// The number of key codes (0-3) is specified by the EFI_KEY_CODE_COUNT field in KeyOptions.
281 EFI_INPUT_KEY Keys
[3];
283 } EFI_BOOT_MANAGER_KEY_OPTION
;
287 Start the hot key service so that the key press can trigger the boot option.
289 @param HotkeyTriggered Return the waitable event and it will be signaled
290 when a valid hot key is pressed.
292 @retval EFI_SUCCESS The hot key service is started.
296 EfiBootManagerStartHotkeyService (
297 IN EFI_EVENT
*HotkeyTriggered
301 // Modifier for EfiBootManagerAddKeyOptionVariable and EfiBootManagerDeleteKeyOptionVariable
303 #define EFI_BOOT_MANAGER_SHIFT_PRESSED 0x00000001
304 #define EFI_BOOT_MANAGER_CONTROL_PRESSED 0x00000002
305 #define EFI_BOOT_MANAGER_ALT_PRESSED 0x00000004
306 #define EFI_BOOT_MANAGER_LOGO_PRESSED 0x00000008
307 #define EFI_BOOT_MANAGER_MENU_KEY_PRESSED 0x00000010
308 #define EFI_BOOT_MANAGER_SYS_REQ_PRESSED 0x00000020
312 It adds the key option variable and the key option takes affect immediately.
314 @param AddedOption Return the added key option.
315 @param BootOptionNumber The boot option number for the key option.
316 @param Modifier Key shift state.
317 @param ... Parameter list of pointer of EFI_INPUT_KEY.
319 @retval EFI_SUCCESS The key option is added.
320 @retval EFI_ALREADY_STARTED The hot key is already used by certain key option.
324 EfiBootManagerAddKeyOptionVariable (
325 OUT EFI_BOOT_MANAGER_KEY_OPTION
*AddedOption
, OPTIONAL
326 IN UINT16 BootOptionNumber
,
332 Delete the Key Option variable and unregister the hot key
334 @param DeletedOption Return the deleted key options.
335 @param Modifier Key shift state.
336 @param ... Parameter list of pointer of EFI_INPUT_KEY.
338 @retval EFI_SUCCESS The key option is deleted.
339 @retval EFI_NOT_FOUND The key option cannot be found.
343 EfiBootManagerDeleteKeyOptionVariable (
344 IN EFI_BOOT_MANAGER_KEY_OPTION
*DeletedOption
, OPTIONAL
350 Register the key option to exit the waiting of the Boot Manager timeout.
351 Platform should ensure that the continue key option isn't conflict with
352 other boot key options.
354 @param Modifier Key shift state.
355 @param ... Parameter list of pointer of EFI_INPUT_KEY.
357 @retval EFI_SUCCESS Successfully register the continue key option.
358 @retval EFI_ALREADY_STARTED The continue key option is already registered.
362 EfiBootManagerRegisterContinueKeyOption (
368 Try to boot the boot option triggered by hot key.
372 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 (
602 // Boot Manager console library functions
616 This function will connect all the console devices base on the console
617 device variable ConIn, ConOut and ErrOut.
619 @retval EFI_DEVICE_ERROR All the consoles were not connected due to an error.
620 @retval EFI_SUCCESS Success connect any one instance of the console
621 device path base on the variable ConVarName.
625 EfiBootManagerConnectAllDefaultConsoles (
630 This function updates the console variable based on ConVarName. It can
631 add or remove one specific console device path from the variable
633 @param ConsoleType ConIn, ConOut, ErrOut, ConInDev, ConOutDev or ErrOutDev.
634 @param CustomizedConDevicePath The console device path to be added to
635 the console variable. Cannot be multi-instance.
636 @param ExclusiveDevicePath The console device path to be removed
637 from the console variable. Cannot be multi-instance.
639 @retval EFI_UNSUPPORTED The added device path is the same as a removed one.
640 @retval EFI_SUCCESS Successfully added or removed the device path from the
646 EfiBootManagerUpdateConsoleVariable (
647 IN CONSOLE_TYPE ConsoleType
,
648 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
649 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
653 Connect the console device base on the variable ConVarName, if
654 device path of the ConVarName is multi-instance device path, if
655 anyone of the instances is connected success, then this function
658 @param ConsoleType ConIn, ConOut or ErrOut.
660 @retval EFI_NOT_FOUND There is not any console devices connected
662 @retval EFI_SUCCESS Success connect any one instance of the console
663 device path base on the variable ConVarName.
668 EfiBootManagerConnectConsoleVariable (
669 IN CONSOLE_TYPE ConsoleType
673 Query all the children of VideoController and return the device paths of all the
674 children that support GraphicsOutput protocol.
676 @param VideoController PCI handle of video controller.
678 @return Device paths of all the children that support GraphicsOutput protocol.
680 EFI_DEVICE_PATH_PROTOCOL
*
682 EfiBootManagerGetGopDevicePath (
683 IN EFI_HANDLE VideoController
687 Connect the platform active active video controller.
689 @param VideoController PCI handle of video controller.
691 @retval EFI_NOT_FOUND There is no active video controller.
692 @retval EFI_SUCCESS The video controller is connected.
696 EfiBootManagerConnectVideoController (
697 EFI_HANDLE VideoController OPTIONAL
701 // Boot Manager driver health library functions.
705 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
708 /// Driver relative handles
710 EFI_HANDLE DriverHealthHandle
;
711 EFI_HANDLE ControllerHandle
;
712 EFI_HANDLE ChildHandle
;
715 /// Driver health messages of the specify Driver
717 EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
;
720 /// HII relative handles
722 EFI_HII_HANDLE HiiHandle
;
725 /// Driver Health status
727 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
728 } EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
;
731 Return all the Driver Health information.
733 When the cumulative health status of all the controllers managed by the
734 driver who produces the EFI_DRIVER_HEALTH_PROTOCOL is healthy, only one
735 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO entry is created for such
736 EFI_DRIVER_HEALTH_PROTOCOL instance.
737 Otherwise, every controller creates one EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
738 entry. Additionally every child controller creates one
739 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO entry if the driver is a bus driver.
741 @param Count Return the count of the Driver Health information.
743 @retval NULL No Driver Health information is returned.
744 @retval !NULL Pointer to the Driver Health information array.
746 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
*
748 EfiBootManagerGetDriverHealthInfo (
753 Free the Driver Health information array.
755 @param DriverHealthInfo Pointer to array of the Driver Health information.
756 @param Count Count of the array.
758 @retval EFI_SUCCESS The array is freed.
759 @retval EFI_INVALID_PARAMETER The array is NULL.
763 EfiBootManagerFreeDriverHealthInfo (
764 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
*DriverHealthInfo
,
769 Process (load and execute) the load option.
771 @param LoadOption Pointer to the load option.
773 @retval EFI_INVALID_PARAMETER The load option type is invalid,
774 or the load option file path doesn't point to a valid file.
775 @retval EFI_UNSUPPORTED The load option type is of LoadOptionTypeBoot.
776 @retval EFI_SUCCESS The load option is inactive, or successfully loaded and executed.
780 EfiBootManagerProcessLoadOption (
781 EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
785 Check whether the VariableName is a valid load option variable name
786 and return the load option type and option number.
788 @param VariableName The name of the load option variable.
789 @param OptionType Return the load option type.
790 @param OptionNumber Return the load option number.
792 @retval TRUE The variable name is valid; The load option type and
793 load option number are returned.
794 @retval FALSE The variable name is NOT valid.
798 EfiBootManagerIsValidLoadOptionVariableName (
799 IN CHAR16
*VariableName
,
800 OUT EFI_BOOT_MANAGER_LOAD_OPTION_TYPE
*OptionType OPTIONAL
,
801 OUT UINT16
*OptionNumber OPTIONAL
806 Dispatch the deferred images that are returned from all DeferredImageLoad instances.
808 @retval EFI_SUCCESS At least one deferred image is loaded successfully and started.
809 @retval EFI_NOT_FOUND There is no deferred image.
810 @retval EFI_ACCESS_DENIED There are deferred images but all of them are failed to load.
814 EfiBootManagerDispatchDeferredImages (