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