3 Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
4 Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "IntelBdsPlatform.h"
18 #include <Library/QemuBootOrderLib.h>
21 /// Predefined platform default time out value
23 UINT16 gPlatformBootTimeOutDefault
;
27 PlatformIntelBdsConstructor (
28 IN EFI_HANDLE ImageHandle
,
29 IN EFI_SYSTEM_TABLE
*SystemTable
32 gPlatformBootTimeOutDefault
= (UINT16
)PcdGet16 (PcdPlatformBootTimeOut
);
37 // BDS Platform Functions
40 Platform Bds init. Include the platform firmware vendor, revision
54 GetConsoleDevicePathFromVariable (
55 IN CHAR16
* ConsoleVarName
,
56 IN CHAR16
* DefaultConsolePaths
,
57 OUT EFI_DEVICE_PATH
** DevicePaths
62 EFI_DEVICE_PATH_PROTOCOL
* DevicePathInstances
;
63 EFI_DEVICE_PATH_PROTOCOL
* DevicePathInstance
;
64 CHAR16
* DevicePathStr
;
65 CHAR16
* NextDevicePathStr
;
66 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL
*EfiDevicePathFromTextProtocol
;
68 Status
= GetGlobalEnvironmentVariable (ConsoleVarName
, NULL
, NULL
, (VOID
**)&DevicePathInstances
);
69 if (EFI_ERROR (Status
)) {
70 // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)
71 if ((DefaultConsolePaths
== NULL
) || (DefaultConsolePaths
[0] == L
'\0')) {
76 Status
= gBS
->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid
, NULL
, (VOID
**)&EfiDevicePathFromTextProtocol
);
77 ASSERT_EFI_ERROR (Status
);
79 DevicePathInstances
= NULL
;
81 // Extract the Device Path instances from the multi-device path string
82 while ((DefaultConsolePaths
!= NULL
) && (DefaultConsolePaths
[0] != L
'\0')) {
83 NextDevicePathStr
= StrStr (DefaultConsolePaths
, L
";");
84 if (NextDevicePathStr
== NULL
) {
85 DevicePathStr
= DefaultConsolePaths
;
86 DefaultConsolePaths
= NULL
;
88 DevicePathStr
= (CHAR16
*)AllocateCopyPool ((NextDevicePathStr
- DefaultConsolePaths
+ 1) * sizeof (CHAR16
), DefaultConsolePaths
);
89 *(DevicePathStr
+ (NextDevicePathStr
- DefaultConsolePaths
)) = L
'\0';
90 DefaultConsolePaths
= NextDevicePathStr
;
91 if (DefaultConsolePaths
[0] == L
';') {
92 DefaultConsolePaths
++;
96 DevicePathInstance
= EfiDevicePathFromTextProtocol
->ConvertTextToDevicePath (DevicePathStr
);
97 ASSERT (DevicePathInstance
!= NULL
);
98 DevicePathInstances
= AppendDevicePathInstance (DevicePathInstances
, DevicePathInstance
);
100 if (NextDevicePathStr
!= NULL
) {
101 FreePool (DevicePathStr
);
103 FreePool (DevicePathInstance
);
106 // Set the environment variable with this device path multi-instances
107 Size
= GetDevicePathSize (DevicePathInstances
);
111 &gEfiGlobalVariableGuid
,
112 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
117 Status
= EFI_INVALID_PARAMETER
;
121 if (!EFI_ERROR (Status
)) {
122 *DevicePaths
= DevicePathInstances
;
129 InitializeConsolePipe (
130 IN EFI_DEVICE_PATH
*ConsoleDevicePaths
,
131 IN EFI_GUID
*Protocol
,
132 OUT EFI_HANDLE
*Handle
,
140 EFI_DEVICE_PATH_PROTOCOL
* DevicePath
;
142 // Connect all the Device Path Consoles
143 while (ConsoleDevicePaths
!= NULL
) {
144 DevicePath
= GetNextDevicePathInstance (&ConsoleDevicePaths
, &Size
);
146 Status
= BdsConnectDevicePath (DevicePath
, Handle
, NULL
);
148 if (EFI_ERROR (Status
)) {
149 // We convert back to the text representation of the device Path
150 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
* DevicePathToTextProtocol
;
151 CHAR16
* DevicePathTxt
;
154 Status
= gBS
->LocateProtocol (&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevicePathToTextProtocol
);
155 if (!EFI_ERROR (Status
)) {
156 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText (DevicePath
, TRUE
, TRUE
);
158 DEBUG ((EFI_D_ERROR
, "Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt
, Status
));
160 FreePool (DevicePathTxt
);
165 // If the console splitter driver is not supported by the platform then use the first Device Path
166 // instance for the console interface.
167 if (!EFI_ERROR (Status
) && (*Interface
== NULL
)) {
168 Status
= gBS
->HandleProtocol (*Handle
, Protocol
, Interface
);
172 // No Device Path has been defined for this console interface. We take the first protocol implementation
173 if (*Interface
== NULL
) {
174 Status
= gBS
->LocateHandleBuffer (ByProtocol
, Protocol
, NULL
, &NoHandles
, &Buffer
);
175 if (EFI_ERROR (Status
)) {
176 BdsConnectAllDrivers ();
177 Status
= gBS
->LocateHandleBuffer (ByProtocol
, Protocol
, NULL
, &NoHandles
, &Buffer
);
180 if (!EFI_ERROR (Status
)) {
182 Status
= gBS
->HandleProtocol (*Handle
, Protocol
, Interface
);
183 ASSERT_EFI_ERROR (Status
);
187 Status
= EFI_SUCCESS
;
194 Connect the predefined platform default console device. Always try to find
195 and enable the vga device if have.
197 @param PlatformConsole Predefined platform default console device array.
199 @retval EFI_SUCCESS Success connect at least one ConIn and ConOut
200 device, there must have one ConOut device is
202 @return Return the status of BdsLibConnectAllDefaultConsoles ()
206 PlatformBdsConnectConsole (
211 EFI_DEVICE_PATH
* ConOutDevicePaths
;
212 EFI_DEVICE_PATH
* ConInDevicePaths
;
213 EFI_DEVICE_PATH
* ConErrDevicePaths
;
215 // By getting the Console Device Paths from the environment variables before initializing the console pipe, we
216 // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface
217 // of newly installed console drivers
218 Status
= GetConsoleDevicePathFromVariable (L
"ConOut", (CHAR16
*)PcdGetPtr (PcdDefaultConOutPaths
), &ConOutDevicePaths
);
219 ASSERT_EFI_ERROR (Status
);
220 Status
= GetConsoleDevicePathFromVariable (L
"ConIn", (CHAR16
*)PcdGetPtr (PcdDefaultConInPaths
), &ConInDevicePaths
);
221 ASSERT_EFI_ERROR (Status
);
222 Status
= GetConsoleDevicePathFromVariable (L
"ErrOut", (CHAR16
*)PcdGetPtr (PcdDefaultConOutPaths
), &ConErrDevicePaths
);
223 ASSERT_EFI_ERROR (Status
);
225 // Initialize the Consoles
226 Status
= InitializeConsolePipe (ConOutDevicePaths
, &gEfiSimpleTextOutProtocolGuid
, &gST
->ConsoleOutHandle
, (VOID
**)&gST
->ConOut
);
227 ASSERT_EFI_ERROR (Status
);
228 Status
= InitializeConsolePipe (ConInDevicePaths
, &gEfiSimpleTextInProtocolGuid
, &gST
->ConsoleInHandle
, (VOID
**)&gST
->ConIn
);
229 ASSERT_EFI_ERROR (Status
);
230 Status
= InitializeConsolePipe (ConErrDevicePaths
, &gEfiSimpleTextOutProtocolGuid
, &gST
->StandardErrorHandle
, (VOID
**)&gST
->StdErr
);
231 if (EFI_ERROR (Status
)) {
232 // In case of error, we reuse the console output for the error output
233 gST
->StandardErrorHandle
= gST
->ConsoleOutHandle
;
234 gST
->StdErr
= gST
->ConOut
;
241 Connect with predefined platform connect sequence,
242 the OEM/IBV can customize with their own connect sequence.
245 PlatformBdsConnectSequence (
252 Load the predefined driver option, OEM/IBV can customize this
253 to load their own drivers
255 @param BdsDriverLists - The header of the driver option link list.
259 PlatformBdsGetDriverOption (
260 IN OUT LIST_ENTRY
*BdsDriverLists
266 Perform the platform diagnostic, such like test memory. OEM/IBV also
267 can customize this function to support specific platform diagnostic.
269 @param MemoryTestLevel The memory test intensive level
270 @param QuietBoot Indicate if need to enable the quiet boot
271 @param BaseMemoryTest A pointer to BdsMemoryTest()
275 PlatformBdsDiagnostics (
276 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
277 IN BOOLEAN QuietBoot
,
278 IN BASEM_MEMORY_TEST BaseMemoryTest
284 The function will execute with as the platform policy, current policy
285 is driven by boot mode. IBV/OEM can customize this code for their specific
288 @param DriverOptionList The header of the driver option link list
289 @param BootOptionList The header of the boot option link list
290 @param ProcessCapsules A pointer to ProcessCapsules()
291 @param BaseMemoryTest A pointer to BaseMemoryTest()
296 PlatformBdsPolicyBehavior (
297 IN LIST_ENTRY
*DriverOptionList
,
298 IN LIST_ENTRY
*BootOptionList
,
299 IN PROCESS_CAPSULES ProcessCapsules
,
300 IN BASEM_MEMORY_TEST BaseMemoryTest
305 Status
= PlatformBdsConnectConsole ();
306 ASSERT_EFI_ERROR (Status
);
309 BdsLibEnumerateAllBootOption (BootOptionList
);
311 SetBootOrderFromQemu (BootOptionList
);
313 // The BootOrder variable may have changed, reload the in-memory list with
316 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
318 PlatformBdsEnterFrontPage (gPlatformBootTimeOutDefault
, TRUE
);
322 Hook point after a boot attempt succeeds. We don't expect a boot option to
323 return, so the UEFI 2.0 specification defines that you will default to an
324 interactive mode and stop processing the BootOrder list in this case. This
325 is also a platform implementation and can be customized by IBV/OEM.
327 @param Option Pointer to Boot Option that succeeded to boot.
332 PlatformBdsBootSuccess (
333 IN BDS_COMMON_OPTION
*Option
339 Hook point after a boot attempt fails.
341 @param Option Pointer to Boot Option that failed to boot.
342 @param Status Status returned from failed boot.
343 @param ExitData Exit data returned from failed boot.
344 @param ExitDataSize Exit data size returned from failed boot.
349 PlatformBdsBootFail (
350 IN BDS_COMMON_OPTION
*Option
,
351 IN EFI_STATUS Status
,
353 IN UINTN ExitDataSize
359 This function locks platform flash that is not allowed to be updated during normal boot path.
360 The flash layout is platform specific.
364 PlatformBdsLockNonUpdatableFlash (
373 Lock the ConsoleIn device in system table. All key
374 presses will be ignored until the Password is typed in. The only way to
375 disable the password is to type it in to a ConIn device.
377 @param Password Password used to lock ConIn device.
379 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
380 @retval EFI_UNSUPPORTED Password not found
389 return EFI_UNSUPPORTED
;