]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/PlatformBdsDxe/Generic/BootMngr/BootManager.c
changed gEfiMdeModulePkgTokenSpaceGuid to gEfiEdkModulePkgTokenSpaceGuid temporary...
[mirror_edk2.git] / Nt32Pkg / PlatformBdsDxe / Generic / BootMngr / BootManager.c
CommitLineData
bc11b829 1/*++\r
2\r
3Copyright (c) 2006 - 2007, 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 common header file for this module.\r
23//\r
24#include "CommonHeader.h"\r
25\r
26#include "BootManager.h"\r
27\r
28UINT16 mKeyInput;\r
29LIST_ENTRY *mBootOptionsList;\r
30BDS_COMMON_OPTION *gOption;\r
31EFI_HII_HANDLE gBootManagerHandle;\r
32EFI_HANDLE BootManagerCallbackHandle;\r
33EFI_FORM_CALLBACK_PROTOCOL BootManagerCallback;\r
34EFI_GUID gBmGuid = BOOT_MANAGER_GUID;\r
35\r
36extern EFI_FORM_BROWSER_PROTOCOL *gBrowser;\r
37extern UINT8 BootManagerVfrBin[];\r
38extern UINT8 BdsStrings[];\r
39extern BOOLEAN gConnectAllHappened;\r
40\r
41EFI_STATUS\r
42EFIAPI\r
43BootManagerCallbackRoutine (\r
44 IN EFI_FORM_CALLBACK_PROTOCOL *This,\r
45 IN UINT16 KeyValue,\r
46 IN EFI_IFR_DATA_ARRAY *DataArray,\r
47 OUT EFI_HII_CALLBACK_PACKET **Packet\r
48 )\r
49/*++\r
50\r
51Routine Description:\r
52\r
53 This is the function that is called to provide results data to the driver. This data\r
54 consists of a unique key which is used to identify what data is either being passed back\r
55 or being asked for.\r
56\r
57Arguments:\r
58\r
59 KeyValue - A unique value which is sent to the original exporting driver so that it\r
60 can identify the type of data to expect. The format of the data tends to\r
61 vary based on the op-code that geerated the callback.\r
62\r
63 Data - A pointer to the data being sent to the original exporting driver.\r
64\r
65Returns:\r
66\r
67--*/\r
68{\r
69 BDS_COMMON_OPTION *Option;\r
70 LIST_ENTRY *Link;\r
71 UINT16 KeyCount;\r
72 EFI_HII_CALLBACK_PACKET *DataPacket;\r
73\r
74 //\r
75 // Initialize the key count\r
76 //\r
77 KeyCount = 0;\r
78\r
79 for (Link = mBootOptionsList->ForwardLink; Link != mBootOptionsList; Link = Link->ForwardLink) {\r
80 Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
81\r
82 KeyCount++;\r
83\r
84 gOption = Option;\r
85\r
86 //\r
87 // Is this device the one chosen?\r
88 //\r
89 if (KeyCount == KeyValue) {\r
90 //\r
91 // Assigning the returned Key to a global allows the original routine to know what was chosen\r
92 //\r
93 mKeyInput = KeyValue;\r
94\r
95 *Packet = AllocateZeroPool (sizeof (EFI_HII_CALLBACK_PACKET) + 2);\r
96 ASSERT (*Packet != NULL);\r
97\r
98 //\r
99 // Assign the buffer address to DataPacket\r
100 //\r
101 DataPacket = *Packet;\r
102\r
103 DataPacket->DataArray.EntryCount = 1;\r
104 DataPacket->DataArray.NvRamMap = NULL;\r
105 ((EFI_IFR_DATA_ENTRY *) (((EFI_IFR_DATA_ARRAY *)DataPacket) + 1))->Flags = EXIT_REQUIRED | NV_NOT_CHANGED;\r
106 return EFI_SUCCESS;\r
107 } else {\r
108 continue;\r
109 }\r
110 }\r
111\r
112 return EFI_SUCCESS;\r
113}\r
114\r
115VOID\r
116CallBootManager (\r
117 VOID\r
118 )\r
119/*++\r
120\r
121Routine Description:\r
122 Hook to enable UI timeout override behavior.\r
123\r
124Arguments:\r
125 BdsDeviceList - Device List that BDS needs to connect.\r
126\r
127 Entry - Pointer to current Boot Entry.\r
128\r
129Returns:\r
130 NONE\r
131\r
132--*/\r
133{\r
134 EFI_STATUS Status;\r
135 EFI_HII_PACKAGES *PackageList;\r
136 BDS_COMMON_OPTION *Option;\r
137 LIST_ENTRY *Link;\r
138 EFI_HII_UPDATE_DATA *UpdateData;\r
139 CHAR16 *ExitData;\r
140 UINTN ExitDataSize;\r
141 STRING_REF Token;\r
142 STRING_REF LastToken;\r
143 EFI_INPUT_KEY Key;\r
144 UINT8 *Location;\r
145 EFI_GUID BmGuid;\r
146 LIST_ENTRY BdsBootOptionList;\r
147 BOOLEAN BootMngrMenuResetRequired;\r
148\r
149 gOption = NULL;\r
150 InitializeListHead (&BdsBootOptionList);\r
151\r
152 //\r
153 // Connect all prior to entering the platform setup menu.\r
154 //\r
155 if (!gConnectAllHappened) {\r
156 BdsLibConnectAllDriversToAllControllers ();\r
157 gConnectAllHappened = TRUE;\r
158 }\r
159 //\r
160 // BugBug: Here we can not remove the legacy refresh macro, so we need\r
161 // get the boot order every time from "BootOrder" variable.\r
162 // Recreate the boot option list base on the BootOrder variable\r
163 //\r
164 BdsLibEnumerateAllBootOption (&BdsBootOptionList);\r
165\r
166 //\r
167 // This GUID must be the same as what is defined in BootManagerVfr.vfr\r
168 //\r
169 BmGuid = gBmGuid;\r
170\r
171 mBootOptionsList = &BdsBootOptionList;\r
172\r
173 //\r
174 // Post our VFR to the HII database\r
175 //\r
176 PackageList = PreparePackages (2, &BmGuid, BootManagerVfrBin, BdsStrings);\r
177 Status = Hii->NewPack (Hii, PackageList, &gBootManagerHandle);\r
178 FreePool (PackageList);\r
179\r
180 //\r
181 // This example does not implement worker functions\r
182 // for the NV accessor functions. Only a callback evaluator\r
183 //\r
184 BootManagerCallback.NvRead = NULL;\r
185 BootManagerCallback.NvWrite = NULL;\r
186 BootManagerCallback.Callback = BootManagerCallbackRoutine;\r
187\r
188 //\r
189 // Install protocol interface\r
190 //\r
191 BootManagerCallbackHandle = NULL;\r
192 Status = gBS->InstallProtocolInterface (\r
193 &BootManagerCallbackHandle,\r
194 &gEfiFormCallbackProtocolGuid,\r
195 EFI_NATIVE_INTERFACE,\r
196 &BootManagerCallback\r
197 );\r
198 ASSERT_EFI_ERROR (Status);\r
199\r
200 LastToken = 0;\r
201 Hii->NewString (Hii, NULL, gBootManagerHandle, &LastToken, L" ");\r
202\r
203 //\r
204 // Allocate space for creation of UpdateData Buffer\r
205 //\r
206 UpdateData = AllocateZeroPool (0x1000);\r
207 ASSERT (UpdateData != NULL);\r
208\r
209 //\r
210 // Flag update pending in FormSet\r
211 //\r
212 UpdateData->FormSetUpdate = TRUE;\r
213 //\r
214 // Register CallbackHandle data for FormSet\r
215 //\r
216 UpdateData->FormCallbackHandle = (EFI_PHYSICAL_ADDRESS) (UINTN) BootManagerCallbackHandle;\r
217 UpdateData->FormUpdate = FALSE;\r
218 UpdateData->FormTitle = 0;\r
219 UpdateData->DataCount = 1;\r
220\r
221 //\r
222 // Create blank space. Since when we update the contents of IFR data at a label, it is\r
223 // inserted at the location of the label. So if you want to add a string with an empty\r
224 // space afterwards, you need to add the space first and then the string like below.\r
225 //\r
226 Status = CreateSubTitleOpCode (\r
227 LastToken, // Token Value for the string\r
228 &UpdateData->Data // Buffer containing created op-code\r
229 );\r
230\r
231 Hii->UpdateForm (Hii, gBootManagerHandle, (EFI_FORM_LABEL) 0x0000, TRUE, UpdateData);\r
232\r
233 //\r
234 // Create "Boot Option Menu" title\r
235 //\r
236 Status = CreateSubTitleOpCode (\r
237 STRING_TOKEN (STR_BOOT_OPTION_BANNER), // Token Value for the string\r
238 &UpdateData->Data // Buffer containing created op-code\r
239 );\r
240\r
241 Hii->UpdateForm (Hii, gBootManagerHandle, (EFI_FORM_LABEL) 0x0000, TRUE, UpdateData);\r
242\r
243 Token = LastToken;\r
244 mKeyInput = 0;\r
245\r
246 UpdateData->DataCount = 0;\r
247 Location = (UINT8 *) &UpdateData->Data;\r
248\r
249 for (Link = BdsBootOptionList.ForwardLink; Link != &BdsBootOptionList; Link = Link->ForwardLink) {\r
250 Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
251\r
252 //\r
253 // At this stage we are creating a menu entry, thus the Keys are reproduceable\r
254 //\r
255 mKeyInput++;\r
256 Token++;\r
257\r
258 Status = Hii->NewString (Hii, NULL, gBootManagerHandle, &Token, Option->Description);\r
259\r
260 //\r
261 // If we got an error it is almost certainly due to the token value being invalid.\r
262 // Therefore we will set the Token to 0 to automatically add a token.\r
263 //\r
264 if (EFI_ERROR (Status)) {\r
265 Token = 0;\r
266 Status = Hii->NewString (Hii, NULL, gBootManagerHandle, &Token, Option->Description);\r
267 }\r
268\r
269 Status = CreateGotoOpCode (\r
270 0x1000, // Form ID\r
271 Token, // Token Value for the string\r
272 0, // Help String (none)\r
273 EFI_IFR_FLAG_INTERACTIVE | EFI_IFR_FLAG_NV_ACCESS, // The Op-Code flags\r
274 mKeyInput, // The Key to get a callback on\r
275 Location // Buffer containing created op-code\r
276 );\r
277\r
278 UpdateData->DataCount++;\r
279 Location = Location + ((EFI_IFR_OP_HEADER *) Location)->Length;\r
280\r
281 }\r
282\r
283 Hii->UpdateForm (Hii, gBootManagerHandle, (EFI_FORM_LABEL) 0x0001, TRUE, UpdateData);\r
284\r
285 UpdateData->DataCount = 1;\r
286\r
287 //\r
288 // Create "Boot Option Menu" title\r
289 //\r
290 Status = CreateSubTitleOpCode (\r
291 STRING_TOKEN (STR_HELP_FOOTER), // Token Value for the string\r
292 &UpdateData->Data // Buffer containing created op-code\r
293 );\r
294\r
295 Hii->UpdateForm (Hii, gBootManagerHandle, (EFI_FORM_LABEL) 0x0002, TRUE, UpdateData);\r
296\r
297 Status = CreateSubTitleOpCode (\r
298 LastToken, // Token Value for the string\r
299 &UpdateData->Data // Buffer containing created op-code\r
300 );\r
301\r
302 Hii->UpdateForm (Hii, gBootManagerHandle, (EFI_FORM_LABEL) 0x0002, TRUE, UpdateData);\r
303\r
304 FreePool (UpdateData);\r
305\r
306 ASSERT (gBrowser);\r
307\r
308 BootMngrMenuResetRequired = FALSE;\r
309 gBrowser->SendForm (\r
310 gBrowser,\r
311 TRUE,\r
312 &gBootManagerHandle,\r
313 1,\r
314 NULL,\r
315 NULL,\r
316 NULL,\r
317 NULL,\r
318 &BootMngrMenuResetRequired\r
319 );\r
320\r
321 if (BootMngrMenuResetRequired) {\r
322 EnableResetRequired ();\r
323 }\r
324\r
325 Hii->ResetStrings (Hii, gBootManagerHandle);\r
326\r
327 if (gOption == NULL) {\r
328 return ;\r
329 }\r
330\r
331 //\r
332 //Will leave browser, check any reset required change is applied? if yes, reset system\r
333 //\r
334 SetupResetReminder ();\r
335\r
336 //\r
337 // BugBug: This code looks repeated from the BDS. Need to save code space.\r
338 //\r
339\r
340 //\r
341 // parse the selected option\r
342 //\r
343 Status = BdsLibBootViaBootOption (gOption, gOption->DevicePath, &ExitDataSize, &ExitData);\r
344\r
345 if (!EFI_ERROR (Status)) {\r
346 PlatformBdsBootSuccess (gOption);\r
347 } else {\r
348 PlatformBdsBootFail (gOption, Status, ExitData, ExitDataSize);\r
349 gST->ConOut->OutputString (\r
350 gST->ConOut,\r
351 GetStringById (STRING_TOKEN (STR_ANY_KEY_CONTINUE))\r
352 );\r
353\r
354 //\r
355 // BdsLibUiWaitForSingleEvent (gST->ConIn->WaitForKey, 0);\r
356 //\r
357\r
358 gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
359 }\r
360}\r