ArmPlatformPkg/Bds: Add support to handle Unicode parameters

Most UEFI applications expect unicode string parameter.
This change is allows to support Ascii or Unicode strings.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15450 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Olivier Martin 2014-04-11 10:55:02 +00:00 committed by oliviermartin
parent e213ae4552
commit 9fc9aa46cc
3 changed files with 75 additions and 7 deletions

View File

@ -1,6 +1,6 @@
/** @file
*
* Copyright (c) 2011-2013, ARM Limited. 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
@ -223,8 +223,11 @@ DefineDefaultBootEntries (
ARM_BDS_LOADER_ARGUMENTS* BootArguments;
ARM_BDS_LOADER_TYPE BootType;
EFI_DEVICE_PATH* InitrdPath;
UINTN CmdLineSize;
UINTN InitrdSize;
UINTN CmdLineSize;
UINTN CmdLineAsciiSize;
CHAR16* DefaultBootArgument;
CHAR8* AsciiDefaultBootArgument;
//
// If Boot Order does not exist then create a default entry
@ -262,17 +265,56 @@ DefineDefaultBootEntries (
if (BootDevicePath != NULL) {
BootType = (ARM_BDS_LOADER_TYPE)PcdGet32 (PcdDefaultBootType);
// 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;
}
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);
}
if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
CmdLineSize = AsciiStrSize ((CHAR8*)PcdGetPtr(PcdDefaultBootArgument));
InitrdPath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootInitrdPath));
InitrdSize = GetDevicePathSize (InitrdPath);
BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);
BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineAsciiSize + InitrdSize);
if (BootArguments == NULL) {
return EFI_OUT_OF_RESOURCES;
}
BootArguments->LinuxArguments.CmdLineSize = CmdLineAsciiSize;
BootArguments->LinuxArguments.InitrdSize = InitrdSize;
CopyMem ((VOID*)(BootArguments + 1), (CHAR8*)PcdGetPtr(PcdDefaultBootArgument), CmdLineSize);
CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
CopyMem ((VOID*)(BootArguments + 1), AsciiDefaultBootArgument, CmdLineAsciiSize);
CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineAsciiSize), InitrdPath, InitrdSize);
} else {
BootArguments = NULL;
}
@ -285,6 +327,12 @@ DefineDefaultBootEntries (
&BdsLoadOption
);
FreePool (BdsLoadOption);
if (DefaultBootArgument == (CHAR16*)PcdGetPtr (PcdDefaultBootArgument)) {
FreePool (AsciiDefaultBootArgument);
} else {
FreePool (DefaultBootArgument);
}
} else {
Status = EFI_UNSUPPORTED;
}

View File

@ -323,3 +323,18 @@ 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;
}
}

View File

@ -243,4 +243,9 @@ BootMenuMain (
VOID
);
BOOLEAN
IsUnicodeString (
IN VOID* String
);
#endif /* _BDSINTERNAL_H_ */