]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/Library/UnixBdsLib/BdsPlatform.c
1, Change name of PcdPlatformBootTimeoutDefault to PcdPlatformBootTimeout, now this...
[mirror_edk2.git] / UnixPkg / Library / UnixBdsLib / BdsPlatform.c
CommitLineData
804405e7 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 BdsPlatform.c\r
15\r
16Abstract:\r
17\r
18 This file include all platform action which can be customized\r
19 by IBV/OEM.\r
20\r
21--*/\r
22\r
23#include "BdsPlatform.h"\r
24\r
25CHAR16 mFirmwareVendor[] = L"TianoCore.org";\r
c71b6597 26UNIX_SYSTEM_CONFIGURATION mSystemConfigData;\r
27\r
28VOID\r
29SetupVariableInit (\r
30 VOID\r
31 )\r
32{\r
33 EFI_STATUS Status;\r
34 UINTN Size;\r
35\r
36 Size = sizeof (mSystemConfigData);\r
37 Status = gRT->GetVariable (\r
38 L"Setup",\r
39 &gEfiUnixSystemConfigGuid,\r
40 NULL,\r
41 &Size,\r
42 (VOID *) &mSystemConfigData\r
43 );\r
44\r
45 if (EFI_ERROR (Status)) {\r
46 //\r
47 // SetupVariable is corrupt\r
48 //\r
49 mSystemConfigData.ConOutRow = PcdGet32 (PcdConOutColumn);\r
50 mSystemConfigData.ConOutColumn = PcdGet32 (PcdConOutRow);\r
51\r
52 Status = gRT->SetVariable (\r
53 L"Setup",\r
54 &gEfiUnixSystemConfigGuid,\r
55 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
56 sizeof (mSystemConfigData),\r
57 (VOID *) &mSystemConfigData\r
58 );\r
59 if (EFI_ERROR (Status)) {\r
60 DEBUG ((EFI_D_ERROR, "Failed to save Setup Variable to non-volatile storage, Status = %r\n", Status));\r
61 }\r
62 }\r
63}\r
804405e7 64\r
65//\r
66// BDS Platform Functions\r
67//\r
68VOID\r
69PlatformBdsInit (\r
70 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData\r
71 )\r
72/*++\r
73\r
74Routine Description:\r
75\r
c71b6597 76 Platform Bds init. Include the platform firmware vendor, revision\r
804405e7 77 and so crc check.\r
78\r
79Arguments:\r
80\r
81 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
82\r
83Returns:\r
84\r
85 None.\r
86\r
87--*/\r
88{\r
89 //\r
90 // set firmwarevendor, here can be IBV/OEM customize\r
91 //\r
92 gST->FirmwareVendor = AllocateRuntimeCopyPool (\r
93 sizeof (mFirmwareVendor),\r
94 &mFirmwareVendor\r
95 );\r
96 ASSERT (gST->FirmwareVendor != NULL);\r
97\r
98 gST->FirmwareRevision = 0;\r
99\r
100 //\r
101 // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
102 //\r
103 gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
104\r
105}\r
106\r
107EFI_STATUS\r
108PlatformBdsConnectConsole (\r
109 IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole\r
110 )\r
111/*++\r
112\r
113Routine Description:\r
114\r
115 Connect the predefined platform default console device. Always try to find\r
116 and enable the vga device if have.\r
117\r
118Arguments:\r
119\r
120 PlatformConsole - Predfined platform default console device array.\r
121 \r
122Returns:\r
123\r
124 EFI_SUCCESS - Success connect at least one ConIn and ConOut \r
125 device, there must have one ConOut device is \r
126 active vga device.\r
127 \r
128 EFI_STATUS - Return the status of \r
129 BdsLibConnectAllDefaultConsoles ()\r
130\r
131--*/\r
132{\r
133 EFI_STATUS Status;\r
134 UINTN Index;\r
135\r
136 Index = 0;\r
137 Status = EFI_SUCCESS;\r
138\r
139 //\r
140 // Have chance to connect the platform default console,\r
141 // the platform default console is the minimue device group\r
142 // the platform should support\r
143 //\r
144 while (PlatformConsole[Index].DevicePath != NULL) {\r
145 //\r
146 // Update the console variable with the connect type\r
147 //\r
148 if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
149 BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);\r
150 }\r
151\r
152 if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
153 BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);\r
154 }\r
155\r
156 if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
157 BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);\r
158 }\r
159\r
160 Index++;\r
161 }\r
162 //\r
163 // Connect the all the default console with current cosole variable\r
164 //\r
165 Status = BdsLibConnectAllDefaultConsoles ();\r
166 return Status;\r
167}\r
168\r
169VOID\r
170PlatformBdsConnectSequence (\r
171 VOID\r
172 )\r
173/*++\r
174\r
175Routine Description:\r
176\r
177 Connect with predeined platform connect sequence, \r
178 the OEM/IBV can customize with their own connect sequence.\r
179 \r
180Arguments:\r
181\r
182 None.\r
183 \r
184Returns:\r
185\r
186 None.\r
187 \r
188--*/\r
189{\r
190 UINTN Index;\r
191\r
192 Index = 0;\r
193\r
194 //\r
195 // Here we can get the customized platform connect sequence\r
196 // Notes: we can connect with new variable which record the\r
197 // last time boots connect device path sequence\r
198 //\r
199 while (gPlatformConnectSequence[Index] != NULL) {\r
200 //\r
201 // Build the platform boot option\r
202 //\r
203 BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);\r
204 Index++;\r
205 }\r
206\r
207 //\r
208 // Just use the simple policy to connect all devices\r
209 //\r
210 BdsLibConnectAll ();\r
211}\r
212\r
213VOID\r
214PlatformBdsGetDriverOption (\r
215 IN OUT LIST_ENTRY *BdsDriverLists\r
216 )\r
217/*++\r
218\r
219Routine Description:\r
220\r
221 Load the predefined driver option, OEM/IBV can customize this\r
222 to load their own drivers\r
223 \r
224Arguments:\r
225\r
226 BdsDriverLists - The header of the driver option link list.\r
227 \r
228Returns:\r
229\r
230 None.\r
231 \r
232--*/\r
233{\r
234 UINTN Index;\r
235\r
236 Index = 0;\r
237\r
238 //\r
239 // Here we can get the customized platform driver option\r
240 //\r
241 while (gPlatformDriverOption[Index] != NULL) {\r
242 //\r
243 // Build the platform boot option\r
244 //\r
245 BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");\r
246 Index++;\r
247 }\r
248\r
249}\r
250\r
251VOID\r
252PlatformBdsDiagnostics (\r
253 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,\r
254 IN BOOLEAN QuietBoot\r
255 )\r
256/*++\r
257\r
258Routine Description:\r
259\r
260 Perform the platform diagnostic, such like test memory. OEM/IBV also\r
261 can customize this fuction to support specific platform diagnostic.\r
262 \r
263Arguments:\r
264\r
265 MemoryTestLevel - The memory test intensive level\r
266 \r
267 QuietBoot - Indicate if need to enable the quiet boot\r
268 \r
269Returns:\r
270\r
271 None.\r
272 \r
273--*/\r
274{\r
275 EFI_STATUS Status;\r
276\r
277 //\r
278 // Here we can decide if we need to show\r
279 // the diagnostics screen\r
280 // Notes: this quiet boot code should be remove\r
281 // from the graphic lib\r
282 //\r
283 if (QuietBoot) {\r
b5a1d1d9 284 EnableQuietBoot (&gEfiDefaultBmpLogoGuid);\r
804405e7 285 //\r
286 // Perform system diagnostic\r
287 //\r
288 Status = BdsMemoryTest (MemoryTestLevel);\r
289 if (EFI_ERROR (Status)) {\r
290 DisableQuietBoot ();\r
291 }\r
292\r
293 return ;\r
294 }\r
295 //\r
296 // Perform system diagnostic\r
297 //\r
298 Status = BdsMemoryTest (MemoryTestLevel);\r
299}\r
300\r
301VOID\r
302PlatformBdsPolicyBehavior (\r
303 IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData,\r
304 IN OUT LIST_ENTRY *DriverOptionList,\r
305 IN OUT LIST_ENTRY *BootOptionList\r
306 )\r
307/*++\r
308\r
309Routine Description:\r
310\r
311 The function will excute with as the platform policy, current policy\r
312 is driven by boot mode. IBV/OEM can customize this code for their specific\r
313 policy action.\r
314 \r
315Arguments:\r
316\r
317 PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
318 \r
319 DriverOptionList - The header of the driver option link list\r
320 \r
321 BootOptionList - The header of the boot option link list\r
322 \r
323Returns:\r
324\r
325 None.\r
326 \r
327--*/\r
328{\r
329 EFI_STATUS Status;\r
330 UINT16 Timeout;\r
331\r
332 //\r
333 // Init the time out value\r
334 //\r
335 Timeout = BdsLibGetTimeout ();\r
336\r
337 //\r
338 // Load the driver option as the driver option list\r
339 //\r
340 PlatformBdsGetDriverOption (DriverOptionList);\r
341\r
342 //\r
343 // Get current Boot Mode\r
344 //\r
345 Status = BdsLibGetBootMode (&PrivateData->BootMode);\r
346\r
347 //\r
348 // Go the different platform policy with different boot mode\r
349 // Notes: this part code can be change with the table policy\r
350 //\r
351 switch (PrivateData->BootMode) {\r
352\r
353 case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:\r
354 case BOOT_WITH_MINIMAL_CONFIGURATION:\r
355 //\r
356 // In no-configuration boot mode, we can connect the\r
357 // console directly.\r
358 //\r
359 BdsLibConnectAllDefaultConsoles ();\r
360 PlatformBdsDiagnostics (IGNORE, TRUE);\r
361\r
362 //\r
363 // Perform some platform specific connect sequence\r
364 //\r
365 PlatformBdsConnectSequence ();\r
366\r
367 //\r
368 // Notes: current time out = 0 can not enter the\r
369 // front page\r
370 //\r
371 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
372\r
373 //\r
374 // Check the boot option with the boot option list\r
375 //\r
376 BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
377 break;\r
378\r
379 case BOOT_ON_FLASH_UPDATE:\r
380 //\r
381 // Boot with the specific configuration\r
382 //\r
383 PlatformBdsConnectConsole (gPlatformConsole);\r
384 PlatformBdsDiagnostics (EXTENSIVE, FALSE);\r
385 BdsLibConnectAll ();\r
386 ProcessCapsules (BOOT_ON_FLASH_UPDATE);\r
387 break;\r
388\r
389 case BOOT_IN_RECOVERY_MODE:\r
390 //\r
391 // In recovery mode, just connect platform console\r
392 // and show up the front page\r
393 //\r
394 PlatformBdsConnectConsole (gPlatformConsole);\r
395 PlatformBdsDiagnostics (EXTENSIVE, FALSE);\r
396\r
397 //\r
398 // In recovery boot mode, we still enter to the\r
399 // frong page now\r
400 //\r
401 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
402 break;\r
403\r
404 case BOOT_WITH_FULL_CONFIGURATION:\r
405 case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:\r
406 case BOOT_WITH_DEFAULT_SETTINGS:\r
407 default:\r
408 //\r
409 // Connect platform console\r
410 //\r
411 Status = PlatformBdsConnectConsole (gPlatformConsole);\r
412 if (EFI_ERROR (Status)) {\r
413 //\r
414 // Here OEM/IBV can customize with defined action\r
415 //\r
416 PlatformBdsNoConsoleAction ();\r
417 }\r
418\r
419 PlatformBdsDiagnostics (IGNORE, TRUE);\r
420\r
421 //\r
422 // Perform some platform specific connect sequence\r
423 //\r
424 PlatformBdsConnectSequence ();\r
425\r
426 //\r
427 // Give one chance to enter the setup if we\r
428 // have the time out\r
429 //\r
430 PlatformBdsEnterFrontPage (Timeout, FALSE);\r
431\r
432 //\r
433 // Here we have enough time to do the enumeration of boot device\r
434 //\r
435 BdsLibEnumerateAllBootOption (BootOptionList);\r
436 break;\r
437 }\r
438\r
439 return ;\r
440\r
441}\r
442\r
443VOID\r
444PlatformBdsBootSuccess (\r
445 IN BDS_COMMON_OPTION *Option\r
446 )\r
447/*++\r
448\r
449Routine Description:\r
450 \r
451 Hook point after a boot attempt succeeds. We don't expect a boot option to\r
452 return, so the EFI 1.0 specification defines that you will default to an\r
453 interactive mode and stop processing the BootOrder list in this case. This\r
454 is alos a platform implementation and can be customized by IBV/OEM.\r
455\r
456Arguments:\r
457\r
458 Option - Pointer to Boot Option that succeeded to boot.\r
459\r
460Returns:\r
461 \r
462 None.\r
463\r
464--*/\r
465{\r
466 CHAR16 *TmpStr;\r
467\r
468 //\r
469 // If Boot returned with EFI_SUCCESS and there is not in the boot device\r
470 // select loop then we need to pop up a UI and wait for user input.\r
471 //\r
472 TmpStr = Option->StatusString;\r
473 if (TmpStr != NULL) {\r
474 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
475 FreePool (TmpStr);\r
476 }\r
477}\r
478\r
479VOID\r
480PlatformBdsBootFail (\r
481 IN BDS_COMMON_OPTION *Option,\r
482 IN EFI_STATUS Status,\r
483 IN CHAR16 *ExitData,\r
484 IN UINTN ExitDataSize\r
485 )\r
486/*++\r
487\r
488Routine Description:\r
489 \r
490 Hook point after a boot attempt fails.\r
491\r
492Arguments:\r
493 \r
494 Option - Pointer to Boot Option that failed to boot.\r
495\r
496 Status - Status returned from failed boot.\r
497\r
498 ExitData - Exit data returned from failed boot.\r
499\r
500 ExitDataSize - Exit data size returned from failed boot.\r
501\r
502Returns:\r
503 \r
504 None.\r
505\r
506--*/\r
507{\r
508 CHAR16 *TmpStr;\r
509\r
510 //\r
511 // If Boot returned with failed status then we need to pop up a UI and wait\r
512 // for user input.\r
513 //\r
514 TmpStr = Option->StatusString;\r
515 if (TmpStr != NULL) {\r
516 BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
517 FreePool (TmpStr);\r
518 }\r
519}\r
520\r
521EFI_STATUS\r
522PlatformBdsNoConsoleAction (\r
523 VOID\r
524 )\r
525/*++\r
526\r
527Routine Description:\r
528 \r
529 This function is remained for IBV/OEM to do some platform action,\r
530 if there no console device can be connected.\r
531\r
532Arguments:\r
533 \r
534 None.\r
535 \r
536Returns:\r
537 \r
538 EFI_SUCCESS - Direct return success now.\r
539\r
540--*/\r
541{\r
542 return EFI_SUCCESS;\r
543}\r
544\r
545EFI_STATUS\r
546EFIAPI\r
547PlatformBdsLockNonUpdatableFlash (\r
548 VOID\r
549 )\r
550{\r
551 return EFI_SUCCESS;\r
552}\r