2 This file include all platform action which can be customized
5 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "PlatformBootManager.h"
11 #include "PlatformConsole.h"
20 EFI_SMM_ACCESS2_PROTOCOL
*SmmAccess
;
22 DEBUG((DEBUG_INFO
,"InstallReadyToLock entering......\n"));
24 // Inform the SMM infrastructure that we're entering BDS and may run 3rd party code hereafter
25 // Since PI1.2.1, we need signal EndOfDxe as ExitPmAuth
27 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid
);
28 DEBUG((DEBUG_INFO
,"All EndOfDxe callbacks have returned successfully\n"));
31 // Install DxeSmmReadyToLock protocol in order to lock SMM
33 Status
= gBS
->LocateProtocol (&gEfiSmmAccess2ProtocolGuid
, NULL
, (VOID
**) &SmmAccess
);
34 if (!EFI_ERROR (Status
)) {
36 Status
= gBS
->InstallProtocolInterface (
38 &gEfiDxeSmmReadyToLockProtocolGuid
,
42 ASSERT_EFI_ERROR (Status
);
45 DEBUG((DEBUG_INFO
,"InstallReadyToLock end\n"));
50 Return the index of the load option in the load option array.
52 The function consider two load options are equal when the
53 OptionType, Attributes, Description, FilePath and OptionalData are equal.
55 @param Key Pointer to the load option to be found.
56 @param Array Pointer to the array of load options to be found.
57 @param Count Number of entries in the Array.
59 @retval -1 Key wasn't found in the Array.
60 @retval 0 ~ Count-1 The index of the Key in the Array.
63 PlatformFindLoadOption (
64 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Key
,
65 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Array
,
71 for (Index
= 0; Index
< Count
; Index
++) {
72 if ((Key
->OptionType
== Array
[Index
].OptionType
) &&
73 (Key
->Attributes
== Array
[Index
].Attributes
) &&
74 (StrCmp (Key
->Description
, Array
[Index
].Description
) == 0) &&
75 (CompareMem (Key
->FilePath
, Array
[Index
].FilePath
, GetDevicePathSize (Key
->FilePath
)) == 0) &&
76 (Key
->OptionalDataSize
== Array
[Index
].OptionalDataSize
) &&
77 (CompareMem (Key
->OptionalData
, Array
[Index
].OptionalData
, Key
->OptionalDataSize
) == 0)) {
86 Register a boot option using a file GUID in the FV.
88 @param FileGuid The file GUID name in FV.
89 @param Description The boot option description.
90 @param Attributes The attributes used for the boot option loading.
93 PlatformRegisterFvBootOption (
101 EFI_BOOT_MANAGER_LOAD_OPTION NewOption
;
102 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
;
103 UINTN BootOptionCount
;
104 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode
;
105 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
106 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
108 Status
= gBS
->HandleProtocol (gImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**) &LoadedImage
);
109 ASSERT_EFI_ERROR (Status
);
111 EfiInitializeFwVolDevicepathNode (&FileNode
, FileGuid
);
112 DevicePath
= AppendDevicePathNode (
113 DevicePathFromHandle (LoadedImage
->DeviceHandle
),
114 (EFI_DEVICE_PATH_PROTOCOL
*) &FileNode
117 Status
= EfiBootManagerInitializeLoadOption (
119 LoadOptionNumberUnassigned
,
127 if (!EFI_ERROR (Status
)) {
128 BootOptions
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
130 OptionIndex
= PlatformFindLoadOption (&NewOption
, BootOptions
, BootOptionCount
);
132 if (OptionIndex
== -1) {
133 Status
= EfiBootManagerAddLoadOptionVariable (&NewOption
, (UINTN
) -1);
134 ASSERT_EFI_ERROR (Status
);
136 EfiBootManagerFreeLoadOption (&NewOption
);
137 EfiBootManagerFreeLoadOptions (BootOptions
, BootOptionCount
);
142 Do the platform specific action before the console is connected.
145 Update console variable;
146 Register new Driver#### or Boot####;
147 Signal ReadyToLock event.
151 PlatformBootManagerBeforeConsole (
158 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
161 // Register ENTER as CONTINUE key
163 Enter
.ScanCode
= SCAN_NULL
;
164 Enter
.UnicodeChar
= CHAR_CARRIAGE_RETURN
;
165 EfiBootManagerRegisterContinueKeyOption (0, &Enter
, NULL
);
168 // Map F2 to Boot Manager Menu
170 F2
.ScanCode
= SCAN_F2
;
171 F2
.UnicodeChar
= CHAR_NULL
;
172 EfiBootManagerGetBootManagerMenu (&BootOption
);
173 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
) BootOption
.OptionNumber
, 0, &F2
, NULL
);
176 // Also add Down key to Boot Manager Menu since some serial terminals don't support F2 key.
178 Down
.ScanCode
= SCAN_DOWN
;
179 Down
.UnicodeChar
= CHAR_NULL
;
180 EfiBootManagerGetBootManagerMenu (&BootOption
);
181 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
) BootOption
.OptionNumber
, 0, &Down
, NULL
);
184 // Install ready to lock.
185 // This needs to be done before option rom dispatched.
187 InstallReadyToLock ();
190 // Dispatch deferred images after EndOfDxe event and ReadyToLock installation.
192 EfiBootManagerDispatchDeferredImages ();
194 PlatformConsoleInit ();
198 Do the platform specific action after the console is connected.
201 Dynamically switch output mode;
202 Signal console ready platform customized event;
203 Run diagnostics like memory testing;
204 Connect certain devices;
205 Dispatch additional option roms.
209 PlatformBootManagerAfterConsole (
213 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black
;
214 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White
;
216 Black
.Blue
= Black
.Green
= Black
.Red
= Black
.Reserved
= 0;
217 White
.Blue
= White
.Green
= White
.Red
= White
.Reserved
= 0xFF;
219 EfiBootManagerConnectAll ();
220 EfiBootManagerRefreshAllBootOption ();
223 // Register UEFI Shell
225 PlatformRegisterFvBootOption (PcdGetPtr (PcdShellFile
), L
"UEFI Shell", LOAD_OPTION_ACTIVE
);
229 L
"F2 or Down to enter Boot Manager Menu.\n"
230 L
"ENTER to boot directly.\n"
237 This function is called each second during the boot manager waits the timeout.
239 @param TimeoutRemain The remaining timeout.
243 PlatformBootManagerWaitCallback (
251 The function is called when no boot option could be launched,
252 including platform recovery options and options pointing to applications
253 built into firmware volumes.
255 If this function returns, BDS attempts to enter an infinite loop.
259 PlatformBootManagerUnableToBoot (