3 * Copyright (c) 2011-2012, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "BdsInternal.h"
19 IN OUT CHAR16
*CmdLine
,
31 for (CmdLineIndex
= StrLen (CmdLine
); CmdLineIndex
< MaxCmdLine
; ) {
32 Status
= gBS
->WaitForEvent (1, &gST
->ConIn
->WaitForKey
, &WaitIndex
);
33 ASSERT_EFI_ERROR (Status
);
35 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
36 ASSERT_EFI_ERROR (Status
);
38 // Unicode character is valid when Scancode is NUll
39 if (Key
.ScanCode
== SCAN_NULL
) {
40 // Scan code is NUll, hence read Unicode character
41 Char
= (CHAR8
)Key
.UnicodeChar
;
46 if ((Char
== CHAR_LINEFEED
) || (Char
== CHAR_CARRIAGE_RETURN
) || (Char
== 0x7f)) {
47 CmdLine
[CmdLineIndex
] = '\0';
51 } else if ((Key
.UnicodeChar
== L
'\b') || (Key
.ScanCode
== SCAN_LEFT
) || (Key
.ScanCode
== SCAN_DELETE
)){
52 if (CmdLineIndex
!= 0) {
56 } else if ((Key
.ScanCode
== SCAN_ESC
) || (Char
== 0x1B) || (Char
== 0x0)) {
57 return EFI_INVALID_PARAMETER
;
59 CmdLine
[CmdLineIndex
++] = Key
.UnicodeChar
;
60 Print (L
"%c", Key
.UnicodeChar
);
69 IN OUT CHAR16
*CmdLine
,
75 // For a new input just passed an empty string
78 Status
= EditHIInputStr (CmdLine
, MaxCmdLine
);
85 IN OUT CHAR8
*CmdLine
,
92 Str
= (CHAR16
*)AllocatePool (MaxCmdLine
* sizeof(CHAR16
));
93 AsciiStrToUnicodeStr (CmdLine
, Str
);
95 Status
= EditHIInputStr (Str
, MaxCmdLine
);
96 if (!EFI_ERROR(Status
)) {
97 UnicodeStrToAsciiStr (Str
, CmdLine
);
106 IN OUT CHAR8
*CmdLine
,
110 // For a new input just passed an empty string
113 return EditHIInputAscii (CmdLine
,MaxCmdLine
);
125 Status
= EditHIInputStr (CmdLine
, 255);
126 if (!EFI_ERROR(Status
)) {
127 *Integer
= StrDecimalToUintn (CmdLine
);
135 OUT EFI_IP_ADDRESS
*Ip
143 Status
= EditHIInputStr (CmdLine
,255);
144 if (!EFI_ERROR(Status
)) {
146 Ip
->v4
.Addr
[0] = (UINT8
)StrDecimalToUintn (Str
);
148 Str
= StrStr (Str
, L
".");
150 return EFI_INVALID_PARAMETER
;
153 Ip
->v4
.Addr
[1] = (UINT8
)StrDecimalToUintn (++Str
);
155 Str
= StrStr (Str
, L
".");
157 return EFI_INVALID_PARAMETER
;
160 Ip
->v4
.Addr
[2] = (UINT8
)StrDecimalToUintn (++Str
);
162 Str
= StrStr (Str
, L
".");
164 return EFI_INVALID_PARAMETER
;
167 Ip
->v4
.Addr
[3] = (UINT8
)StrDecimalToUintn (++Str
);
178 CHAR16 CmdBoolean
[2];
183 Status
= GetHIInputStr (CmdBoolean
, 2);
184 if (EFI_ERROR(Status
)) {
186 } else if ((CmdBoolean
[0] == L
'y') || (CmdBoolean
[0] == L
'Y')) {
187 if (Value
) *Value
= TRUE
;
189 } else if ((CmdBoolean
[0] == L
'n') || (CmdBoolean
[0] == L
'N')) {
190 if (Value
) *Value
= FALSE
;
197 HasFilePathEfiExtension (
201 return (StrCmp (FilePath
+ (StrSize(FilePath
)/sizeof(CHAR16
)) - 5, L
".efi") == 0);
204 // Return the last non end-type Device Path Node from a Device Path
206 GetLastDevicePathNode (
207 IN EFI_DEVICE_PATH
* DevicePath
210 EFI_DEVICE_PATH
* PrevDevicePathNode
;
212 PrevDevicePathNode
= DevicePath
;
213 while (!IsDevicePathEndType (DevicePath
)) {
214 PrevDevicePathNode
= DevicePath
;
215 DevicePath
= NextDevicePathNode (DevicePath
);
218 return PrevDevicePathNode
;
222 GenerateDeviceDescriptionName (
223 IN EFI_HANDLE Handle
,
224 IN OUT CHAR16
* Description
228 EFI_COMPONENT_NAME_PROTOCOL
* ComponentName2Protocol
;
229 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
* DevicePathToTextProtocol
;
230 EFI_DEVICE_PATH_PROTOCOL
* DevicePathProtocol
;
232 CHAR16
* DevicePathTxt
;
233 EFI_DEVICE_PATH
* DevicePathNode
;
235 ComponentName2Protocol
= NULL
;
236 Status
= gBS
->HandleProtocol (Handle
, &gEfiComponentName2ProtocolGuid
, (VOID
**)&ComponentName2Protocol
);
237 if (!EFI_ERROR(Status
)) {
238 //TODO: Fixme. we must find the best langague
239 Status
= ComponentName2Protocol
->GetDriverName (ComponentName2Protocol
,"en",&DriverName
);
240 if (!EFI_ERROR(Status
)) {
241 StrnCpy (Description
, DriverName
, BOOT_DEVICE_DESCRIPTION_MAX
);
245 if (EFI_ERROR(Status
)) {
246 // Use the lastest non null entry of the Device path as a description
247 Status
= gBS
->HandleProtocol (Handle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevicePathProtocol
);
248 if (EFI_ERROR(Status
)) {
252 // Convert the last non end-type Device Path Node in text for the description
253 DevicePathNode
= GetLastDevicePathNode (DevicePathProtocol
);
254 Status
= gBS
->LocateProtocol (&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevicePathToTextProtocol
);
255 ASSERT_EFI_ERROR(Status
);
256 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText (DevicePathNode
, TRUE
, TRUE
);
257 StrnCpy (Description
, DevicePathTxt
, BOOT_DEVICE_DESCRIPTION_MAX
);
258 FreePool (DevicePathTxt
);
266 IN CHAR16
* BootOption
270 BDS_LOAD_OPTION
*BdsLoadOption
;
272 Status
= BootOptionFromLoadOptionVariable (BootOption
, &BdsLoadOption
);
273 if (!EFI_ERROR(Status
)) {
274 Status
= BootOptionStart (BdsLoadOption
);
275 FreePool (BdsLoadOption
);
277 if (!EFI_ERROR(Status
)) {
278 Status
= EFI_SUCCESS
;
280 Status
= EFI_NOT_STARTED
;
283 Status
= EFI_NOT_FOUND
;
289 GetUnalignedDevicePathSize (
290 IN EFI_DEVICE_PATH
* DevicePath
294 EFI_DEVICE_PATH
* AlignedDevicePath
;
296 if ((UINTN
)DevicePath
& 0x1) {
297 AlignedDevicePath
= DuplicateDevicePath (DevicePath
);
298 Size
= GetDevicePathSize (AlignedDevicePath
);
299 FreePool (AlignedDevicePath
);
301 Size
= GetDevicePathSize (DevicePath
);
307 GetAlignedDevicePath (
308 IN EFI_DEVICE_PATH
* DevicePath
311 if ((UINTN
)DevicePath
& 0x1) {
312 return DuplicateDevicePath (DevicePath
);