summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwei.xu <xuwei5@huawei.com>2014-05-29 09:43:41 +0800
committerWei Xu <xuwei5@huawei.com>2014-10-10 17:26:21 +0800
commit13749358dcd8d4eb43fd4b500bb0bb349b32a2a2 (patch)
tree99ad2253cf30209f627f60433ac8827ae40a7cf4
parent99f933c17b390180fafc1d542aca4822aa2dee82 (diff)
HisiPkg: change to use uefi shell in HisiPkg
Signed-off-by: Wei Xu <xuwei5@huawei.com>
-rw-r--r--HisiPkg/D01BoardPkg/Bds/Bds.c112
-rw-r--r--HisiPkg/D01BoardPkg/Bds/Bds.inf1
-rw-r--r--HisiPkg/D01BoardPkg/Bds/BdsHelper.c98
-rw-r--r--HisiPkg/D01BoardPkg/Bds/BdsInternal.h62
-rw-r--r--HisiPkg/D01BoardPkg/Bds/BootMenu.c388
-rw-r--r--HisiPkg/D01BoardPkg/Bds/BootOption.c95
-rw-r--r--HisiPkg/D01BoardPkg/Bds/BootOptionSupport.c190
7 files changed, 525 insertions, 421 deletions
diff --git a/HisiPkg/D01BoardPkg/Bds/Bds.c b/HisiPkg/D01BoardPkg/Bds/Bds.c
index 429050653..bc4e1f85f 100644
--- a/HisiPkg/D01BoardPkg/Bds/Bds.c
+++ b/HisiPkg/D01BoardPkg/Bds/Bds.c
@@ -299,13 +299,16 @@ DefineDefaultBootEntries (
EFI_STATUS Status;
EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL* EfiDevicePathFromTextProtocol;
EFI_DEVICE_PATH* BootDevicePath;
+ UINT8* OptionalData;
+ UINTN OptionalDataSize;
ARM_BDS_LOADER_ARGUMENTS* BootArguments;
ARM_BDS_LOADER_TYPE BootType;
EFI_DEVICE_PATH* InitrdPath;
- EFI_DEVICE_PATH* FdtLocalPath;
- UINTN CmdLineSize;
UINTN InitrdSize;
- UINTN FdtLocalSize;
+ UINTN CmdLineSize;
+ UINTN CmdLineAsciiSize;
+ CHAR16* DefaultBootArgument;
+ CHAR8* AsciiDefaultBootArgument;
//
// If Boot Order does not exist then create a default entry
@@ -336,63 +339,85 @@ DefineDefaultBootEntries (
ASSERT (StrCmp ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath), DevicePathTxt) == 0);
- if (DevicePathTxt != NULL){
- FreePool (DevicePathTxt);
- }
+ FreePool (DevicePathTxt);
DEBUG_CODE_END();
// Create the entry is the Default values are correct
if (BootDevicePath != NULL) {
BootType = (ARM_BDS_LOADER_TYPE)PcdGet32 (PcdDefaultBootType);
- if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) {
- CmdLineSize = AsciiStrSize ((CHAR8*)PcdGetPtr(PcdDefaultBootArgument));
- InitrdPath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootInitrdPath));
- if (InitrdPath != NULL) {
- InitrdSize = GetDevicePathSize (InitrdPath);
- } else {
- InitrdSize = 0;
+ // We do not support NULL pointer
+ ASSERT (PcdGetPtr (PcdDefaultBootArgument) != NULL);
+
+ //
+ // Logic to handle ASCII or Unicode default parameters
+ //
+ if (*(CHAR8*)PcdGetPtr (PcdDefaultBootArgument) == '\0') {
+ CmdLineSize = 0;
+ CmdLineAsciiSize = 0;
+ DefaultBootArgument = NULL;
+ AsciiDefaultBootArgument = NULL;
+ } else if (IsUnicodeString ((CHAR16*)PcdGetPtr (PcdDefaultBootArgument))) {
+ // The command line is a Unicode string
+ DefaultBootArgument = (CHAR16*)PcdGetPtr (PcdDefaultBootArgument);
+ CmdLineSize = StrSize (DefaultBootArgument);
+
+ // Initialize ASCII variables
+ CmdLineAsciiSize = CmdLineSize / 2;
+ AsciiDefaultBootArgument = AllocatePool (CmdLineAsciiSize);
+ if (AsciiDefaultBootArgument == NULL) {
+ return EFI_OUT_OF_RESOURCES;
}
- if (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT) {
- FdtLocalPath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultFdtLocalDevicePath));
- FdtLocalSize = GetDevicePathSize (FdtLocalPath);
- } else {
- FdtLocalPath = NULL;
- FdtLocalSize = 0;
+ UnicodeStrToAsciiStr ((CHAR16*)PcdGetPtr (PcdDefaultBootArgument), AsciiDefaultBootArgument);
+ } else {
+ // The command line is a ASCII string
+ AsciiDefaultBootArgument = (CHAR8*)PcdGetPtr (PcdDefaultBootArgument);
+ CmdLineAsciiSize = AsciiStrSize (AsciiDefaultBootArgument);
+
+ // Initialize ASCII variables
+ CmdLineSize = CmdLineAsciiSize * 2;
+ DefaultBootArgument = AllocatePool (CmdLineSize);
+ if (DefaultBootArgument == NULL) {
+ return EFI_OUT_OF_RESOURCES;
}
+ AsciiStrToUnicodeStr (AsciiDefaultBootArgument, DefaultBootArgument);
+ }
- BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize + FdtLocalSize);
- if ( BootArguments != NULL ) {
- BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
- BootArguments->LinuxArguments.InitrdSize = InitrdSize;
- BootArguments->LinuxArguments.FdtLocalSize = FdtLocalSize;
+ if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
+ InitrdPath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootInitrdPath));
+ InitrdSize = GetDevicePathSize (InitrdPath);
- CopyMem ((VOID*)(BootArguments + 1), (CHAR8*)PcdGetPtr(PcdDefaultBootArgument), CmdLineSize);
- CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
- CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineSize + InitrdSize), FdtLocalPath, FdtLocalSize);
- }
- if (FdtLocalPath != NULL ) {
- FreePool (FdtLocalPath);
- }
- if (InitrdPath != NULL ) {
- FreePool (InitrdPath);
+ OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineAsciiSize + InitrdSize;
+ BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);
+ if (BootArguments == NULL) {
+ return EFI_OUT_OF_RESOURCES;
}
+ BootArguments->LinuxArguments.CmdLineSize = CmdLineAsciiSize;
+ BootArguments->LinuxArguments.InitrdSize = InitrdSize;
+
+ CopyMem ((VOID*)(BootArguments + 1), AsciiDefaultBootArgument, CmdLineAsciiSize);
+ CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineAsciiSize), InitrdPath, InitrdSize);
+
+ OptionalData = (UINT8*)BootArguments;
} else {
- BootArguments = NULL;
+ OptionalData = (UINT8*)DefaultBootArgument;
+ OptionalDataSize = CmdLineSize;
}
BootOptionCreate (LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_BOOT,
(CHAR16*)PcdGetPtr(PcdDefaultBootDescription),
BootDevicePath,
BootType,
- BootArguments,
+ OptionalData,
+ OptionalDataSize,
&BdsLoadOption
);
- if (BdsLoadOption != NULL){
- FreePool (BdsLoadOption);
- }
- if (BootDevicePath != NULL){
- FreePool (BootDevicePath);
+ FreePool (BdsLoadOption);
+
+ if (DefaultBootArgument == (CHAR16*)PcdGetPtr (PcdDefaultBootArgument)) {
+ FreePool (AsciiDefaultBootArgument);
+ } else if (DefaultBootArgument != NULL) {
+ FreePool (DefaultBootArgument);
}
} else {
Status = EFI_UNSUPPORTED;
@@ -421,8 +446,11 @@ StartDefaultBootOnTimeout (
Size = sizeof(UINT16);
Timeout = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);
- TimeoutPtr = &Timeout;
- GetGlobalEnvironmentVariable (L"Timeout", &Timeout, &Size, (VOID**)&TimeoutPtr);
+ Status = GetGlobalEnvironmentVariable (L"Timeout", &Timeout, &Size, (VOID**)&TimeoutPtr);
+ if (!EFI_ERROR (Status)) {
+ Timeout = *TimeoutPtr;
+ FreePool (TimeoutPtr);
+ }
if (Timeout != 0xFFFF) {
if (Timeout > 0) {
diff --git a/HisiPkg/D01BoardPkg/Bds/Bds.inf b/HisiPkg/D01BoardPkg/Bds/Bds.inf
index 195d0dcd6..f7416bf3c 100644
--- a/HisiPkg/D01BoardPkg/Bds/Bds.inf
+++ b/HisiPkg/D01BoardPkg/Bds/Bds.inf
@@ -75,7 +75,6 @@
gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument
gArmPlatformTokenSpaceGuid.PcdDefaultBootType
gArmPlatformTokenSpaceGuid.PcdFdtDevicePath
- gArmPlatformTokenSpaceGuid.PcdDefaultFdtLocalDevicePath
gArmPlatformTokenSpaceGuid.PcdPlatformBootTimeOut
gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths
gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths
diff --git a/HisiPkg/D01BoardPkg/Bds/BdsHelper.c b/HisiPkg/D01BoardPkg/Bds/BdsHelper.c
index 5896baba7..c07b8af0f 100644
--- a/HisiPkg/D01BoardPkg/Bds/BdsHelper.c
+++ b/HisiPkg/D01BoardPkg/Bds/BdsHelper.c
@@ -1,7 +1,6 @@
/** @file
*
-* Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-* Copyright (c) Huawei Technologies Co., Ltd. 2013. All rights reserved.
+* Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
@@ -188,9 +187,7 @@ GetHIInputBoolean (
while(1) {
Print (L"[y/n] ");
- // Set MaxCmdLine to 3 to give space for carriage return (when the user
- // hits enter) and terminal '\0'.
- Status = GetHIInputStr (CmdBoolean, 3);
+ Status = GetHIInputStr (CmdBoolean, 2);
if (EFI_ERROR(Status)) {
return Status;
} else if ((CmdBoolean[0] == L'y') || (CmdBoolean[0] == L'Y')) {
@@ -326,3 +323,94 @@ GetAlignedDevicePath (
}
}
+BOOLEAN
+IsUnicodeString (
+ IN VOID* String
+ )
+{
+ // We do not support NULL pointer
+ ASSERT (String != NULL);
+
+ if (*(CHAR16*)String < 0x100) {
+ //Note: We could get issue if the string is an empty Ascii string...
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * Try to detect if the given string is an ASCII or Unicode string
+ *
+ * There are actually few limitation to this function but it is mainly to give
+ * a user friendly output.
+ *
+ * Some limitations:
+ * - it only supports unicode string that use ASCII character (< 0x100)
+ * - single character ASCII strings are interpreted as Unicode string
+ * - string cannot be longer than 2 x BOOT_DEVICE_OPTION_MAX (600 bytes)
+ *
+ * @param String Buffer that might contain a Unicode or Ascii string
+ * @param IsUnicode If not NULL this boolean value returns if the string is an
+ * ASCII or Unicode string.
+ */
+BOOLEAN
+IsPrintableString (
+ IN VOID* String,
+ OUT BOOLEAN *IsUnicode
+ )
+{
+ BOOLEAN UnicodeDetected;
+ BOOLEAN IsPrintable;
+ UINTN Index;
+ CHAR16 Character;
+
+ // We do not support NULL pointer
+ ASSERT (String != NULL);
+
+ // Test empty string
+ if (*(CHAR16*)String == L'\0') {
+ if (IsUnicode) {
+ *IsUnicode = TRUE;
+ }
+ return TRUE;
+ } else if (*(CHAR16*)String == '\0') {
+ if (IsUnicode) {
+ *IsUnicode = FALSE;
+ }
+ return TRUE;
+ }
+
+ // Limitation: if the string is an ASCII single character string. This comparison
+ // will assume it is a Unicode string.
+ if (*(CHAR16*)String < 0x100) {
+ UnicodeDetected = TRUE;
+ } else {
+ UnicodeDetected = FALSE;
+ }
+
+ IsPrintable = FALSE;
+ for (Index = 0; Index < BOOT_DEVICE_OPTION_MAX * 2; Index++) {
+ if (UnicodeDetected) {
+ Character = ((CHAR16*)String)[Index];
+ } else {
+ Character = ((CHAR8*)String)[Index];
+ }
+
+ if (Character == '\0') {
+ // End of the string
+ IsPrintable = TRUE;
+ break;
+ } else if ((Character < 0x20) || (Character > 0x7f)) {
+ // We only support the range of printable ASCII character
+ IsPrintable = FALSE;
+ break;
+ }
+ }
+
+ if (IsPrintable && IsUnicode) {
+ *IsUnicode = UnicodeDetected;
+ }
+
+ return IsPrintable;
+}
diff --git a/HisiPkg/D01BoardPkg/Bds/BdsInternal.h b/HisiPkg/D01BoardPkg/Bds/BdsInternal.h
index 12d904a70..447b8c9cd 100644
--- a/HisiPkg/D01BoardPkg/Bds/BdsInternal.h
+++ b/HisiPkg/D01BoardPkg/Bds/BdsInternal.h
@@ -1,7 +1,6 @@
/** @file
*
-* Copyright (c) 2011-2013, ARM Limited. All rights reserved.
-* Copyright (c) Huawei Technologies Co., Ltd. 2013. All rights reserved.
+* Copyright (c) 2011-2014, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
@@ -38,14 +37,12 @@
#define BOOT_DEVICE_OPTION_MAX 300
#define BOOT_DEVICE_ADDRESS_MAX (sizeof(L"0x0000000000000000"))
-// Length of the buffer used to hold the user input for the main menu
-// This includes the NULL terminator
-// 1 chars + newline + NULL gives room for up to 9 boot device configs
-#define BOOT_OPTION_LEN 3
-
#define ARM_BDS_OPTIONAL_DATA_SIGNATURE SIGNATURE_32('a', 'b', 'o', 'd')
-#define IS_ARM_BDS_BOOTENTRY(ptr) (ReadUnaligned32 ((CONST UINT32*)&((ARM_BDS_LOADER_OPTIONAL_DATA*)((ptr)->OptionalData))->Header.Signature) == ARM_BDS_OPTIONAL_DATA_SIGNATURE)
+#define IS_ARM_BDS_BOOTENTRY(ptr) \
+ (((ptr)->OptionalData != NULL) && \
+ (ReadUnaligned32 ((CONST UINT32*)&((ARM_BDS_LOADER_OPTIONAL_DATA*)((ptr)->OptionalData))->Header.Signature) \
+ == ARM_BDS_OPTIONAL_DATA_SIGNATURE))
#define UPDATE_BOOT_ENTRY L"Update entry: "
#define DELETE_BOOT_ENTRY L"Delete entry: "
@@ -53,20 +50,16 @@
typedef enum {
BDS_LOADER_EFI_APPLICATION = 0,
BDS_LOADER_KERNEL_LINUX_ATAG,
- BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT,
- BDS_LOADER_KERNEL_LINUX_LOCAL_FDT,
+ BDS_LOADER_KERNEL_LINUX_FDT,
} ARM_BDS_LOADER_TYPE;
typedef struct {
UINT16 CmdLineSize;
UINT16 InitrdSize;
- UINT16 FdtLocalSize;
-
// These following fields have variable length and are packed:
//CHAR8 *CmdLine;
//EFI_DEVICE_PATH_PROTOCOL *InitrdPathList;
- //EFI_DEVICE_PATH_PROTOCOL *FdtLocalPathList;
} ARM_BDS_LINUX_ARGUMENTS;
typedef union {
@@ -109,8 +102,8 @@ typedef struct _BDS_LOAD_OPTION_SUPPORT {
BDS_SUPPORTED_DEVICE_TYPE Type;
EFI_STATUS (*ListDevices)(IN OUT LIST_ENTRY* BdsLoadOptionList);
BOOLEAN (*IsSupported)(IN EFI_DEVICE_PATH *DevicePath);
- EFI_STATUS (*CreateDevicePathNode)(IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes, OUT ARM_BDS_LOADER_TYPE *BootType, OUT UINT32 *Attributes);
- EFI_STATUS (*UpdateDevicePathNode)(IN EFI_DEVICE_PATH *OldDevicePath, IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath, OUT ARM_BDS_LOADER_TYPE *BootType, OUT UINT32 *Attributes);
+ EFI_STATUS (*CreateDevicePathNode)(IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes, OUT BOOLEAN *RequestBootType);
+ EFI_STATUS (*UpdateDevicePathNode)(IN EFI_DEVICE_PATH *OldDevicePath, IN CHAR16* FileName, OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath, OUT BOOLEAN *RequestBootType);
} BDS_LOAD_OPTION_SUPPORT;
#define LOAD_OPTION_ENTRY_FROM_LINK(a) BASE_CR(a, BDS_LOAD_OPTION_ENTRY, Link)
@@ -226,7 +219,8 @@ BootOptionCreate (
IN CHAR16* BootDescription,
IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
IN ARM_BDS_LOADER_TYPE BootType,
- IN ARM_BDS_LOADER_ARGUMENTS* BootArguments,
+ IN UINT8* OptionalData,
+ IN UINTN OptionalDataSize,
OUT BDS_LOAD_OPTION** BdsLoadOption
);
@@ -237,7 +231,8 @@ BootOptionUpdate (
IN CHAR16* BootDescription,
IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
IN ARM_BDS_LOADER_TYPE BootType,
- IN ARM_BDS_LOADER_ARGUMENTS* BootArguments
+ IN UINT8* OptionalData,
+ IN UINTN OptionalDataSize
);
EFI_STATUS
@@ -246,8 +241,41 @@ BootOptionDelete (
);
EFI_STATUS
+BootDeviceGetType (
+ IN EFI_DEVICE_PATH* DevicePath,
+ OUT ARM_BDS_LOADER_TYPE *BootType,
+ OUT UINT32 *Attributes
+ );
+
+EFI_STATUS
BootMenuMain (
VOID
);
+BOOLEAN
+IsUnicodeString (
+ IN VOID* String
+ );
+
+/*
+ * Try to detect if the given string is an ASCII or Unicode string
+ *
+ * There are actually few limitation to this function but it is mainly to give
+ * a user friendly output.
+ *
+ * Some limitations:
+ * - it only supports unicode string that use ASCII character (< 0x100)
+ * - single character ASCII strings are interpreted as Unicode string
+ * - string cannot be longer than 2 x BOOT_DEVICE_OPTION_MAX (600 bytes)
+ *
+ * @param String Buffer that might contain a Unicode or Ascii string
+ * @param IsUnicode If not NULL this boolean value returns if the string is an
+ * ASCII or Unicode string.
+ */
+BOOLEAN
+IsPrintableString (
+ IN VOID* String,
+ OUT BOOLEAN *IsUnicode
+ );
+
#endif /* _BDSINTERNAL_H_ */
diff --git a/HisiPkg/D01BoardPkg/Bds/BootMenu.c b/HisiPkg/D01BoardPkg/Bds/BootMenu.c
index cade8296f..c9cc4b08d 100644
--- a/HisiPkg/D01BoardPkg/Bds/BootMenu.c
+++ b/HisiPkg/D01BoardPkg/Bds/BootMenu.c
@@ -127,7 +127,8 @@ BootMenuAddBootOption (
BDS_SUPPORTED_DEVICE* SupportedBootDevice;
ARM_BDS_LOADER_ARGUMENTS* BootArguments;
CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];
- CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];
+ CHAR8 AsciiCmdLine[BOOT_DEVICE_OPTION_MAX];
+ CHAR16 CmdLine[BOOT_DEVICE_OPTION_MAX];
UINT32 Attributes;
ARM_BDS_LOADER_TYPE BootType;
BDS_LOAD_OPTION_ENTRY *BdsLoadOptionEntry;
@@ -135,12 +136,12 @@ BootMenuAddBootOption (
EFI_DEVICE_PATH_PROTOCOL *DevicePathNodes;
EFI_DEVICE_PATH_PROTOCOL *InitrdPathNodes;
EFI_DEVICE_PATH_PROTOCOL *InitrdPath;
- EFI_DEVICE_PATH_PROTOCOL *FdtLocalPathNode;
- EFI_DEVICE_PATH_PROTOCOL *FdtLocalPath;
UINTN CmdLineSize;
BOOLEAN InitrdSupport;
UINTN InitrdSize;
- UINTN FdtLocalSize;
+ UINT8* OptionalData;
+ UINTN OptionalDataSize;
+ BOOLEAN RequestBootType;
Attributes = 0;
SupportedBootDevice = NULL;
@@ -153,7 +154,8 @@ BootMenuAddBootOption (
}
// Create the specific device path node
- Status = SupportedBootDevice->Support->CreateDevicePathNode (L"EFI Application or the kernel", &DevicePathNodes, &BootType, &Attributes);
+ RequestBootType = TRUE;
+ Status = SupportedBootDevice->Support->CreateDevicePathNode (L"EFI Application or the kernel", &DevicePathNodes, &RequestBootType);
if (EFI_ERROR(Status)) {
Status = EFI_ABORTED;
goto EXIT;
@@ -165,20 +167,30 @@ BootMenuAddBootOption (
goto EXIT;
}
- if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) {
+ if (RequestBootType) {
+ Status = BootDeviceGetType (DevicePath, &BootType, &Attributes);
+ if (EFI_ERROR(Status)) {
+ Status = EFI_ABORTED;
+ goto EXIT;
+ }
+ } else {
+ BootType = BDS_LOADER_EFI_APPLICATION;
+ }
+
+ if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
Print(L"Add an initrd: ");
Status = GetHIInputBoolean (&InitrdSupport);
if (EFI_ERROR(Status)) {
Status = EFI_ABORTED;
- goto FREE_DEVICE_PATH;
+ goto EXIT;
}
if (InitrdSupport) {
// Create the specific device path node
- Status = SupportedBootDevice->Support->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL, NULL);
+ Status = SupportedBootDevice->Support->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL);
if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
Status = EFI_ABORTED;
- goto FREE_DEVICE_PATH;
+ goto EXIT;
}
if (InitrdPathNodes != NULL) {
@@ -186,7 +198,7 @@ BootMenuAddBootOption (
InitrdPath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);
if (InitrdPath == NULL) {
Status = EFI_OUT_OF_RESOURCES;
- goto FREE_DEVICE_PATH;
+ goto EXIT;
}
} else {
InitrdPath = NULL;
@@ -196,45 +208,34 @@ BootMenuAddBootOption (
}
Print(L"Arguments to pass to the binary: ");
- Status = GetHIInputAscii (CmdLine,BOOT_DEVICE_OPTION_MAX);
+ Status = GetHIInputAscii (AsciiCmdLine, BOOT_DEVICE_OPTION_MAX);
if (EFI_ERROR(Status)) {
Status = EFI_ABORTED;
goto FREE_DEVICE_PATH;
}
- if (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT) {
- // Create the specific device path node
- Status = SupportedBootDevice->Support->CreateDevicePathNode (L"local FDT", &FdtLocalPathNode, NULL, NULL);
- if (EFI_ERROR(Status) || (FdtLocalPathNode == NULL)) {
- Status = EFI_ABORTED;
- goto FREE_DEVICE_PATH;
- }
+ CmdLineSize = AsciiStrSize (AsciiCmdLine);
+ InitrdSize = GetDevicePathSize (InitrdPath);
- if (FdtLocalPathNode != NULL) {
- // Append the Device Path node to the select device path
- FdtLocalPath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)FdtLocalPathNode);
- } else {
- FdtLocalPath = NULL;
- }
- } else {
- FdtLocalPath = NULL;
- }
+ OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;
+ BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);
- CmdLineSize = AsciiStrSize (CmdLine);
- InitrdSize = GetDevicePathSize (InitrdPath);
- FdtLocalSize = GetDevicePathSize (FdtLocalPath);
-
- BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize + FdtLocalSize);
- if ( BootArguments != NULL ) {
- BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
- BootArguments->LinuxArguments.InitrdSize = InitrdSize;
- BootArguments->LinuxArguments.FdtLocalSize = FdtLocalSize;
- CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), CmdLine, CmdLineSize);
- CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
- CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize + InitrdSize), FdtLocalPath, FdtLocalSize);
- }
+ BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
+ BootArguments->LinuxArguments.InitrdSize = InitrdSize;
+ CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), CmdLine, CmdLineSize);
+ CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
+
+ OptionalData = (UINT8*)BootArguments;
} else {
- BootArguments = NULL;
+ Print (L"Arguments to pass to the EFI Application: ");
+ Status = GetHIInputStr (CmdLine, BOOT_DEVICE_OPTION_MAX);
+ if (EFI_ERROR (Status)) {
+ Status = EFI_ABORTED;
+ goto EXIT;
+ }
+
+ OptionalData = (UINT8*)CmdLine;
+ OptionalDataSize = StrSize (CmdLine);
}
Print(L"Description for this new Entry: ");
@@ -246,11 +247,7 @@ BootMenuAddBootOption (
// Create new entry
BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY));
- if ( BdsLoadOptionEntry == NULL ) {
- Status = EFI_ABORTED;
- goto FREE_DEVICE_PATH;
- }
- Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, BootArguments, &BdsLoadOptionEntry->BdsLoadOption);
+ Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize, &BdsLoadOptionEntry->BdsLoadOption);
if (!EFI_ERROR(Status)) {
InsertTailList (BootOptionsList, &BdsLoadOptionEntry->Link);
}
@@ -271,7 +268,6 @@ EFI_STATUS
BootMenuSelectBootOption (
IN LIST_ENTRY* BootOptionsList,
IN CONST CHAR16* InputStatement,
- IN BOOLEAN OnlyArmBdsBootEntry,
OUT BDS_LOAD_OPTION_ENTRY** BdsLoadOptionEntry
)
{
@@ -281,6 +277,7 @@ BootMenuSelectBootOption (
UINTN BootOptionSelected;
UINTN BootOptionCount;
UINTN Index;
+ BOOLEAN IsUnicode;
// Display the list of supported boot devices
BootOptionCount = 0;
@@ -291,10 +288,6 @@ BootMenuSelectBootOption (
{
BdsLoadOption = LOAD_OPTION_FROM_LINK(Entry);
- if (OnlyArmBdsBootEntry && !IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {
- continue;
- }
-
Print (L"[%d] %s\n", (BootOptionCount + 1), BdsLoadOption->Description);
DEBUG_CODE_BEGIN();
@@ -309,9 +302,19 @@ BootMenuSelectBootOption (
Print(L"\t- %s\n",DevicePathTxt);
OptionalData = BdsLoadOption->OptionalData;
- LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);
- if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (LoaderType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) {
- Print (L"\t- Arguments: %a\n",&OptionalData->Arguments.LinuxArguments + 1);
+ if (IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {
+ LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);
+ if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {
+ Print (L"\t- Arguments: %a\n",&OptionalData->Arguments.LinuxArguments + 1);
+ }
+ } else if (OptionalData != NULL) {
+ if (IsPrintableString (OptionalData, &IsUnicode)) {
+ if (IsUnicode) {
+ Print (L"\t- Arguments: %s\n", OptionalData);
+ } else {
+ AsciiPrint ("\t- Arguments: %a\n", OptionalData);
+ }
+ }
}
FreePool(DevicePathTxt);
@@ -371,7 +374,7 @@ BootMenuRemoveBootOption (
EFI_STATUS Status;
BDS_LOAD_OPTION_ENTRY* BootOptionEntry;
- Status = BootMenuSelectBootOption (BootOptionsList, DELETE_BOOT_ENTRY, FALSE, &BootOptionEntry);
+ Status = BootMenuSelectBootOption (BootOptionsList, DELETE_BOOT_ENTRY, &BootOptionEntry);
if (EFI_ERROR(Status)) {
return Status;
}
@@ -400,23 +403,24 @@ BootMenuUpdateBootOption (
ARM_BDS_LOADER_ARGUMENTS* BootArguments;
CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];
CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];
+ CHAR16 UnicodeCmdLine[BOOT_DEVICE_OPTION_MAX];
EFI_DEVICE_PATH *DevicePath;
EFI_DEVICE_PATH *TempInitrdPath;
- EFI_DEVICE_PATH *TempFdtLocalPath;
ARM_BDS_LOADER_TYPE BootType;
- ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;
+ ARM_BDS_LOADER_OPTIONAL_DATA* LoaderOptionalData;
ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;
EFI_DEVICE_PATH *InitrdPathNodes;
EFI_DEVICE_PATH *InitrdPath;
UINTN InitrdSize;
- EFI_DEVICE_PATH *FdtLocalPathNode;
- EFI_DEVICE_PATH *FdtLocalPath;
- UINTN FdtLocalSize;
UINTN CmdLineSize;
BOOLEAN InitrdSupport;
- BOOLEAN FdtLocalSupport;
+ UINT8* OptionalData;
+ UINTN OptionalDataSize;
+ BOOLEAN RequestBootType;
+ BOOLEAN IsPrintable;
+ BOOLEAN IsUnicode;
- Status = BootMenuSelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, TRUE, &BootOptionEntry);
+ Status = BootMenuSelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, &BootOptionEntry);
if (EFI_ERROR(Status)) {
return Status;
}
@@ -429,74 +433,34 @@ BootMenuUpdateBootOption (
return EFI_UNSUPPORTED;
}
- Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath, NULL, NULL);
+ RequestBootType = TRUE;
+ Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath, &RequestBootType);
if (EFI_ERROR(Status)) {
Status = EFI_ABORTED;
goto EXIT;
}
- OptionalData = BootOption->OptionalData;
- BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&OptionalData->Header.LoaderType));
+ if (RequestBootType) {
+ Status = BootDeviceGetType (DevicePath, &BootType, &BootOption->Attributes);
+ if (EFI_ERROR(Status)) {
+ Status = EFI_ABORTED;
+ goto EXIT;
+ }
+ }
+
+ LoaderOptionalData = BootOption->OptionalData;
+ if (LoaderOptionalData != NULL) {
+ BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&LoaderOptionalData->Header.LoaderType));
+ } else {
+ BootType = BDS_LOADER_EFI_APPLICATION;
+ }
- if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) {
- LinuxArguments = &OptionalData->Arguments.LinuxArguments;
+ if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
+ LinuxArguments = &LoaderOptionalData->Arguments.LinuxArguments;
CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);
InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);
- FdtLocalSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->FdtLocalSize);
-
- if (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT) {
- if (FdtLocalSize > 0) {
- Print(L"Keep the local FDT: ");
- } else {
- Print(L"Add a local FDT: ");
- }
- Status = GetHIInputBoolean (&FdtLocalSupport);
- if (EFI_ERROR(Status)) {
- Status = EFI_ABORTED;
- goto EXIT;
- }
- if (FdtLocalSupport && BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT) {
- if (FdtLocalSize > 0) {
- // Case we update the FDT local device path
- Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize + InitrdSize), L"local FDT", &FdtLocalPath, NULL, NULL);
- if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {// EFI_NOT_FOUND is returned on empty input string
- Status = EFI_ABORTED;
- goto EXIT;
- }
- FdtLocalSize = GetDevicePathSize (FdtLocalPath);
- } else {
- // Case we create the FdtLocal device path
-
- Status = DeviceSupport->CreateDevicePathNode (L"local FDT", &FdtLocalPathNode, NULL, NULL);
- if (EFI_ERROR(Status) || (FdtLocalPathNode == NULL)) {
- Status = EFI_ABORTED;
- goto EXIT;
- }
-
- if (FdtLocalPathNode != NULL) {
- // Duplicate Linux kernel Device Path
- TempFdtLocalPath = DuplicateDevicePath (BootOption->FilePathList);
- if ( TempFdtLocalPath != NULL ) {
- // Replace Linux kernel Node by EndNode
- SetDevicePathEndNode (GetLastDevicePathNode (TempFdtLocalPath));
- // Append the Device Path node to the select device path
- FdtLocalPath = AppendDevicePathNode (TempFdtLocalPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)FdtLocalPathNode);
- FreePool (TempFdtLocalPath);
- FdtLocalSize = GetDevicePathSize (FdtLocalPath);
- }
- } else {
- FdtLocalPath = NULL;
- }
- }
- } else {
- FdtLocalSize = 0;
- }
- } else {
- FdtLocalSupport = FALSE;
- }
-
if (InitrdSize > 0) {
Print(L"Keep the initrd: ");
} else {
@@ -511,7 +475,7 @@ BootMenuUpdateBootOption (
if (InitrdSupport) {
if (InitrdSize > 0) {
// Case we update the initrd device path
- Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath, NULL, NULL);
+ Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath, NULL);
if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {// EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
Status = EFI_ABORTED;
goto EXIT;
@@ -520,7 +484,7 @@ BootMenuUpdateBootOption (
} else {
// Case we create the initrd device path
- Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL, NULL);
+ Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL);
if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
Status = EFI_ABORTED;
goto EXIT;
@@ -561,17 +525,58 @@ BootMenuUpdateBootOption (
CmdLineSize = AsciiStrSize (CmdLine);
- BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool(sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize + FdtLocalSize);
- if ( BootArguments != NULL ) {
- BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
- BootArguments->LinuxArguments.InitrdSize = InitrdSize;
- BootArguments->LinuxArguments.FdtLocalSize = FdtLocalSize;
- CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);
- CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
- CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize + InitrdSize), FdtLocalPath, FdtLocalSize);
- }
+ OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;
+ BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);
+ BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
+ BootArguments->LinuxArguments.InitrdSize = InitrdSize;
+ CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);
+ CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
+
+ OptionalData = (UINT8*)BootArguments;
} else {
- BootArguments = NULL;
+ Print (L"Arguments to pass to the EFI Application: ");
+
+ if (BootOption->OptionalDataSize > 0) {
+ IsPrintable = IsPrintableString (BootOption->OptionalData, &IsUnicode);
+ if (IsPrintable) {
+ if (IsUnicode) {
+ StrnCpy (UnicodeCmdLine, BootOption->OptionalData, BootOption->OptionalDataSize / 2);
+ } else {
+ AsciiStrnCpy (CmdLine, BootOption->OptionalData, BootOption->OptionalDataSize);
+ }
+ }
+ } else {
+ UnicodeCmdLine[0] = L'\0';
+ IsPrintable = TRUE;
+ IsUnicode = TRUE;
+ }
+
+ // We do not request arguments for OptionalData that cannot be printed
+ if (IsPrintable) {
+ if (IsUnicode) {
+ Status = EditHIInputStr (UnicodeCmdLine, BOOT_DEVICE_OPTION_MAX);
+ if (EFI_ERROR (Status)) {
+ Status = EFI_ABORTED;
+ goto FREE_DEVICE_PATH;
+ }
+
+ OptionalData = (UINT8*)UnicodeCmdLine;
+ OptionalDataSize = StrSize (UnicodeCmdLine);
+ } else {
+ Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);
+ if (EFI_ERROR (Status)) {
+ Status = EFI_ABORTED;
+ goto FREE_DEVICE_PATH;
+ }
+
+ OptionalData = (UINT8*)CmdLine;
+ OptionalDataSize = AsciiStrSize (CmdLine);
+ }
+ } else {
+ // We keep the former OptionalData
+ OptionalData = BootOption->OptionalData;
+ OptionalDataSize = BootOption->OptionalDataSize;
+ }
}
Print(L"Description for this new Entry: ");
@@ -583,7 +588,7 @@ BootMenuUpdateBootOption (
}
// Update the entry
- Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, BootArguments);
+ Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);
FREE_DEVICE_PATH:
FreePool (DevicePath);
@@ -613,7 +618,7 @@ UpdateFdtPath (
}
// Create the specific device path node
- Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNodes, NULL, NULL);
+ Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNodes, NULL);
if (EFI_ERROR(Status)) {
Status = EFI_ABORTED;
goto EXIT;
@@ -824,23 +829,18 @@ BootMenuMain (
VOID
)
{
- LIST_ENTRY BootOptionsList;
- UINTN OptionCount;
- UINTN BootOptionCount;
- EFI_STATUS Status;
- LIST_ENTRY* Entry;
- BDS_LOAD_OPTION* BootOption;
- UINTN BootOptionSelected;
- UINTN Index;
- UINTN BootMainEntryCount;
- CHAR8 BootOptionSelectedStr[BOOT_OPTION_LEN];
- EFI_DEVICE_PATH_PROTOCOL* DefaultFdtDevicePath;
- UINTN FdtDevicePathSize;
- EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
- CHAR16* DevicePathTxt;
-
-
- BootOption = NULL;
+ LIST_ENTRY BootOptionsList;
+ UINTN OptionCount;
+ UINTN BootOptionCount;
+ EFI_STATUS Status;
+ LIST_ENTRY* Entry;
+ BDS_LOAD_OPTION* BootOption;
+ UINTN BootOptionSelected;
+ UINTN Index;
+ UINTN BootMainEntryCount;
+ BOOLEAN IsUnicode;
+
+ BootOption = NULL;
BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);
while (TRUE) {
@@ -859,10 +859,11 @@ BootMenuMain (
Print(L"[%d] %s\n", OptionCount, BootOption->Description);
- //DEBUG_CODE_BEGIN();
+ DEBUG_CODE_BEGIN();
+ CHAR16* DevicePathTxt;
+ EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;
UINTN CmdLineSize;
- UINTN InitrdSize;
ARM_BDS_LOADER_TYPE LoaderType;
Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
@@ -879,14 +880,16 @@ BootMenuMain (
if (IS_ARM_BDS_BOOTENTRY (BootOption)) {
OptionalData = BootOption->OptionalData;
LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);
- if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (LoaderType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) {
+ if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {
if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {
CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);
DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (
GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);
Print(L"\t- Initrd: %s\n", DevicePathTxt);
}
- Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));
+ if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize) > 0) {
+ Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));
+ }
}
switch (LoaderType) {
@@ -898,64 +901,32 @@ BootMenuMain (
Print(L"\t- LoaderType: Linux kernel with ATAG support\n");
break;
- case BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT:
- Print(L"\t- LoaderType: Linux kernel with global FDT support\n");
- break;
- case BDS_LOADER_KERNEL_LINUX_LOCAL_FDT:
- if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.FdtLocalSize) > 0) {
- CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);
- InitrdSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize);
- DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (
- GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize + InitrdSize)), TRUE, TRUE);
- Print(L"\t- FDT: %s\n", DevicePathTxt);
- } else {
- Print(L"\t- FDT: error, local FDT not specified, using global FDT\n");
- }
- Print(L"\t- LoaderType: Linux kernel with Local FDT\n");
+ case BDS_LOADER_KERNEL_LINUX_FDT:
+ Print(L"\t- LoaderType: Linux kernel with FDT support\n");
break;
+
default:
Print(L"\t- LoaderType: Not recognized (%d)\n", LoaderType);
- break;
+ }
+ } else if (BootOption->OptionalData != NULL) {
+ if (IsPrintableString (BootOption->OptionalData, &IsUnicode)) {
+ if (IsUnicode) {
+ Print (L"\t- Arguments: %s\n", BootOption->OptionalData);
+ } else {
+ AsciiPrint ("\t- Arguments: %a\n", BootOption->OptionalData);
+ }
}
}
FreePool(DevicePathTxt);
- //DEBUG_CODE_END();
+ DEBUG_CODE_END();
OptionCount++;
}
BootOptionCount = OptionCount-1;
- // Display the global FDT config
- Print(L"-----------------------\n");
- {
- EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL* EfiDevicePathFromTextProtocol;
- EFI_DEVICE_PATH_PROTOCOL* FdtDevicePath;
-
- // Get the default FDT device path
- Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);
- ASSERT_EFI_ERROR(Status);
- DefaultFdtDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdFdtDevicePath));
-
- // Get the FDT device path
- FdtDevicePathSize = GetDevicePathSize (DefaultFdtDevicePath);
- Status = GetEnvironmentVariable ((CHAR16 *)L"Fdt", &gArmGlobalVariableGuid, DefaultFdtDevicePath, &FdtDevicePathSize, (VOID **)&FdtDevicePath);
-
- // Convert FdtDevicePath to text
- if (EFI_ERROR(Status)) {
- DevicePathTxt = L"not configured";
- } else {
- Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
- DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText ( FdtDevicePath, TRUE, TRUE );
- }
- Print(L"Global FDT Config\n\t- %s\n", DevicePathTxt);
- FreePool(DevicePathTxt);
- FreePool(DefaultFdtDevicePath);
- }
-
// Display the hardcoded Boot entries
- Print(L"-----------------------\n");
for (Index = 0; Index < BootMainEntryCount; Index++) {
- Print(L"[%c] %s\n", ('a' + Index), BootMainEntries[Index]);
+ Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);
OptionCount++;
}
@@ -963,19 +934,10 @@ BootMenuMain (
BootOptionSelected = 0;
while (BootOptionSelected == 0) {
Print(L"Start: ");
- Status = GetHIInputAscii (BootOptionSelectedStr, BOOT_OPTION_LEN);
-
- if (!EFI_ERROR(Status)) {
- if ((BootOptionSelectedStr[0] - '0') < OptionCount) {
- BootOptionSelected = BootOptionSelectedStr[0] - '0';
- } else if ((BootOptionSelectedStr[0] - 'a') < BootMainEntryCount) {
- BootOptionSelected = BootOptionCount + 1 + BootOptionSelectedStr[0] - 'a';
- }
-
- if ((BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {
- Print(L"Invalid input, please choose a menu option from the list above\n");
- BootOptionSelected = 0;
- }
+ Status = GetHIInputInteger (&BootOptionSelected);
+ if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {
+ Print(L"Invalid input (max %d)\n",(OptionCount-1));
+ BootOptionSelected = 0;
}
}
diff --git a/HisiPkg/D01BoardPkg/Bds/BootOption.c b/HisiPkg/D01BoardPkg/Bds/BootOption.c
index 08ba7a417..52c9d831b 100644
--- a/HisiPkg/D01BoardPkg/Bds/BootOption.c
+++ b/HisiPkg/D01BoardPkg/Bds/BootOption.c
@@ -1,7 +1,6 @@
/** @file
*
-* Copyright (c) 2011-2012, ARM Limited. All rights reserved.
-* Copyright (c) Huawei Technologies Co., Ltd. 2013. All rights reserved.
+* Copyright (c) 2011-2013, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
@@ -34,7 +33,6 @@ BootOptionStart (
UINTN CmdLineSize;
UINTN InitrdSize;
EFI_DEVICE_PATH* Initrd;
- UINTN FdtLocalSize;
UINT16 LoadOptionIndexSize;
if (IS_ARM_BDS_BOOTENTRY (BootOption)) {
@@ -43,8 +41,10 @@ BootOptionStart (
LoaderType = ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);
if (LoaderType == BDS_LOADER_EFI_APPLICATION) {
- // Need to connect every drivers to ensure no dependencies are missing for the application
- BdsConnectAllDrivers();
+ if ((BootOption->Attributes & LOAD_OPTION_CATEGORY_BOOT) == 0) {
+ // Need to connect every drivers to ensure no dependencies are missing for the application
+ BdsConnectAllDrivers ();
+ }
Status = BdsStartEfiApplication (mImageHandle, BootOption->FilePathList, 0, NULL);
} else if (LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) {
@@ -61,7 +61,7 @@ BootOptionStart (
Status = BdsBootLinuxAtag (BootOption->FilePathList,
Initrd, // Initrd
(CHAR8*)(LinuxArguments + 1)); // CmdLine
- } else if ((LoaderType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (LoaderType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) {
+ } else if (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT) {
LinuxArguments = &(OptionalData->Arguments.LinuxArguments);
CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);
InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);
@@ -72,35 +72,31 @@ BootOptionStart (
Initrd = NULL;
}
- if (LoaderType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT) {
- FdtLocalSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->FdtLocalSize);
+ // Get the default FDT device path
+ Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);
+ ASSERT_EFI_ERROR(Status);
+ DefaultFdtDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdFdtDevicePath));
+
+ // Get the FDT device path
+ FdtDevicePathSize = GetDevicePathSize (DefaultFdtDevicePath);
+ Status = GetEnvironmentVariable ((CHAR16 *)L"Fdt", &gArmGlobalVariableGuid,
+ DefaultFdtDevicePath, &FdtDevicePathSize, (VOID **)&FdtDevicePath);
+ ASSERT_EFI_ERROR(Status);
- if (FdtLocalSize > 0) {
- FdtDevicePath = GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize + InitrdSize));
- } else {
- FdtDevicePath = NULL;
- }
- } else {
- // Get the default FDT device path
- Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);
- ASSERT_EFI_ERROR(Status);
- DefaultFdtDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdFdtDevicePath));
-
- // Get the FDT device path
- FdtDevicePathSize = GetDevicePathSize (DefaultFdtDevicePath);
- Status = GetEnvironmentVariable ((CHAR16 *)L"Fdt", &gArmGlobalVariableGuid,
- DefaultFdtDevicePath, &FdtDevicePathSize, (VOID **)&FdtDevicePath);
- ASSERT_EFI_ERROR(Status);
- FreePool (DefaultFdtDevicePath);
- }
Status = BdsBootLinuxFdt (BootOption->FilePathList,
Initrd, // Initrd
(CHAR8*)(LinuxArguments + 1),
FdtDevicePath);
+ FreePool (DefaultFdtDevicePath);
FreePool (FdtDevicePath);
}
} else {
+ // Connect all the drivers if the EFI Application is not a EFI OS Loader
+ if ((BootOption->Attributes & LOAD_OPTION_CATEGORY_BOOT) == 0) {
+ BdsConnectAllDrivers ();
+ }
+
// Set BootCurrent variable
LoadOptionIndexSize = sizeof(UINT16);
gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,
@@ -161,37 +157,37 @@ BootOptionSetFields (
IN CHAR16* BootDescription,
IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
IN ARM_BDS_LOADER_TYPE BootType,
- IN ARM_BDS_LOADER_ARGUMENTS* BootArguments
+ IN UINT8* OptionalData,
+ IN UINTN OptionalDataSize
)
{
EFI_LOAD_OPTION EfiLoadOption;
UINTN EfiLoadOptionSize;
UINTN BootDescriptionSize;
- UINTN BootOptionalDataSize;
UINT16 FilePathListLength;
UINT8* EfiLoadOptionPtr;
UINT8* InitrdPathListPtr;
- UINT8* FdtLocalPathListPtr;
- UINTN OptionalDataSize;
ARM_BDS_LINUX_ARGUMENTS* DestLinuxArguments;
ARM_BDS_LINUX_ARGUMENTS* SrcLinuxArguments;
+ ARM_BDS_LOADER_ARGUMENTS* BootArguments;
// If we are overwriting an existent Boot Option then we have to free previously allocated memory
if (BootOption->LoadOption) {
- FreePool(BootOption->LoadOption);
+ FreePool (BootOption->LoadOption);
}
BootDescriptionSize = StrSize (BootDescription);
- BootOptionalDataSize = sizeof(ARM_BDS_LOADER_OPTIONAL_DATA_HEADER);
- if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) {
- BootOptionalDataSize += sizeof(ARM_BDS_LINUX_ARGUMENTS) + BootArguments->LinuxArguments.CmdLineSize + BootArguments->LinuxArguments.InitrdSize + BootArguments->LinuxArguments.FdtLocalSize;
+
+ // Fixup the size in case of entry specific to ArmPlatformPkg/Bds
+ if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
+ OptionalDataSize += sizeof(ARM_BDS_LOADER_OPTIONAL_DATA_HEADER);
}
// Compute the size of the FilePath list
FilePathListLength = GetUnalignedDevicePathSize (DevicePath);
// Allocate the memory for the EFI Load Option
- EfiLoadOptionSize = sizeof(UINT32) + sizeof(UINT16) + BootDescriptionSize + FilePathListLength + BootOptionalDataSize;
+ EfiLoadOptionSize = sizeof(UINT32) + sizeof(UINT16) + BootDescriptionSize + FilePathListLength + OptionalDataSize;
EfiLoadOption = (EFI_LOAD_OPTION)AllocatePool(EfiLoadOptionSize);
EfiLoadOptionPtr = EfiLoadOption;
@@ -221,34 +217,29 @@ BootOptionSetFields (
// Optional Data fields, Do unaligned writes
BootOption->OptionalData = EfiLoadOptionPtr;
- WriteUnaligned32 ((UINT32 *)EfiLoadOptionPtr, ARM_BDS_OPTIONAL_DATA_SIGNATURE);
- WriteUnaligned32 ((UINT32 *)(EfiLoadOptionPtr + 4), BootType);
- OptionalDataSize = sizeof(ARM_BDS_LOADER_OPTIONAL_DATA_HEADER);
+ if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
+ // Write the header
+ WriteUnaligned32 ((UINT32 *)EfiLoadOptionPtr, ARM_BDS_OPTIONAL_DATA_SIGNATURE);
+ WriteUnaligned32 ((UINT32 *)(EfiLoadOptionPtr + 4), BootType);
- if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT) || (BootType == BDS_LOADER_KERNEL_LINUX_LOCAL_FDT)) {
+ BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)OptionalData;
SrcLinuxArguments = &(BootArguments->LinuxArguments);
DestLinuxArguments = &((ARM_BDS_LOADER_OPTIONAL_DATA*)EfiLoadOptionPtr)->Arguments.LinuxArguments;
WriteUnaligned16 ((UINT16 *)&(DestLinuxArguments->CmdLineSize), SrcLinuxArguments->CmdLineSize);
WriteUnaligned16 ((UINT16 *)&(DestLinuxArguments->InitrdSize), SrcLinuxArguments->InitrdSize);
- WriteUnaligned16 ((UINT16 *)&(DestLinuxArguments->FdtLocalSize), SrcLinuxArguments->FdtLocalSize);
- OptionalDataSize += sizeof (ARM_BDS_LINUX_ARGUMENTS);
if (SrcLinuxArguments->CmdLineSize > 0) {
CopyMem ((VOID*)(DestLinuxArguments + 1), (VOID*)(SrcLinuxArguments + 1), SrcLinuxArguments->CmdLineSize);
- OptionalDataSize += SrcLinuxArguments->CmdLineSize;
}
if (SrcLinuxArguments->InitrdSize > 0) {
InitrdPathListPtr = (UINT8*)((UINTN)(DestLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize);
CopyMem (InitrdPathListPtr, (VOID*)((UINTN)(SrcLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize), SrcLinuxArguments->InitrdSize);
}
-
- if (SrcLinuxArguments->FdtLocalSize > 0) {
- FdtLocalPathListPtr = (UINT8*)((UINTN)(DestLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize + SrcLinuxArguments->InitrdSize);
- CopyMem (FdtLocalPathListPtr, (VOID*)((UINTN)(SrcLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize + SrcLinuxArguments->InitrdSize), SrcLinuxArguments->FdtLocalSize);
- }
+ } else {
+ CopyMem (BootOption->OptionalData, OptionalData, OptionalDataSize);
}
BootOption->OptionalDataSize = OptionalDataSize;
@@ -271,7 +262,8 @@ BootOptionCreate (
IN CHAR16* BootDescription,
IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
IN ARM_BDS_LOADER_TYPE BootType,
- IN ARM_BDS_LOADER_ARGUMENTS* BootArguments,
+ IN UINT8* OptionalData,
+ IN UINTN OptionalDataSize,
OUT BDS_LOAD_OPTION** BdsLoadOption
)
{
@@ -290,7 +282,7 @@ BootOptionCreate (
BootOptionEntry->BdsLoadOption = (BDS_LOAD_OPTION*)AllocateZeroPool (sizeof(BDS_LOAD_OPTION));
BootOption = BootOptionEntry->BdsLoadOption;
- BootOptionSetFields (BootOption, Attributes, BootDescription, DevicePath, BootType, BootArguments);
+ BootOptionSetFields (BootOption, Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);
//
// Set the related environment variables
@@ -344,14 +336,15 @@ BootOptionUpdate (
IN CHAR16* BootDescription,
IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
IN ARM_BDS_LOADER_TYPE BootType,
- IN ARM_BDS_LOADER_ARGUMENTS* BootArguments
+ IN UINT8* OptionalData,
+ IN UINTN OptionalDataSize
)
{
EFI_STATUS Status;
CHAR16 BootVariableName[9];
// Update the BDS Load Option structure
- BootOptionSetFields (BdsLoadOption, Attributes, BootDescription, DevicePath, BootType, BootArguments);
+ BootOptionSetFields (BdsLoadOption, Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);
// Update the related environment variables
UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BdsLoadOption->LoadOptionIndex);
diff --git a/HisiPkg/D01BoardPkg/Bds/BootOptionSupport.c b/HisiPkg/D01BoardPkg/Bds/BootOptionSupport.c
index d5463c6fc..dc70dc4a1 100644
--- a/HisiPkg/D01BoardPkg/Bds/BootOptionSupport.c
+++ b/HisiPkg/D01BoardPkg/Bds/BootOptionSupport.c
@@ -1,7 +1,6 @@
/** @file
*
-* Copyright (c) 2011, ARM Limited. All rights reserved.
-* Copyright (c) Huawei Technologies Co., Ltd. 2013. All rights reserved.
+* Copyright (c) 2011-2014, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
@@ -26,7 +25,6 @@
#include <Guid/FileSystemInfo.h>
#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && ((node)->SubType == (subtype)))
-#define LOCAL_FDT_RESPONSE_LEN 2 // 1 character, plus carriage return
EFI_STATUS
BdsLoadOptionFileSystemList (
@@ -37,8 +35,7 @@ EFI_STATUS
BdsLoadOptionFileSystemCreateDevicePath (
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
);
EFI_STATUS
@@ -46,8 +43,7 @@ BdsLoadOptionFileSystemUpdateDevicePath (
IN EFI_DEVICE_PATH *OldDevicePath,
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
);
BOOLEAN
@@ -64,8 +60,7 @@ EFI_STATUS
BdsLoadOptionMemMapCreateDevicePath (
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
);
EFI_STATUS
@@ -73,8 +68,7 @@ BdsLoadOptionMemMapUpdateDevicePath (
IN EFI_DEVICE_PATH *OldDevicePath,
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
);
BOOLEAN
@@ -91,8 +85,7 @@ EFI_STATUS
BdsLoadOptionPxeCreateDevicePath (
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
);
EFI_STATUS
@@ -100,8 +93,7 @@ BdsLoadOptionPxeUpdateDevicePath (
IN EFI_DEVICE_PATH *OldDevicePath,
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
);
BOOLEAN
@@ -118,8 +110,7 @@ EFI_STATUS
BdsLoadOptionTftpCreateDevicePath (
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
);
EFI_STATUS
@@ -127,8 +118,7 @@ BdsLoadOptionTftpUpdateDevicePath (
IN EFI_DEVICE_PATH *OldDevicePath,
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
);
BOOLEAN
@@ -224,18 +214,44 @@ BootDeviceGetDeviceSupport (
return EFI_UNSUPPORTED;
}
-STATIC
EFI_STATUS
BootDeviceGetType (
- IN CHAR16* FileName,
+ IN EFI_DEVICE_PATH* DevicePath,
OUT ARM_BDS_LOADER_TYPE *BootType,
OUT UINT32 *Attributes
)
{
- EFI_STATUS Status;
- BOOLEAN IsEfiApp;
- BOOLEAN IsBootLoader;
- CHAR16 FDTType[ LOCAL_FDT_RESPONSE_LEN ];
+ EFI_STATUS Status;
+ BOOLEAN IsEfiApp;
+ BOOLEAN IsBootLoader;
+ BOOLEAN HasFDTSupport;
+ CHAR16* FileName;
+ EFI_DEVICE_PATH* PrevDevicePathNode;
+ EFI_DEVICE_PATH* DevicePathNode;
+ EFI_PHYSICAL_ADDRESS Image;
+ UINTN FileSize;
+ EFI_IMAGE_DOS_HEADER* DosHeader;
+ UINTN PeCoffHeaderOffset;
+ EFI_IMAGE_NT_HEADERS32* NtHeader;
+
+ //
+ // Check if the last node of the device path is a FilePath node
+ //
+ PrevDevicePathNode = NULL;
+ DevicePathNode = DevicePath;
+ while ((DevicePathNode != NULL) && !IsDevicePathEnd (DevicePathNode)) {
+ PrevDevicePathNode = DevicePathNode;
+ DevicePathNode = NextDevicePathNode (DevicePathNode);
+ }
+
+ if ((PrevDevicePathNode != NULL) &&
+ (PrevDevicePathNode->Type == MEDIA_DEVICE_PATH) &&
+ (PrevDevicePathNode->SubType == MEDIA_FILEPATH_DP))
+ {
+ FileName = ((FILEPATH_DEVICE_PATH*)PrevDevicePathNode)->PathName;
+ } else {
+ FileName = NULL;
+ }
if (FileName == NULL) {
Print(L"Is an EFI Application? ");
@@ -246,7 +262,41 @@ BootDeviceGetType (
} else if (HasFilePathEfiExtension(FileName)) {
IsEfiApp = TRUE;
} else {
- IsEfiApp = FALSE;
+ // Check if the file exist
+ Status = BdsLoadImage (DevicePath, AllocateAnyPages, &Image, &FileSize);
+ if (!EFI_ERROR (Status)) {
+
+ DosHeader = (EFI_IMAGE_DOS_HEADER *)(UINTN) Image;
+ if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
+ //
+ // DOS image header is present,
+ // so read the PE header after the DOS image header.
+ //
+ PeCoffHeaderOffset = DosHeader->e_lfanew;
+ } else {
+ PeCoffHeaderOffset = 0;
+ }
+
+ //
+ // Check PE/COFF image.
+ //
+ NtHeader = (EFI_IMAGE_NT_HEADERS32 *)(UINTN) (Image + PeCoffHeaderOffset);
+ if (NtHeader->Signature != EFI_IMAGE_NT_SIGNATURE) {
+ IsEfiApp = FALSE;
+ } else {
+ IsEfiApp = TRUE;
+ }
+
+ // Free memory
+ gBS->FreePages (Image, EFI_SIZE_TO_PAGES(FileSize));
+ } else {
+ // If we did not manage to open it then ask for the type
+ Print(L"Is an EFI Application? ");
+ Status = GetHIInputBoolean (&IsEfiApp);
+ if (EFI_ERROR(Status)) {
+ return EFI_ABORTED;
+ }
+ }
}
if (IsEfiApp) {
@@ -260,19 +310,15 @@ BootDeviceGetType (
}
*BootType = BDS_LOADER_EFI_APPLICATION;
} else {
- Print(L"Boot Type: [a] ATAGS, [g] Global FDT or [l] Local FDT? [a/g/l] ");
- Status = GetHIInputStr (FDTType, LOCAL_FDT_RESPONSE_LEN );
+ Print(L"Has FDT support? ");
+ Status = GetHIInputBoolean (&HasFDTSupport);
if (EFI_ERROR(Status)) {
return EFI_ABORTED;
}
- if (StrCmp(FDTType, L"g") == 0) {
- *BootType = BDS_LOADER_KERNEL_LINUX_GLOBAL_FDT;
- } else if (StrCmp(FDTType, L"l") == 0) {
- *BootType = BDS_LOADER_KERNEL_LINUX_LOCAL_FDT;
- } else if (StrCmp(FDTType, L"a") == 0) {
- *BootType = BDS_LOADER_KERNEL_LINUX_ATAG;
+ if (HasFDTSupport) {
+ *BootType = BDS_LOADER_KERNEL_LINUX_FDT;
} else {
- return EFI_ABORTED;
+ *BootType = BDS_LOADER_KERNEL_LINUX_ATAG;
}
}
@@ -339,8 +385,7 @@ EFI_STATUS
BdsLoadOptionFileSystemCreateDevicePath (
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
)
{
EFI_STATUS Status;
@@ -367,16 +412,7 @@ BdsLoadOptionFileSystemCreateDevicePath (
SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);
CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize);
SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize));
-
- if (BootType != NULL || Attributes != NULL) {
- Status = BootDeviceGetType (FilePathDevicePath->PathName, BootType, Attributes);
- }
-
- if (EFI_ERROR(Status)) {
- FreePool (FilePathDevicePath);
- } else {
- *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)FilePathDevicePath;
- }
+ *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)FilePathDevicePath;
return Status;
}
@@ -386,8 +422,7 @@ BdsLoadOptionFileSystemUpdateDevicePath (
IN EFI_DEVICE_PATH *OldDevicePath,
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
)
{
EFI_STATUS Status;
@@ -426,10 +461,6 @@ BdsLoadOptionFileSystemUpdateDevicePath (
*NewDevicePath = AppendDevicePathNode (DevicePath, (CONST EFI_DEVICE_PATH_PROTOCOL *)FilePathDevicePath);
FreePool(DevicePath);
- if (BootType != NULL || Attributes != NULL) {
- return BootDeviceGetType (FilePathDevicePath->PathName, BootType, Attributes);
- }
-
return EFI_SUCCESS;
}
@@ -541,8 +572,7 @@ EFI_STATUS
BdsLoadOptionMemMapCreateDevicePath (
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
)
{
EFI_STATUS Status;
@@ -573,16 +603,7 @@ BdsLoadOptionMemMapCreateDevicePath (
// Set a Device Path End Node after the Memory Map Device Path Node
SetDevicePathEndNode (MemMapDevicePath + 1);
-
- if (BootType != NULL || Attributes != NULL) {
- Status = BootDeviceGetType (NULL, BootType, Attributes);
- }
-
- if (EFI_ERROR(Status)) {
- FreePool (MemMapDevicePath);
- } else {
- *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)MemMapDevicePath;
- }
+ *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)MemMapDevicePath;
return Status;
}
@@ -592,8 +613,7 @@ BdsLoadOptionMemMapUpdateDevicePath (
IN EFI_DEVICE_PATH *OldDevicePath,
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
)
{
EFI_STATUS Status;
@@ -622,10 +642,6 @@ BdsLoadOptionMemMapUpdateDevicePath (
EndingDevicePath->StartingAddress = StrHexToUint64 (StrStartingAddress);
EndingDevicePath->EndingAddress = StrHexToUint64 (StrEndingAddress);
- if (BootType != NULL || Attributes != NULL) {
- Status = BootDeviceGetType (NULL, BootType, Attributes);
- }
-
if (EFI_ERROR(Status)) {
FreePool(DevicePath);
} else {
@@ -699,13 +715,15 @@ EFI_STATUS
BdsLoadOptionPxeCreateDevicePath (
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
)
{
*DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
SetDevicePathEndNode (*DevicePathNodes);
- *BootType = BDS_LOADER_EFI_APPLICATION;
+
+ if (RequestBootType) {
+ *RequestBootType = FALSE;
+ }
return EFI_SUCCESS;
}
@@ -714,12 +732,11 @@ BdsLoadOptionPxeUpdateDevicePath (
IN EFI_DEVICE_PATH *OldDevicePath,
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
)
{
ASSERT (0);
- return EFI_SUCCESS;
+ return EFI_UNSUPPORTED;
}
BOOLEAN
@@ -801,8 +818,7 @@ EFI_STATUS
BdsLoadOptionTftpCreateDevicePath (
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNodes,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
)
{
EFI_STATUS Status;
@@ -868,16 +884,7 @@ BdsLoadOptionTftpCreateDevicePath (
// Set the End Device Path Node
SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize));
-
- if (BootType != NULL || Attributes != NULL) {
- Status = BootDeviceGetType (NULL, BootType, Attributes);
- }
-
- if (EFI_ERROR(Status)) {
- FreePool (IPv4DevicePathNode);
- } else {
- *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)IPv4DevicePathNode;
- }
+ *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)IPv4DevicePathNode;
return Status;
}
@@ -887,12 +894,11 @@ BdsLoadOptionTftpUpdateDevicePath (
IN EFI_DEVICE_PATH *OldDevicePath,
IN CHAR16* FileName,
OUT EFI_DEVICE_PATH_PROTOCOL **NewDevicePath,
- OUT ARM_BDS_LOADER_TYPE *BootType,
- OUT UINT32 *Attributes
+ OUT BOOLEAN *RequestBootType
)
{
ASSERT (0);
- return EFI_SUCCESS;
+ return EFI_UNSUPPORTED;
}
BOOLEAN