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