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