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