2 This file include all platform action which can be customized
5 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "PlatformBootManager.h"
17 #include "PlatformConsole.h"
26 EFI_SMM_ACCESS2_PROTOCOL
*SmmAccess
;
28 DEBUG((DEBUG_INFO
,"InstallReadyToLock entering......\n"));
30 // Inform the SMM infrastructure that we're entering BDS and may run 3rd party code hereafter
31 // Since PI1.2.1, we need signal EndOfDxe as ExitPmAuth
33 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid
);
34 DEBUG((DEBUG_INFO
,"All EndOfDxe callbacks have returned successfully\n"));
37 // Install DxeSmmReadyToLock protocol in order to lock SMM
39 Status
= gBS
->LocateProtocol (&gEfiSmmAccess2ProtocolGuid
, NULL
, (VOID
**) &SmmAccess
);
40 if (!EFI_ERROR (Status
)) {
42 Status
= gBS
->InstallProtocolInterface (
44 &gEfiDxeSmmReadyToLockProtocolGuid
,
48 ASSERT_EFI_ERROR (Status
);
51 DEBUG((DEBUG_INFO
,"InstallReadyToLock end\n"));
56 Return the index of the load option in the load option array.
58 The function consider two load options are equal when the
59 OptionType, Attributes, Description, FilePath and OptionalData are equal.
61 @param Key Pointer to the load option to be found.
62 @param Array Pointer to the array of load options to be found.
63 @param Count Number of entries in the Array.
65 @retval -1 Key wasn't found in the Array.
66 @retval 0 ~ Count-1 The index of the Key in the Array.
69 PlatformFindLoadOption (
70 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Key
,
71 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION
*Array
,
77 for (Index
= 0; Index
< Count
; Index
++) {
78 if ((Key
->OptionType
== Array
[Index
].OptionType
) &&
79 (Key
->Attributes
== Array
[Index
].Attributes
) &&
80 (StrCmp (Key
->Description
, Array
[Index
].Description
) == 0) &&
81 (CompareMem (Key
->FilePath
, Array
[Index
].FilePath
, GetDevicePathSize (Key
->FilePath
)) == 0) &&
82 (Key
->OptionalDataSize
== Array
[Index
].OptionalDataSize
) &&
83 (CompareMem (Key
->OptionalData
, Array
[Index
].OptionalData
, Key
->OptionalDataSize
) == 0)) {
92 Register a boot option using a file GUID in the FV.
94 @param FileGuid The file GUID name in FV.
95 @param Description The boot option description.
96 @param Attributes The attributes used for the boot option loading.
99 PlatformRegisterFvBootOption (
107 EFI_BOOT_MANAGER_LOAD_OPTION NewOption
;
108 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
;
109 UINTN BootOptionCount
;
110 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode
;
111 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
112 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
114 Status
= gBS
->HandleProtocol (gImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**) &LoadedImage
);
115 ASSERT_EFI_ERROR (Status
);
117 EfiInitializeFwVolDevicepathNode (&FileNode
, FileGuid
);
118 DevicePath
= AppendDevicePathNode (
119 DevicePathFromHandle (LoadedImage
->DeviceHandle
),
120 (EFI_DEVICE_PATH_PROTOCOL
*) &FileNode
123 Status
= EfiBootManagerInitializeLoadOption (
125 LoadOptionNumberUnassigned
,
133 if (!EFI_ERROR (Status
)) {
134 BootOptions
= EfiBootManagerGetLoadOptions (&BootOptionCount
, LoadOptionTypeBoot
);
136 OptionIndex
= PlatformFindLoadOption (&NewOption
, BootOptions
, BootOptionCount
);
138 if (OptionIndex
== -1) {
139 Status
= EfiBootManagerAddLoadOptionVariable (&NewOption
, (UINTN
) -1);
140 ASSERT_EFI_ERROR (Status
);
142 EfiBootManagerFreeLoadOption (&NewOption
);
143 EfiBootManagerFreeLoadOptions (BootOptions
, BootOptionCount
);
148 Do the platform specific action before the console is connected.
151 Update console variable;
152 Register new Driver#### or Boot####;
153 Signal ReadyToLock event.
157 PlatformBootManagerBeforeConsole (
164 EFI_BOOT_MANAGER_LOAD_OPTION BootOption
;
166 PlatformConsoleInit ();
169 // Register ENTER as CONTINUE key
171 Enter
.ScanCode
= SCAN_NULL
;
172 Enter
.UnicodeChar
= CHAR_CARRIAGE_RETURN
;
173 EfiBootManagerRegisterContinueKeyOption (0, &Enter
, NULL
);
176 // Map F2 to Boot Manager Menu
178 F2
.ScanCode
= SCAN_F2
;
179 F2
.UnicodeChar
= CHAR_NULL
;
180 EfiBootManagerGetBootManagerMenu (&BootOption
);
181 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
) BootOption
.OptionNumber
, 0, &F2
, NULL
);
184 // Also add Down key to Boot Manager Menu since some serial terminals don't support F2 key.
186 Down
.ScanCode
= SCAN_DOWN
;
187 Down
.UnicodeChar
= CHAR_NULL
;
188 EfiBootManagerGetBootManagerMenu (&BootOption
);
189 EfiBootManagerAddKeyOptionVariable (NULL
, (UINT16
) BootOption
.OptionNumber
, 0, &Down
, NULL
);
192 // Install ready to lock.
193 // This needs to be done before option rom dispatched.
195 InstallReadyToLock ();
198 // Dispatch deferred images after EndOfDxe event and ReadyToLock installation.
200 EfiBootManagerDispatchDeferredImages ();
204 Do the platform specific action after the console is connected.
207 Dynamically switch output mode;
208 Signal console ready platform customized event;
209 Run diagnostics like memory testing;
210 Connect certain devices;
211 Dispatch aditional option roms.
215 PlatformBootManagerAfterConsole (
219 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black
;
220 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White
;
222 Black
.Blue
= Black
.Green
= Black
.Red
= Black
.Reserved
= 0;
223 White
.Blue
= White
.Green
= White
.Red
= White
.Reserved
= 0xFF;
225 EfiBootManagerConnectAll ();
226 EfiBootManagerRefreshAllBootOption ();
229 // Register UEFI Shell
231 PlatformRegisterFvBootOption (PcdGetPtr (PcdShellFile
), L
"UEFI Shell", LOAD_OPTION_ACTIVE
);
235 L
"F2 or Down to enter Boot Manager Menu.\n"
236 L
"ENTER to boot directly.\n"
243 This function is called each second during the boot manager waits the timeout.
245 @param TimeoutRemain The remaining timeout.
249 PlatformBootManagerWaitCallback (