3 * Copyright (c) 2011, 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
);
97 if (!EFI_ERROR(Status
)) {
98 UnicodeStrToAsciiStr (Str
, CmdLine
);
107 IN OUT CHAR8
*CmdLine
,
111 // For a new input just passed an empty string
114 return EditHIInputAscii (CmdLine
,MaxCmdLine
);
126 Status
= EditHIInputStr (CmdLine
, 255);
127 if (!EFI_ERROR(Status
)) {
128 *Integer
= StrDecimalToUintn (CmdLine
);
136 OUT EFI_IP_ADDRESS
*Ip
144 Status
= EditHIInputStr (CmdLine
,255);
145 if (!EFI_ERROR(Status
)) {
147 Ip
->v4
.Addr
[0] = (UINT8
)StrDecimalToUintn (Str
);
149 Str
= StrStr (Str
, L
".");
151 return EFI_INVALID_PARAMETER
;
154 Ip
->v4
.Addr
[1] = (UINT8
)StrDecimalToUintn (++Str
);
156 Str
= StrStr (Str
, L
".");
158 return EFI_INVALID_PARAMETER
;
161 Ip
->v4
.Addr
[2] = (UINT8
)StrDecimalToUintn (++Str
);
163 Str
= StrStr (Str
, L
".");
165 return EFI_INVALID_PARAMETER
;
168 Ip
->v4
.Addr
[3] = (UINT8
)StrDecimalToUintn (++Str
);
179 CHAR16 CmdBoolean
[2];
184 Status
= GetHIInputStr (CmdBoolean
,2);
185 if (EFI_ERROR(Status
)) {
187 } else if ((CmdBoolean
[0] == L
'y') || (CmdBoolean
[0] == L
'Y')) {
188 if (Value
) *Value
= TRUE
;
190 } else if ((CmdBoolean
[0] == L
'n') || (CmdBoolean
[0] == L
'N')) {
191 if (Value
) *Value
= FALSE
;
198 HasFilePathEfiExtension (
202 return (StrCmp (FilePath
+ (StrSize(FilePath
)/sizeof(CHAR16
)) - 5, L
".efi") == 0);
205 // Return the last non end-type Device Path Node from a Device Path
207 GetLastDevicePathNode (
208 IN EFI_DEVICE_PATH
* DevicePath
211 EFI_DEVICE_PATH
* PrevDevicePathNode
;
213 PrevDevicePathNode
= DevicePath
;
214 while (!IsDevicePathEndType (DevicePath
)) {
215 PrevDevicePathNode
= DevicePath
;
216 DevicePath
= NextDevicePathNode (DevicePath
);
219 return PrevDevicePathNode
;
223 GenerateDeviceDescriptionName (
224 IN EFI_HANDLE Handle
,
225 IN OUT CHAR16
* Description
229 EFI_COMPONENT_NAME_PROTOCOL
* ComponentName2Protocol
;
230 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
* DevicePathToTextProtocol
;
231 EFI_DEVICE_PATH_PROTOCOL
* DevicePathProtocol
;
233 CHAR16
* DevicePathTxt
;
234 EFI_DEVICE_PATH
* DevicePathNode
;
236 ComponentName2Protocol
= NULL
;
237 Status
= gBS
->HandleProtocol (Handle
, &gEfiComponentName2ProtocolGuid
, (VOID
**)&ComponentName2Protocol
);
238 if (!EFI_ERROR(Status
)) {
239 //TODO: Fixme. we must find the best langague
240 Status
= ComponentName2Protocol
->GetDriverName (ComponentName2Protocol
,"en",&DriverName
);
241 if (!EFI_ERROR(Status
)) {
242 StrnCpy (Description
, DriverName
, BOOT_DEVICE_DESCRIPTION_MAX
);
246 if (EFI_ERROR(Status
)) {
247 // Use the lastest non null entry of the Device path as a description
248 Status
= gBS
->HandleProtocol (Handle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevicePathProtocol
);
249 if (EFI_ERROR(Status
)) {
253 // Convert the last non end-type Device Path Node in text for the description
254 DevicePathNode
= GetLastDevicePathNode (DevicePathProtocol
);
255 Status
= gBS
->LocateProtocol (&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevicePathToTextProtocol
);
256 ASSERT_EFI_ERROR(Status
);
257 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText (DevicePathNode
, TRUE
, TRUE
);
258 StrnCpy (Description
, DevicePathTxt
, BOOT_DEVICE_DESCRIPTION_MAX
);
259 FreePool (DevicePathTxt
);
267 IN CHAR16
* BootOption
271 BDS_LOAD_OPTION
*BdsLoadOption
;
273 Status
= BootOptionFromLoadOptionVariable (BootOption
, &BdsLoadOption
);
274 if (!EFI_ERROR(Status
)) {
275 Status
= BootOptionStart (BdsLoadOption
);
276 FreePool (BdsLoadOption
);
278 if (!EFI_ERROR(Status
)) {
279 Status
= EFI_SUCCESS
;
281 Status
= EFI_NOT_STARTED
;
284 Status
= EFI_NOT_FOUND
;
290 GetUnalignedDevicePathSize (
291 IN EFI_DEVICE_PATH
* DevicePath
295 EFI_DEVICE_PATH
* AlignedDevicePath
;
297 if ((UINTN
)DevicePath
& 0x1) {
298 AlignedDevicePath
= DuplicateDevicePath (DevicePath
);
299 Size
= GetDevicePathSize (AlignedDevicePath
);
300 FreePool (AlignedDevicePath
);
302 Size
= GetDevicePathSize (DevicePath
);
308 GetAlignedDevicePath (
309 IN EFI_DEVICE_PATH
* DevicePath
312 if ((UINTN
)DevicePath
& 0x1) {
313 return DuplicateDevicePath (DevicePath
);