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"
19 /// Predefined platform default time out value
21 UINT16 gPlatformBootTimeOutDefault
;
25 PlatformIntelBdsConstructor (
26 IN EFI_HANDLE ImageHandle
,
27 IN EFI_SYSTEM_TABLE
*SystemTable
30 gPlatformBootTimeOutDefault
= (UINT16
)PcdGet16 (PcdPlatformBootTimeOut
);
35 // BDS Platform Functions
38 Platform Bds init. Include the platform firmware vendor, revision
52 GetConsoleDevicePathFromVariable (
53 IN CHAR16
* ConsoleVarName
,
54 IN CHAR16
* DefaultConsolePaths
,
55 OUT EFI_DEVICE_PATH
** DevicePaths
60 EFI_DEVICE_PATH_PROTOCOL
* DevicePathInstances
;
61 EFI_DEVICE_PATH_PROTOCOL
* DevicePathInstance
;
62 CHAR16
* DevicePathStr
;
63 CHAR16
* NextDevicePathStr
;
64 EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL
*EfiDevicePathFromTextProtocol
;
66 Status
= GetGlobalEnvironmentVariable (ConsoleVarName
, NULL
, NULL
, (VOID
**)&DevicePathInstances
);
67 if (EFI_ERROR(Status
)) {
68 // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)
69 if ((DefaultConsolePaths
== NULL
) || (DefaultConsolePaths
[0] == L
'\0')) {
74 Status
= gBS
->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid
, NULL
, (VOID
**)&EfiDevicePathFromTextProtocol
);
75 ASSERT_EFI_ERROR(Status
);
77 DevicePathInstances
= NULL
;
79 // Extract the Device Path instances from the multi-device path string
80 while ((DefaultConsolePaths
!= NULL
) && (DefaultConsolePaths
[0] != L
'\0')) {
81 NextDevicePathStr
= StrStr (DefaultConsolePaths
, L
";");
82 if (NextDevicePathStr
== NULL
) {
83 DevicePathStr
= DefaultConsolePaths
;
84 DefaultConsolePaths
= NULL
;
86 DevicePathStr
= (CHAR16
*)AllocateCopyPool ((NextDevicePathStr
- DefaultConsolePaths
+ 1) * sizeof(CHAR16
), DefaultConsolePaths
);
87 *(DevicePathStr
+ (NextDevicePathStr
- DefaultConsolePaths
)) = L
'\0';
88 DefaultConsolePaths
= NextDevicePathStr
;
89 if (DefaultConsolePaths
[0] == L
';') {
90 DefaultConsolePaths
++;
94 DevicePathInstance
= EfiDevicePathFromTextProtocol
->ConvertTextToDevicePath (DevicePathStr
);
95 ASSERT(DevicePathInstance
!= NULL
);
96 DevicePathInstances
= AppendDevicePathInstance (DevicePathInstances
, DevicePathInstance
);
98 if (NextDevicePathStr
!= NULL
) {
99 FreePool (DevicePathStr
);
101 FreePool (DevicePathInstance
);
104 // Set the environment variable with this device path multi-instances
105 Size
= GetDevicePathSize (DevicePathInstances
);
109 &gEfiGlobalVariableGuid
,
110 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
115 Status
= EFI_INVALID_PARAMETER
;
119 if (!EFI_ERROR(Status
)) {
120 *DevicePaths
= DevicePathInstances
;
127 InitializeConsolePipe (
128 IN EFI_DEVICE_PATH
*ConsoleDevicePaths
,
129 IN EFI_GUID
*Protocol
,
130 OUT EFI_HANDLE
*Handle
,
138 EFI_DEVICE_PATH_PROTOCOL
* DevicePath
;
140 // Connect all the Device Path Consoles
141 while (ConsoleDevicePaths
!= NULL
) {
142 DevicePath
= GetNextDevicePathInstance (&ConsoleDevicePaths
, &Size
);
144 Status
= BdsConnectDevicePath (DevicePath
, Handle
, NULL
);
146 if (EFI_ERROR(Status
)) {
147 // We convert back to the text representation of the device Path
148 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
* DevicePathToTextProtocol
;
149 CHAR16
* DevicePathTxt
;
152 Status
= gBS
->LocateProtocol(&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevicePathToTextProtocol
);
153 if (!EFI_ERROR(Status
)) {
154 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText (DevicePath
, TRUE
, TRUE
);
156 DEBUG((EFI_D_ERROR
,"Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt
, Status
));
158 FreePool (DevicePathTxt
);
163 // If the console splitter driver is not supported by the platform then use the first Device Path
164 // instance for the console interface.
165 if (!EFI_ERROR(Status
) && (*Interface
== NULL
)) {
166 Status
= gBS
->HandleProtocol (*Handle
, Protocol
, Interface
);
170 // No Device Path has been defined for this console interface. We take the first protocol implementation
171 if (*Interface
== NULL
) {
172 Status
= gBS
->LocateHandleBuffer (ByProtocol
, Protocol
, NULL
, &NoHandles
, &Buffer
);
173 if (EFI_ERROR (Status
)) {
174 BdsConnectAllDrivers ();
175 Status
= gBS
->LocateHandleBuffer (ByProtocol
, Protocol
, NULL
, &NoHandles
, &Buffer
);
178 if (!EFI_ERROR(Status
)) {
180 Status
= gBS
->HandleProtocol (*Handle
, Protocol
, Interface
);
181 ASSERT_EFI_ERROR (Status
);
185 Status
= EFI_SUCCESS
;
192 Connect the predefined platform default console device. Always try to find
193 and enable the vga device if have.
195 @param PlatformConsole Predefined platform default console device array.
197 @retval EFI_SUCCESS Success connect at least one ConIn and ConOut
198 device, there must have one ConOut device is
200 @return Return the status of BdsLibConnectAllDefaultConsoles ()
204 PlatformBdsConnectConsole (
209 EFI_DEVICE_PATH
* ConOutDevicePaths
;
210 EFI_DEVICE_PATH
* ConInDevicePaths
;
211 EFI_DEVICE_PATH
* ConErrDevicePaths
;
213 // By getting the Console Device Paths from the environment variables before initializing the console pipe, we
214 // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface
215 // of newly installed console drivers
216 Status
= GetConsoleDevicePathFromVariable (L
"ConOut", (CHAR16
*)PcdGetPtr(PcdDefaultConOutPaths
), &ConOutDevicePaths
);
217 ASSERT_EFI_ERROR (Status
);
218 Status
= GetConsoleDevicePathFromVariable (L
"ConIn", (CHAR16
*)PcdGetPtr(PcdDefaultConInPaths
), &ConInDevicePaths
);
219 ASSERT_EFI_ERROR (Status
);
220 Status
= GetConsoleDevicePathFromVariable (L
"ErrOut", (CHAR16
*)PcdGetPtr(PcdDefaultConOutPaths
), &ConErrDevicePaths
);
221 ASSERT_EFI_ERROR (Status
);
223 // Initialize the Consoles
224 Status
= InitializeConsolePipe (ConOutDevicePaths
, &gEfiSimpleTextOutProtocolGuid
, &gST
->ConsoleOutHandle
, (VOID
**)&gST
->ConOut
);
225 ASSERT_EFI_ERROR (Status
);
226 Status
= InitializeConsolePipe (ConInDevicePaths
, &gEfiSimpleTextInProtocolGuid
, &gST
->ConsoleInHandle
, (VOID
**)&gST
->ConIn
);
227 ASSERT_EFI_ERROR (Status
);
228 Status
= InitializeConsolePipe (ConErrDevicePaths
, &gEfiSimpleTextOutProtocolGuid
, &gST
->StandardErrorHandle
, (VOID
**)&gST
->StdErr
);
229 if (EFI_ERROR(Status
)) {
230 // In case of error, we reuse the console output for the error output
231 gST
->StandardErrorHandle
= gST
->ConsoleOutHandle
;
232 gST
->StdErr
= gST
->ConOut
;
239 Connect with predefined platform connect sequence,
240 the OEM/IBV can customize with their own connect sequence.
243 PlatformBdsConnectSequence (
250 Load the predefined driver option, OEM/IBV can customize this
251 to load their own drivers
253 @param BdsDriverLists - The header of the driver option link list.
257 PlatformBdsGetDriverOption (
258 IN OUT LIST_ENTRY
*BdsDriverLists
264 Perform the platform diagnostic, such like test memory. OEM/IBV also
265 can customize this function to support specific platform diagnostic.
267 @param MemoryTestLevel The memory test intensive level
268 @param QuietBoot Indicate if need to enable the quiet boot
269 @param BaseMemoryTest A pointer to BdsMemoryTest()
273 PlatformBdsDiagnostics (
274 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
275 IN BOOLEAN QuietBoot
,
276 IN BASEM_MEMORY_TEST BaseMemoryTest
282 The function will execute with as the platform policy, current policy
283 is driven by boot mode. IBV/OEM can customize this code for their specific
286 @param DriverOptionList The header of the driver option link list
287 @param BootOptionList The header of the boot option link list
288 @param ProcessCapsules A pointer to ProcessCapsules()
289 @param BaseMemoryTest A pointer to BaseMemoryTest()
294 PlatformBdsPolicyBehavior (
295 IN LIST_ENTRY
*DriverOptionList
,
296 IN LIST_ENTRY
*BootOptionList
,
297 IN PROCESS_CAPSULES ProcessCapsules
,
298 IN BASEM_MEMORY_TEST BaseMemoryTest
303 Status
= PlatformBdsConnectConsole ();
304 ASSERT_EFI_ERROR (Status
);
308 Hook point after a boot attempt succeeds. We don't expect a boot option to
309 return, so the UEFI 2.0 specification defines that you will default to an
310 interactive mode and stop processing the BootOrder list in this case. This
311 is also a platform implementation and can be customized by IBV/OEM.
313 @param Option Pointer to Boot Option that succeeded to boot.
318 PlatformBdsBootSuccess (
319 IN BDS_COMMON_OPTION
*Option
325 Hook point after a boot attempt fails.
327 @param Option Pointer to Boot Option that failed to boot.
328 @param Status Status returned from failed boot.
329 @param ExitData Exit data returned from failed boot.
330 @param ExitDataSize Exit data size returned from failed boot.
335 PlatformBdsBootFail (
336 IN BDS_COMMON_OPTION
*Option
,
337 IN EFI_STATUS Status
,
339 IN UINTN ExitDataSize
345 This function locks platform flash that is not allowed to be updated during normal boot path.
346 The flash layout is platform specific.
350 PlatformBdsLockNonUpdatableFlash (
359 Lock the ConsoleIn device in system table. All key
360 presses will be ignored until the Password is typed in. The only way to
361 disable the password is to type it in to a ConIn device.
363 @param Password Password used to lock ConIn device.
365 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
366 @retval EFI_UNSUPPORTED Password not found
375 return EFI_UNSUPPORTED
;