]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/BdsDxe/BootMngr/BootManager.c
1) Cleanup HiiLib, IfrSupportLib.
[mirror_edk2.git] / MdeModulePkg / Universal / BdsDxe / BootMngr / BootManager.c
CommitLineData
93e3992d 1/*++\r
2\r
3Copyright (c) 2004 - 2008, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 BootManager.c\r
15\r
16Abstract:\r
17\r
18 The platform boot manager reference implement\r
19\r
20--*/\r
21\r
22#include "BootManager.h"\r
23\r
24UINT16 mKeyInput;\r
25EFI_GUID mBootManagerGuid = BOOT_MANAGER_FORMSET_GUID;\r
26LIST_ENTRY *mBootOptionsList;\r
27BDS_COMMON_OPTION *gOption;\r
28\r
29BOOT_MANAGER_CALLBACK_DATA gBootManagerPrivate = {\r
30 BOOT_MANAGER_CALLBACK_DATA_SIGNATURE,\r
31 NULL,\r
32 NULL,\r
33 {\r
34 FakeExtractConfig,\r
35 FakeRouteConfig,\r
36 BootManagerCallback\r
37 }\r
38};\r
39\r
40EFI_STATUS\r
41EFIAPI\r
42BootManagerCallback (\r
43 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
44 IN EFI_BROWSER_ACTION Action,\r
45 IN EFI_QUESTION_ID QuestionId,\r
46 IN UINT8 Type,\r
47 IN EFI_IFR_TYPE_VALUE *Value,\r
48 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
49 )\r
50/*++\r
51\r
52 Routine Description:\r
53 This function processes the results of changes in configuration.\r
54\r
55 Arguments:\r
56 This - Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
57 Action - Specifies the type of action taken by the browser.\r
58 QuestionId - A unique value which is sent to the original exporting driver\r
59 so that it can identify the type of data to expect.\r
60 Type - The type of value for the question.\r
61 Value - A pointer to the data being sent to the original exporting driver.\r
62 ActionRequest - On return, points to the action requested by the callback function.\r
63\r
64 Returns:\r
65 EFI_SUCCESS - The callback successfully handled the action.\r
66 EFI_OUT_OF_RESOURCES - Not enough storage is available to hold the variable and its data.\r
67 EFI_DEVICE_ERROR - The variable could not be saved.\r
68 EFI_UNSUPPORTED - The specified Action is not supported by the callback.\r
69\r
70--*/\r
71{\r
72 BDS_COMMON_OPTION *Option;\r
73 LIST_ENTRY *Link;\r
74 UINT16 KeyCount;\r
75\r
76 if ((Value == NULL) || (ActionRequest == NULL)) {\r
77 return EFI_INVALID_PARAMETER;\r
78 }\r
79\r
80 //\r
81 // Initialize the key count\r
82 //\r
83 KeyCount = 0;\r
84\r
85 for (Link = mBootOptionsList->ForwardLink; Link != mBootOptionsList; Link = Link->ForwardLink) {\r
86 Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
87\r
88 KeyCount++;\r
89\r
90 gOption = Option;\r
91\r
92 //\r
93 // Is this device the one chosen?\r
94 //\r
95 if (KeyCount == QuestionId) {\r
96 //\r
97 // Assigning the returned Key to a global allows the original routine to know what was chosen\r
98 //\r
99 mKeyInput = QuestionId;\r
100\r
101 //\r
102 // Request to exit SendForm(), so that we could boot the selected option\r
103 //\r
104 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
105 break;\r
106 }\r
107 }\r
108\r
109 return EFI_SUCCESS;\r
110}\r
111\r
112EFI_STATUS\r
113InitializeBootManager (\r
114 VOID\r
115 )\r
116/*++\r
117\r
118Routine Description:\r
119\r
120 Initialize HII information for the FrontPage\r
121\r
122Arguments:\r
123 None\r
124\r
125Returns:\r
126\r
127--*/\r
128{\r
129 EFI_STATUS Status;\r
130 EFI_HII_PACKAGE_LIST_HEADER *PackageList;\r
131\r
132 //\r
133 // Create driver handle used by HII database\r
134 //\r
135 Status = HiiLibCreateHiiDriverHandle (&gBootManagerPrivate.DriverHandle);\r
136 if (EFI_ERROR (Status)) {\r
137 return Status;\r
138 }\r
139\r
140 //\r
141 // Install Config Access protocol to driver handle\r
142 //\r
143 Status = gBS->InstallProtocolInterface (\r
144 &gBootManagerPrivate.DriverHandle,\r
145 &gEfiHiiConfigAccessProtocolGuid,\r
146 EFI_NATIVE_INTERFACE,\r
147 &gBootManagerPrivate.ConfigAccess\r
148 );\r
149 ASSERT_EFI_ERROR (Status);\r
150\r
151 //\r
152 // Publish our HII data\r
153 //\r
9226efe5 154 PackageList = HiiLibPreparePackageList (2, &mBootManagerGuid, BootManagerVfrBin, BdsStrings);\r
93e3992d 155 ASSERT (PackageList != NULL);\r
156\r
157 Status = gHiiDatabase->NewPackageList (\r
158 gHiiDatabase,\r
159 PackageList,\r
160 gBootManagerPrivate.DriverHandle,\r
161 &gBootManagerPrivate.HiiHandle\r
162 );\r
163 FreePool (PackageList);\r
164\r
165 return Status;\r
166}\r
167\r
168VOID\r
169CallBootManager (\r
170 VOID\r
171 )\r
172/*++\r
173\r
174Routine Description:\r
175 Hook to enable UI timeout override behavior.\r
176\r
177Arguments:\r
178 BdsDeviceList - Device List that BDS needs to connect.\r
179\r
180 Entry - Pointer to current Boot Entry.\r
181\r
182Returns:\r
183 NONE\r
184\r
185--*/\r
186{\r
187 EFI_STATUS Status;\r
188 BDS_COMMON_OPTION *Option;\r
189 LIST_ENTRY *Link;\r
190 EFI_HII_UPDATE_DATA UpdateData;\r
191 CHAR16 *ExitData;\r
192 UINTN ExitDataSize;\r
193 EFI_STRING_ID Token;\r
194 EFI_INPUT_KEY Key;\r
195 LIST_ENTRY BdsBootOptionList;\r
196 CHAR16 *HelpString;\r
197 EFI_STRING_ID HelpToken;\r
198 UINT16 *TempStr;\r
199 EFI_HII_HANDLE HiiHandle;\r
200 EFI_BROWSER_ACTION_REQUEST ActionRequest;\r
201 UINTN TempSize;\r
202\r
203 gOption = NULL;\r
204 InitializeListHead (&BdsBootOptionList);\r
205\r
206 //\r
207 // Connect all prior to entering the platform setup menu.\r
208 //\r
209 if (!gConnectAllHappened) {\r
210 BdsLibConnectAllDriversToAllControllers ();\r
211 gConnectAllHappened = TRUE;\r
212 }\r
213 //\r
214 // BugBug: Here we can not remove the legacy refresh macro, so we need\r
215 // get the boot order every time from "BootOrder" variable.\r
216 // Recreate the boot option list base on the BootOrder variable\r
217 //\r
218 BdsLibEnumerateAllBootOption (&BdsBootOptionList);\r
219\r
220 mBootOptionsList = &BdsBootOptionList;\r
221\r
222 HiiHandle = gBootManagerPrivate.HiiHandle;\r
223\r
224 //\r
225 // Allocate space for creation of UpdateData Buffer\r
226 //\r
227 UpdateData.BufferSize = 0x1000;\r
228 UpdateData.Offset = 0;\r
229 UpdateData.Data = AllocateZeroPool (0x1000);\r
230 ASSERT (UpdateData.Data != NULL);\r
231\r
232 mKeyInput = 0;\r
233\r
234 for (Link = BdsBootOptionList.ForwardLink; Link != &BdsBootOptionList; Link = Link->ForwardLink) {\r
235 Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
236\r
237 //\r
238 // At this stage we are creating a menu entry, thus the Keys are reproduceable\r
239 //\r
240 mKeyInput++;\r
241\r
242 //\r
243 // Don't display the boot option marked as LOAD_OPTION_HIDDEN\r
244 //\r
245 if (Option->Attribute & LOAD_OPTION_HIDDEN) {\r
246 continue;\r
247 }\r
248\r
9226efe5 249 HiiLibNewString (HiiHandle, &Token, Option->Description);\r
93e3992d 250\r
251 TempStr = DevicePathToStr (Option->DevicePath);\r
252 TempSize = StrSize (TempStr);\r
253 HelpString = AllocateZeroPool (TempSize + StrSize (L"Device Path : "));\r
254 StrCat (HelpString, L"Device Path : ");\r
255 StrCat (HelpString, TempStr);\r
256\r
9226efe5 257 HiiLibNewString (HiiHandle, &HelpToken, HelpString);\r
93e3992d 258\r
259 CreateActionOpCode (\r
260 mKeyInput,\r
261 Token,\r
262 HelpToken,\r
263 EFI_IFR_FLAG_CALLBACK,\r
264 0,\r
265 &UpdateData\r
266 );\r
267 }\r
268\r
269 IfrLibUpdateForm (\r
270 HiiHandle,\r
271 &mBootManagerGuid,\r
272 BOOT_MANAGER_FORM_ID,\r
273 LABEL_BOOT_OPTION,\r
274 FALSE,\r
275 &UpdateData\r
276 );\r
277 FreePool (UpdateData.Data);\r
278\r
279 //\r
280 // Drop the TPL level from TPL_APPLICATION to TPL_APPLICATION\r
281 //\r
282 gBS->RestoreTPL (TPL_APPLICATION);\r
283\r
284 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
285 Status = gFormBrowser2->SendForm (\r
286 gFormBrowser2,\r
287 &HiiHandle,\r
288 1,\r
289 NULL,\r
290 0,\r
291 NULL,\r
292 &ActionRequest\r
293 );\r
294 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {\r
295 EnableResetRequired ();\r
296 }\r
297\r
298 if (gOption == NULL) {\r
299 gBS->RaiseTPL (TPL_APPLICATION);\r
300 return ;\r
301 }\r
302\r
303 //\r
304 //Will leave browser, check any reset required change is applied? if yes, reset system\r
305 //\r
306 SetupResetReminder ();\r
307\r
308 //\r
309 // Raise the TPL level back to TPL_APPLICATION\r
310 //\r
311 gBS->RaiseTPL (TPL_APPLICATION);\r
312\r
313 //\r
314 // parse the selected option\r
315 //\r
316 Status = BdsLibBootViaBootOption (gOption, gOption->DevicePath, &ExitDataSize, &ExitData);\r
317\r
318 if (!EFI_ERROR (Status)) {\r
319 gOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED));\r
320 PlatformBdsBootSuccess (gOption);\r
321 } else {\r
322 gOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));\r
323 PlatformBdsBootFail (gOption, Status, ExitData, ExitDataSize);\r
324 gST->ConOut->OutputString (\r
325 gST->ConOut,\r
326 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE))\r
327 );\r
328 gBS->RestoreTPL (TPL_APPLICATION);\r
329 //\r
330 // BdsLibUiWaitForSingleEvent (gST->ConIn->WaitForKey, 0);\r
331 //\r
332 gBS->RaiseTPL (TPL_APPLICATION);\r
333 gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
334 }\r
335}\r