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