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