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.
31 LoadOptionTypeSysPrep
,
34 } EFI_BOOT_MANAGER_LOAD_OPTION_TYPE
;
37 LoadOptionNumberMax
= 0x10000,
38 LoadOptionNumberUnassigned
= LoadOptionNumberMax
39 } EFI_BOOT_MANAGER_LOAD_OPTION_NUMBER
;
42 // Common structure definition for DriverOption and BootOption
46 // Data read from UEFI NV variables
48 UINTN OptionNumber
; // #### numerical value, could be LoadOptionNumberUnassigned
49 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
; // LoadOptionTypeBoot or LoadOptionTypeDriver
50 UINT32 Attributes
; // Load Option Attributes
51 CHAR16
*Description
; // Load Option Description
52 EFI_DEVICE_PATH_PROTOCOL
*FilePath
; // Load Option Device Path
53 UINT8
*OptionalData
; // Load Option optional data to pass into image
54 UINT32 OptionalDataSize
; // Load Option size of OptionalData
60 EFI_STATUS Status
; // Status returned from boot attempt gBS->StartImage ()
61 CHAR16
*ExitData
; // Exit data returned from gBS->StartImage ()
62 UINTN ExitDataSize
; // Size of ExitData
63 } EFI_BOOT_MANAGER_LOAD_OPTION
;
66 Returns an array of load options based on the EFI variable
67 L"BootOrder"/L"DriverOrder" and the L"Boot####"/L"Driver####" variables impled by it.
68 #### is the hex value of the UINT16 in each BootOrder/DriverOrder entry.
70 @param LoadOptionCount Returns number of entries in the array.
71 @param LoadOptionType The type of the load option.
73 @retval NULL No load options exist.
74 @retval !NULL Array of load option entries.
77 EFI_BOOT_MANAGER_LOAD_OPTION
*
79 EfiBootManagerGetLoadOptions (
80 OUT UINTN
*LoadOptionCount
,
81 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
85 Free an array of load options returned from EfiBootManagerGetLoadOptions().
87 @param LoadOptions Pointer to the array of load options to free.
88 @param LoadOptionCount Number of array entries in LoadOptions.
90 @return EFI_SUCCESS LoadOptions was freed.
91 @return EFI_INVALID_PARAMETER LoadOptions is NULL.
95 EfiBootManagerFreeLoadOptions (
96 IN EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOptions
,
97 IN UINTN LoadOptionCount
101 Initialize a load option.
103 @param Option Pointer to the load option to be initialized.
104 @param OptionNumber Option number of the load option.
105 @param OptionType Type of the load option.
106 @param Attributes Attributes of the load option.
107 @param Description Description of the load option.
108 @param FilePath Device path of the load option.
109 @param OptionalData Optional data of the load option.
110 @param OptionalDataSize Size of the optional data of the load option.
112 @retval EFI_SUCCESS The load option was initialized successfully.
113 @retval EFI_INVALID_PARAMETER Option, Description or FilePath is NULL.
117 EfiBootManagerInitializeLoadOption (
118 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION
*Option
,
119 IN UINTN OptionNumber
,
120 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
,
121 IN UINT32 Attributes
,
122 IN CHAR16
*Description
,
123 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
124 IN UINT8
*OptionalData
,
125 IN UINT32 OptionalDataSize
129 Free a load option created by EfiBootManagerInitializeLoadOption()
130 or EfiBootManagerVariableToLoadOption().
132 @param LoadOption Pointer to the load option to free.
133 CONCERN: Check Boot#### instead of BootOrder, optimize, spec clarify
134 @return EFI_SUCCESS LoadOption was freed.
135 @return EFI_INVALID_PARAMETER LoadOption is NULL.
140 EfiBootManagerFreeLoadOption (
141 IN EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
145 Initialize the load option from the VariableName.
147 @param VariableName EFI Variable name which could be Boot#### or
149 @param LoadOption Pointer to the load option to be initialized
151 @retval EFI_SUCCESS The option was created
152 @retval EFI_INVALID_PARAMETER VariableName or LoadOption is NULL.
153 @retval EFI_NOT_FOUND The variable specified by VariableName cannot be found.
157 EfiBootManagerVariableToLoadOption (
158 IN CHAR16
*VariableName
,
159 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
163 Create the Boot#### or Driver#### variable from the load option.
165 @param LoadOption Pointer to the load option.
167 @retval EFI_SUCCESS The variable was created.
168 @retval Others Error status returned by RT->SetVariable.
172 EfiBootManagerLoadOptionToVariable (
173 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption
177 This function will update the Boot####/Driver####/SysPrep#### and the
178 BootOrder/DriverOrder/SysPrepOrder to add a new load option.
180 @param Option Pointer to load option to add.
181 @param Position Position of the new load option to put in the BootOrder/DriverOrder/SysPrepOrder.
183 @retval EFI_SUCCESS The load option has been successfully added.
184 @retval Others Error status returned by RT->SetVariable.
188 EfiBootManagerAddLoadOptionVariable (
189 IN EFI_BOOT_MANAGER_LOAD_OPTION
*Option
,
194 Delete the load option according to the OptionNumber and OptionType.
196 Only the BootOrder/DriverOrder is updated to remove the reference of the OptionNumber.
198 @param OptionNumber Option number of the load option.
199 @param OptionType Type of the load option.
201 @retval EFI_NOT_FOUND The load option cannot be found.
202 @retval EFI_SUCCESS The load option was deleted.
206 EfiBootManagerDeleteLoadOptionVariable (
207 IN UINTN OptionNumber
,
208 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
212 Sort the load options. The DriverOrder/BootOrder variables will be re-created to
213 reflect the new order.
215 @param OptionType The type of the load option.
216 @param Comparator The comparator function pointer.
220 EfiBootManagerSortLoadOptionVariable (
221 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
,
222 IN SORT_COMPARE CompareFunction
226 // Boot Manager hot key library functions.
235 /// Specifies options about how the key will be processed.
237 EFI_BOOT_KEY_DATA KeyData
;
239 /// The CRC-32 which should match the CRC-32 of the entire EFI_LOAD_OPTION to
240 /// which BootOption refers. If the CRC-32s do not match this value, then this key
241 /// option is ignored.
243 UINT32 BootOptionCrc
;
245 /// The Boot#### option which will be invoked if this key is pressed and the boot option
246 /// is active (LOAD_OPTION_ACTIVE is set).
250 /// The key codes to compare against those returned by the
251 /// EFI_SIMPLE_TEXT_INPUT and EFI_SIMPLE_TEXT_INPUT_EX protocols.
252 /// The number of key codes (0-3) is specified by the EFI_KEY_CODE_COUNT field in KeyOptions.
254 EFI_INPUT_KEY Keys
[3];
256 } EFI_BOOT_MANAGER_KEY_OPTION
;
260 Start the hot key service so that the key press can trigger the boot option.
262 @param HotkeyTriggered Return the waitable event and it will be signaled
263 when a valid hot key is pressed.
265 @retval EFI_SUCCESS The hot key service is started.
269 EfiBootManagerStartHotkeyService (
270 IN EFI_EVENT
*HotkeyTriggered
274 // Modifier for EfiBootManagerAddKeyOptionVariable and EfiBootManagerDeleteKeyOptionVariable
276 #define EFI_BOOT_MANAGER_SHIFT_PRESSED 0x00000001
277 #define EFI_BOOT_MANAGER_CONTROL_PRESSED 0x00000002
278 #define EFI_BOOT_MANAGER_ALT_PRESSED 0x00000004
279 #define EFI_BOOT_MANAGER_LOGO_PRESSED 0x00000008
280 #define EFI_BOOT_MANAGER_MENU_KEY_PRESSED 0x00000010
281 #define EFI_BOOT_MANAGER_SYS_REQ_PRESSED 0x00000020
285 It adds the key option variable and the key option takes affect immediately.
287 @param AddedOption Return the added key option.
288 @param BootOptionNumber The boot option number for the key option.
289 @param Modifier Key shift state.
290 @param ... Parameter list of pointer of EFI_INPUT_KEY.
292 @retval EFI_SUCCESS The key option is added.
293 @retval EFI_ALREADY_STARTED The hot key is already used by certain key option.
297 EfiBootManagerAddKeyOptionVariable (
298 OUT EFI_BOOT_MANAGER_KEY_OPTION
*AddedOption
, OPTIONAL
299 IN UINT16 BootOptionNumber
,
305 Delete the Key Option variable and unregister the hot key
307 @param DeletedOption Return the deleted key options.
308 @param Modifier Key shift state.
309 @param ... Parameter list of pointer of EFI_INPUT_KEY.
311 @retval EFI_SUCCESS The key option is deleted.
312 @retval EFI_NOT_FOUND The key option cannot be found.
316 EfiBootManagerDeleteKeyOptionVariable (
317 IN EFI_BOOT_MANAGER_KEY_OPTION
*DeletedOption
, OPTIONAL
323 Register the key option to exit the waiting of the Boot Manager timeout.
324 Platform should ensure that the continue key option isn't conflict with
325 other boot key options.
327 @param Modifier Key shift state.
328 @param ... Parameter list of pointer of EFI_INPUT_KEY.
330 @retval EFI_SUCCESS Successfully register the continue key option.
331 @retval EFI_ALREADY_STARTED The continue key option is already registered.
335 EfiBootManagerRegisterContinueKeyOption (
341 Try to boot the boot option triggered by hot key.
345 EfiBootManagerHotkeyBoot (
349 // Boot Manager boot library functions.
353 The function creates boot options for all possible bootable medias in the following order:
354 1. Removable BlockIo - The boot option only points to the removable media
355 device, like USB key, DVD, Floppy etc.
356 2. Fixed BlockIo - The boot option only points to a Fixed blockIo device,
358 3. Non-BlockIo SimpleFileSystem - The boot option points to a device supporting
359 SimpleFileSystem Protocol, but not supporting BlockIo
361 4. LoadFile - The boot option points to the media supporting
363 Reference: UEFI Spec chapter 3.3 Boot Option Variables Default Boot Behavior
365 The function won't delete the boot option not added by itself.
369 EfiBootManagerRefreshAllBootOption (
374 Attempt to boot the EFI boot option. This routine sets L"BootCurent" and
375 signals the EFI ready to boot event. If the device path for the option starts
376 with a BBS device path a legacy boot is attempted. Short form device paths are
377 also supported via this rountine. A device path starting with
378 MEDIA_HARDDRIVE_DP, MSG_USB_WWID_DP, MSG_USB_CLASS_DP gets expaned out
379 to find the first device that matches. If the BootOption Device Path
380 fails the removable media boot algorithm is attempted (\EFI\BOOTIA32.EFI,
381 \EFI\BOOTX64.EFI,... only one file type is tried per processor type)
383 @param BootOption Boot Option to try and boot.
384 On return, BootOption->Status contains the boot status:
385 EFI_SUCCESS BootOption was booted
386 EFI_UNSUPPORTED BootOption isn't supported.
387 EFI_NOT_FOUND The BootOption was not found on the system
388 Others BootOption failed with this error status
394 IN EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
398 Return the Boot Manager Menu.
400 @param BootOption Return the Boot Manager Menu.
402 @retval EFI_SUCCESS The Boot Manager Menu is successfully returned.
403 @retval EFI_NOT_FOUND The Boot Manager Menu is not found.
407 EfiBootManagerGetBootManagerMenu (
408 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
412 The function enumerates all the legacy boot options, creates them and
413 registers them in the BootOrder variable.
417 (EFIAPI
*EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION
) (
422 The function boots a legacy boot option.
426 (EFIAPI
*EFI_BOOT_MANAGER_LEGACY_BOOT
) (
427 IN EFI_BOOT_MANAGER_LOAD_OPTION
*BootOption
431 The function registers the legacy boot support capabilities.
433 @param RefreshLegacyBootOption The function pointer to create all the legacy boot options.
434 @param LegacyBoot The function pointer to boot the legacy boot option.
438 EfiBootManagerRegisterLegacyBootSupport (
439 EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION RefreshLegacyBootOption
,
440 EFI_BOOT_MANAGER_LEGACY_BOOT LegacyBoot
445 // Boot Manager connect and disconnect library functions
449 This function will connect all the system driver to controller
450 first, and then special connect the default console, this make
451 sure all the system controller available and the platform default
456 EfiBootManagerConnectAll (
461 This function will create all handles associate with every device
462 path node. If the handle associate with one device path node can not
463 be created successfully, then still give chance to do the dispatch,
464 which load the missing drivers if possible.
466 @param DevicePathToConnect The device path which will be connected, it can be
467 a multi-instance device path
468 @param MatchingHandle Return the controller handle closest to the DevicePathToConnect
470 @retval EFI_SUCCESS All handles associate with every device path node
472 @retval EFI_OUT_OF_RESOURCES There is no resource to create new handles.
473 @retval EFI_NOT_FOUND Create the handle associate with one device path
475 @retval EFI_SECURITY_VIOLATION The user has no permission to start UEFI device
476 drivers on the DevicePath.
480 EfiBootManagerConnectDevicePath (
481 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathToConnect
,
482 OUT EFI_HANDLE
*MatchingHandle OPTIONAL
486 This function will disconnect all current system handles.
488 gBS->DisconnectController() is invoked for each handle exists in system handle buffer.
489 If handle is a bus type handle, all childrens also are disconnected recursively by
490 gBS->DisconnectController().
494 EfiBootManagerDisconnectAll (
500 // Boot Manager console library functions
514 This function will connect all the console devices base on the console
515 device variable ConIn, ConOut and ErrOut.
517 @retval EFI_DEVICE_ERROR All the consoles were not connected due to an error.
518 @retval EFI_SUCCESS Success connect any one instance of the console
519 device path base on the variable ConVarName.
523 EfiBootManagerConnectAllDefaultConsoles (
528 This function updates the console variable based on ConVarName. It can
529 add or remove one specific console device path from the variable
531 @param ConsoleType ConIn, ConOut, ErrOut, ConInDev, ConOutDev or ErrOutDev.
532 @param CustomizedConDevicePath The console device path to be added to
533 the console variable. Cannot be multi-instance.
534 @param ExclusiveDevicePath The console device path to be removed
535 from the console variable. Cannot be multi-instance.
537 @retval EFI_UNSUPPORTED The added device path is the same as a removed one.
538 @retval EFI_SUCCESS Successfully added or removed the device path from the
544 EfiBootManagerUpdateConsoleVariable (
545 IN CONSOLE_TYPE ConsoleType
,
546 IN EFI_DEVICE_PATH_PROTOCOL
*CustomizedConDevicePath
,
547 IN EFI_DEVICE_PATH_PROTOCOL
*ExclusiveDevicePath
551 Connect the console device base on the variable ConVarName, if
552 device path of the ConVarName is multi-instance device path, if
553 anyone of the instances is connected success, then this function
556 @param ConsoleType ConIn, ConOut or ErrOut.
558 @retval EFI_NOT_FOUND There is not any console devices connected
560 @retval EFI_SUCCESS Success connect any one instance of the console
561 device path base on the variable ConVarName.
566 EfiBootManagerConnectConsoleVariable (
567 IN CONSOLE_TYPE ConsoleType
571 Query all the children of VideoController and return the device paths of all the
572 children that support GraphicsOutput protocol.
574 @param VideoController PCI handle of video controller.
576 @return Device paths of all the children that support GraphicsOutput protocol.
578 EFI_DEVICE_PATH_PROTOCOL
*
580 EfiBootManagerGetGopDevicePath (
581 IN EFI_HANDLE VideoController
585 Connect the platform active active video controller.
587 @param VideoController PCI handle of video controller.
589 @retval EFI_NOT_FOUND There is no active video controller.
590 @retval EFI_SUCCESS The video controller is connected.
594 EfiBootManagerConnectVideoController (
595 EFI_HANDLE VideoController OPTIONAL
599 // Boot Manager driver health library functions.
603 EFI_DRIVER_HEALTH_PROTOCOL
*DriverHealth
;
606 /// Driver relative handles
608 EFI_HANDLE DriverHealthHandle
;
609 EFI_HANDLE ControllerHandle
;
610 EFI_HANDLE ChildHandle
;
613 /// Driver health messages of the specify Driver
615 EFI_DRIVER_HEALTH_HII_MESSAGE
*MessageList
;
618 /// HII relative handles
620 EFI_HII_HANDLE HiiHandle
;
623 /// Driver Health status
625 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
626 } EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
;
629 Return all the Driver Health information.
631 When the cumulative health status of all the controllers managed by the
632 driver who produces the EFI_DRIVER_HEALTH_PROTOCOL is healthy, only one
633 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO entry is created for such
634 EFI_DRIVER_HEALTH_PROTOCOL instance.
635 Otherwise, every controller creates one EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
636 entry. Additionally every child controller creates one
637 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO entry if the driver is a bus driver.
639 @param Count Return the count of the Driver Health information.
641 @retval NULL No Driver Health information is returned.
642 @retval !NULL Pointer to the Driver Health information array.
644 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
*
646 EfiBootManagerGetDriverHealthInfo (
651 Free the Driver Health information array.
653 @param DriverHealthInfo Pointer to array of the Driver Health information.
654 @param Count Count of the array.
656 @retval EFI_SUCCESS The array is freed.
657 @retval EFI_INVALID_PARAMETER The array is NULL.
661 EfiBootManagerFreeDriverHealthInfo (
662 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
*DriverHealthInfo
,
667 Process (load and execute) the load option.
669 @param LoadOption Pointer to the load option.
671 @retval EFI_INVALID_PARAMETER The load option type is invalid,
672 or the load option file path doesn't point to a valid file.
673 @retval EFI_UNSUPPORTED The load option type is of LoadOptionTypeBoot.
674 @retval EFI_SUCCESS The load option is inactive, or successfully loaded and executed.
678 EfiBootManagerProcessLoadOption (
679 EFI_BOOT_MANAGER_LOAD_OPTION
*LoadOption