]> git.proxmox.com Git - mirror_edk2.git/blame - CorebootPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
IntelFrameworkModulePkg: Use EfiEventEmptyFunction from UefiLib
[mirror_edk2.git] / CorebootPayloadPkg / Library / PlatformBootManagerLib / PlatformBootManager.c
CommitLineData
42a8f2ce
MM
1/** @file\r
2 This file include all platform action which can be customized\r
3 by IBV/OEM.\r
4\r
c46bf81d 5Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
42a8f2ce
MM
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "PlatformBootManager.h"\r
17#include "PlatformConsole.h"\r
18\r
c46bf81d 19VOID\r
20EFIAPI\r
21InternalBdsEmptyCallbackFuntion (\r
22 IN EFI_EVENT Event,\r
23 IN VOID *Context\r
24 )\r
25{\r
26 return;\r
27}\r
28\r
29VOID\r
30InstallReadyToLock (\r
31 VOID\r
32 )\r
33{\r
34 EFI_STATUS Status;\r
35 EFI_HANDLE Handle;\r
36 EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r
37 EFI_EVENT EndOfDxeEvent;\r
38\r
39 DEBUG((DEBUG_INFO,"InstallReadyToLock entering......\n"));\r
40 //\r
41 // Inform the SMM infrastructure that we're entering BDS and may run 3rd party code hereafter\r
42 // Since PI1.2.1, we need signal EndOfDxe as ExitPmAuth\r
43 //\r
44 Status = gBS->CreateEventEx (\r
45 EVT_NOTIFY_SIGNAL,\r
46 TPL_CALLBACK,\r
47 InternalBdsEmptyCallbackFuntion,\r
48 NULL,\r
49 &gEfiEndOfDxeEventGroupGuid,\r
50 &EndOfDxeEvent\r
51 );\r
52 ASSERT_EFI_ERROR (Status);\r
53 gBS->SignalEvent (EndOfDxeEvent);\r
54 gBS->CloseEvent (EndOfDxeEvent);\r
55 DEBUG((DEBUG_INFO,"All EndOfDxe callbacks have returned successfully\n"));\r
56\r
57 //\r
58 // Install DxeSmmReadyToLock protocol in order to lock SMM\r
59 //\r
60 Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **) &SmmAccess);\r
61 if (!EFI_ERROR (Status)) {\r
62 Handle = NULL;\r
63 Status = gBS->InstallProtocolInterface (\r
64 &Handle,\r
65 &gEfiDxeSmmReadyToLockProtocolGuid,\r
66 EFI_NATIVE_INTERFACE,\r
67 NULL\r
68 );\r
69 ASSERT_EFI_ERROR (Status);\r
70 }\r
71\r
72 DEBUG((DEBUG_INFO,"InstallReadyToLock end\n"));\r
73 return;\r
74}\r
75\r
42a8f2ce
MM
76/**\r
77 Return the index of the load option in the load option array.\r
78\r
79 The function consider two load options are equal when the\r
80 OptionType, Attributes, Description, FilePath and OptionalData are equal.\r
81\r
82 @param Key Pointer to the load option to be found.\r
83 @param Array Pointer to the array of load options to be found.\r
84 @param Count Number of entries in the Array.\r
85\r
86 @retval -1 Key wasn't found in the Array.\r
87 @retval 0 ~ Count-1 The index of the Key in the Array.\r
88**/\r
89INTN\r
90PlatformFindLoadOption (\r
91 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key,\r
92 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array,\r
93 IN UINTN Count\r
94)\r
95{\r
96 UINTN Index;\r
97\r
98 for (Index = 0; Index < Count; Index++) {\r
99 if ((Key->OptionType == Array[Index].OptionType) &&\r
100 (Key->Attributes == Array[Index].Attributes) &&\r
101 (StrCmp (Key->Description, Array[Index].Description) == 0) &&\r
102 (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize (Key->FilePath)) == 0) &&\r
103 (Key->OptionalDataSize == Array[Index].OptionalDataSize) &&\r
104 (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->OptionalDataSize) == 0)) {\r
105 return (INTN) Index;\r
106 }\r
107 }\r
108\r
109 return -1;\r
110}\r
111\r
112/**\r
113 Register a boot option using a file GUID in the FV.\r
114\r
115 @param FileGuid The file GUID name in FV.\r
116 @param Description The boot option description.\r
117 @param Attributes The attributes used for the boot option loading.\r
118**/\r
119VOID\r
120PlatformRegisterFvBootOption (\r
121 EFI_GUID *FileGuid,\r
122 CHAR16 *Description,\r
123 UINT32 Attributes\r
124)\r
125{\r
126 EFI_STATUS Status;\r
127 UINTN OptionIndex;\r
128 EFI_BOOT_MANAGER_LOAD_OPTION NewOption;\r
129 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
130 UINTN BootOptionCount;\r
131 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;\r
132 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
133 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
134\r
135 Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);\r
136 ASSERT_EFI_ERROR (Status);\r
137\r
138 EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r
139 DevicePath = AppendDevicePathNode (\r
140 DevicePathFromHandle (LoadedImage->DeviceHandle),\r
141 (EFI_DEVICE_PATH_PROTOCOL *) &FileNode\r
142 );\r
143\r
144 Status = EfiBootManagerInitializeLoadOption (\r
145 &NewOption,\r
146 LoadOptionNumberUnassigned,\r
147 LoadOptionTypeBoot,\r
148 Attributes,\r
149 Description,\r
150 DevicePath,\r
151 NULL,\r
152 0\r
153 );\r
154 if (!EFI_ERROR (Status)) {\r
155 BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
156\r
157 OptionIndex = PlatformFindLoadOption (&NewOption, BootOptions, BootOptionCount);\r
158\r
159 if (OptionIndex == -1) {\r
160 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN) -1);\r
161 ASSERT_EFI_ERROR (Status);\r
162 }\r
163 EfiBootManagerFreeLoadOption (&NewOption);\r
164 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
165 }\r
166}\r
167\r
168/**\r
169 Do the platform specific action before the console is connected.\r
170\r
171 Such as:\r
172 Update console variable;\r
173 Register new Driver#### or Boot####;\r
174 Signal ReadyToLock event.\r
175**/\r
176VOID\r
177EFIAPI\r
178PlatformBootManagerBeforeConsole (\r
179 VOID\r
180)\r
181{\r
182 EFI_INPUT_KEY Enter;\r
183 EFI_INPUT_KEY F2;\r
bb47667a 184 EFI_INPUT_KEY Down;\r
42a8f2ce
MM
185 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r
186\r
187 PlatformConsoleInit ();\r
188\r
189 //\r
190 // Register ENTER as CONTINUE key\r
191 //\r
192 Enter.ScanCode = SCAN_NULL;\r
193 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;\r
194 EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);\r
195\r
196 //\r
197 // Map F2 to Boot Manager Menu\r
198 //\r
199 F2.ScanCode = SCAN_F2;\r
200 F2.UnicodeChar = CHAR_NULL;\r
201 EfiBootManagerGetBootManagerMenu (&BootOption);\r
202 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);\r
203\r
bb47667a 204 //\r
205 // Also add Down key to Boot Manager Menu since some serial terminals don't support F2 key.\r
206 //\r
207 Down.ScanCode = SCAN_DOWN;\r
208 Down.UnicodeChar = CHAR_NULL;\r
209 EfiBootManagerGetBootManagerMenu (&BootOption);\r
210 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &Down, NULL);\r
211\r
c46bf81d 212 //\r
213 // Install ready to lock.\r
214 // This needs to be done before option rom dispatched.\r
215 //\r
216 InstallReadyToLock ();\r
6d7864c2
RN
217\r
218 //\r
219 // Dispatch deferred images after EndOfDxe event and ReadyToLock installation.\r
220 //\r
221 EfiBootManagerDispatchDeferredImages ();\r
42a8f2ce
MM
222}\r
223\r
224/**\r
225 Do the platform specific action after the console is connected.\r
226\r
227 Such as:\r
228 Dynamically switch output mode;\r
229 Signal console ready platform customized event;\r
230 Run diagnostics like memory testing;\r
231 Connect certain devices;\r
232 Dispatch aditional option roms.\r
233**/\r
234VOID\r
235EFIAPI\r
236PlatformBootManagerAfterConsole (\r
237 VOID\r
238)\r
239{\r
240 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;\r
241 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;\r
242\r
243 Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;\r
244 White.Blue = White.Green = White.Red = White.Reserved = 0xFF;\r
245\r
246 EfiBootManagerConnectAll ();\r
247 EfiBootManagerRefreshAllBootOption ();\r
248\r
f94623aa 249 //\r
250 // Register UEFI Shell\r
251 //\r
252 PlatformRegisterFvBootOption (PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE);\r
253 \r
42a8f2ce
MM
254 Print (\r
255 L"\n"\r
bb47667a 256 L"F2 or Down to enter Boot Manager Menu.\n"\r
257 L"ENTER to boot directly.\n"\r
42a8f2ce
MM
258 L"\n"\r
259 );\r
260\r
261}\r
262\r
263/**\r
264 This function is called each second during the boot manager waits the timeout.\r
265\r
266 @param TimeoutRemain The remaining timeout.\r
267**/\r
268VOID\r
269EFIAPI\r
270PlatformBootManagerWaitCallback (\r
271 UINT16 TimeoutRemain\r
272)\r
273{\r
274 return;\r
275}\r