]> git.proxmox.com Git - mirror_edk2.git/blame - CorebootPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManager.c
CorebootPayloadPkg: Notify EndOfDxe and install ReadyToLock protocol.
[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
184 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r
185\r
186 PlatformConsoleInit ();\r
187\r
188 //\r
189 // Register ENTER as CONTINUE key\r
190 //\r
191 Enter.ScanCode = SCAN_NULL;\r
192 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;\r
193 EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);\r
194\r
195 //\r
196 // Map F2 to Boot Manager Menu\r
197 //\r
198 F2.ScanCode = SCAN_F2;\r
199 F2.UnicodeChar = CHAR_NULL;\r
200 EfiBootManagerGetBootManagerMenu (&BootOption);\r
201 EfiBootManagerAddKeyOptionVariable (NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL);\r
202\r
203 //\r
204 // Register UEFI Shell\r
205 //\r
206 PlatformRegisterFvBootOption (PcdGetPtr (PcdShellFile), L"UEFI Shell", LOAD_OPTION_ACTIVE);\r
c46bf81d 207\r
208 //\r
209 // Install ready to lock.\r
210 // This needs to be done before option rom dispatched.\r
211 //\r
212 InstallReadyToLock ();\r
42a8f2ce
MM
213}\r
214\r
215/**\r
216 Do the platform specific action after the console is connected.\r
217\r
218 Such as:\r
219 Dynamically switch output mode;\r
220 Signal console ready platform customized event;\r
221 Run diagnostics like memory testing;\r
222 Connect certain devices;\r
223 Dispatch aditional option roms.\r
224**/\r
225VOID\r
226EFIAPI\r
227PlatformBootManagerAfterConsole (\r
228 VOID\r
229)\r
230{\r
231 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;\r
232 EFI_GRAPHICS_OUTPUT_BLT_PIXEL White;\r
233\r
234 Black.Blue = Black.Green = Black.Red = Black.Reserved = 0;\r
235 White.Blue = White.Green = White.Red = White.Reserved = 0xFF;\r
236\r
237 EfiBootManagerConnectAll ();\r
238 EfiBootManagerRefreshAllBootOption ();\r
239\r
240 Print (\r
241 L"\n"\r
242 L"F2 to enter Boot Manager Menu.\n"\r
243 L"ENTER to boot directly.\n"\r
244 L"\n"\r
245 );\r
246\r
247}\r
248\r
249/**\r
250 This function is called each second during the boot manager waits the timeout.\r
251\r
252 @param TimeoutRemain The remaining timeout.\r
253**/\r
254VOID\r
255EFIAPI\r
256PlatformBootManagerWaitCallback (\r
257 UINT16 TimeoutRemain\r
258)\r
259{\r
260 return;\r
261}\r