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