Merged in the following trackers from EDK:

EDK1145 Cursor mising in shell in some case 
EDK1099: Dell - [HII] HiiGetFontInfo() not retrieve the system font by FoFontInfoMask
EDK1127: [UEFI 2.10] Keyboard layout support 
EDK1129: [UEFI HII] GUID is represented wrongly in Config String
And some other fixes such as
*[UEFI HII] HiiGetAltCfg is generating "Name=" sub string in the wrong format 
*UEFI HII: GetUnicodeStringTextOrSize() doesn't handle NULL StringDest properly
*GetFontInfo() need be updated to avoid iteration 
*HIIStringProtocolTest failed on multiple platform
*[Uefi 2.1] Comply with latest Hii ECR 
* GetFontInfo() need be updated to avoid iteration


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5361 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12
2008-06-23 09:41:33 +00:00
parent 54cf87805f
commit 813acf3a9a
18 changed files with 1425 additions and 693 deletions

View File

@@ -27,189 +27,6 @@ Revision History
#ifndef DISABLE_UNUSED_HII_PROTOCOLS
STATIC
CHAR16
NibbleToHexCharPrivate (
IN UINT8 Nibble
)
/*++
Routine Description:
Converts the low nibble of a byte to hex unicode character.
Arguments:
Nibble - lower nibble of a byte.
Returns:
Hex unicode character between L'0' to L'f'.
--*/
{
Nibble &= 0x0F;
if (Nibble <= 0x9) {
return (CHAR16)(Nibble + L'0');
}
return (CHAR16)(Nibble - 0xA + L'a');
}
/**
Converts Unicode string to binary buffer.
The conversion may be partial.
The first character in the string that is not hex digit stops the conversion.
At a minimum, any blob of data could be represented as a hex string.
@param Buf Pointer to buffer that receives the data.
@param Len Length in bytes of the buffer to hold converted
data. If routine return with EFI_SUCCESS,
containing length of converted data. If routine
return with EFI_BUFFER_TOO_SMALL, containg length
of buffer desired.
@param Str String to be converted from.
@param ConvertedStrLen Length of the Hex String consumed.
@retval EFI_SUCCESS Routine Success.
@retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold converted data.
**/
STATIC
EFI_STATUS
HexStringToBufPrivate (
IN OUT UINT8 *Buf,
IN OUT UINTN *Len,
IN CHAR16 *Str,
OUT UINTN *ConvertedStrLen OPTIONAL
)
{
UINTN HexCnt;
UINTN Idx;
UINTN BufferLength;
UINT8 Digit;
UINT8 Byte;
//
// Find out how many hex characters the string has.
//
for (Idx = 0, HexCnt = 0; IsHexDigit (&Digit, Str[Idx]); Idx++, HexCnt++);
if (HexCnt == 0) {
*Len = 0;
return EFI_SUCCESS;
}
//
// Two Unicode characters make up 1 buffer byte. Round up.
//
BufferLength = (HexCnt + 1) / 2;
//
// Test if buffer is passed enough.
//
if (BufferLength > (*Len)) {
*Len = BufferLength;
return EFI_BUFFER_TOO_SMALL;
}
*Len = BufferLength;
for (Idx = 0; Idx < HexCnt; Idx++) {
IsHexDigit (&Digit, Str[Idx]);
//
// For odd charaters, write the lower nibble for each buffer byte,
// and for even characters, the upper nibble.
//
if ((Idx & 1) == 0) {
Byte = (UINT8) (Digit << 4);
} else {
Byte = Buf[Idx / 2];
Byte &= 0xF0;
Byte = (UINT8) (Byte | Digit);
}
Buf[Idx / 2] = Byte;
}
if (ConvertedStrLen != NULL) {
*ConvertedStrLen = HexCnt;
}
return EFI_SUCCESS;
}
/**
Converts binary buffer to Unicode string.
At a minimum, any blob of data could be represented as a hex string.
@param Str Pointer to the string.
@param HexStringBufferLength Length in bytes of buffer to hold the hex string.
Includes tailing '\0' character. If routine return
with EFI_SUCCESS, containing length of hex string
buffer. If routine return with
EFI_BUFFER_TOO_SMALL, containg length of hex
string buffer desired.
@param Buf Buffer to be converted from.
@param Len Length in bytes of the buffer to be converted.
@param Flag If TRUE, encode the data in the same order as the
it resides in the Buf. Else encode it in the
reverse direction.
@retval EFI_SUCCESS Routine success.
@retval EFI_BUFFER_TOO_SMALL The hex string buffer is too small.
**/
STATIC
EFI_STATUS
BufToHexStringPrivate (
IN OUT CHAR16 *Str,
IN OUT UINTN *HexStringBufferLength,
IN UINT8 *Buf,
IN UINTN Len,
IN BOOLEAN Flag
)
{
UINTN Idx;
UINT8 Byte;
UINTN StrLen;
//
// Make sure string is either passed or allocate enough.
// It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.
// Plus the Unicode termination character.
//
StrLen = Len * 2;
if ((*HexStringBufferLength) < (StrLen + 1) * sizeof (CHAR16)) {
*HexStringBufferLength = (StrLen + 1) * sizeof (CHAR16);
return EFI_BUFFER_TOO_SMALL;
}
*HexStringBufferLength = (StrLen + 1) * sizeof (CHAR16);
//
// Ends the string.
//
Str[StrLen] = 0;
for (Idx = 0; Idx < Len; Idx++) {
Byte = Buf[Idx];
if (Flag) {
Str[Idx * 2] = NibbleToHexCharPrivate ((UINT8)(Byte >> 4));
Str[Idx * 2 + 1] = NibbleToHexCharPrivate (Byte);
} else {
Str[StrLen - 1 - Idx * 2] = NibbleToHexCharPrivate (Byte);
Str[StrLen - 2 - Idx * 2] = NibbleToHexCharPrivate ((UINT8)(Byte >> 4));
}
}
return EFI_SUCCESS;
}
/**
Calculate the number of Unicode characters of the incoming Configuration string,
not including NULL terminator.
@@ -306,7 +123,6 @@ GetDevicePath (
// The data in <PathHdr> is encoded as hex UNICODE %02x bytes in the same order
// as the device path resides in RAM memory.
// Translate the data into binary.
// Two Unicode characters make up 1 buffer byte.
//
Length /= 2;
*DevicePath = (UINT8 *) AllocateZeroPool (Length);
@@ -315,7 +131,7 @@ GetDevicePath (
return EFI_OUT_OF_RESOURCES;
}
HexStringToBufPrivate (*DevicePath, &Length, DevicePathString, NULL);
HexStringToBuffer (*DevicePath, &Length, DevicePathString);
SafeFreePool (DevicePathString);
@@ -503,12 +319,11 @@ ExportAllStorage (
@param String A constant string which is the prefix of the to be
generated string, e.g. GUID=
@param BufferLen The length of the Buffer in bytes.
@param Buffer Points to a buffer which will be converted to hex
string and to be the content of the generated
string.
@param Flag If TRUE, convert the buffer data in the same order
as the it resides in the Buffer. Else convert it
in the reverse direction.
@param Buffer Points to a buffer which will be converted to be the
content of the generated string.
@param Flag If 1, the buffer contains data for the value of GUID or PATH stored in
UINT8 *; if 2, the buffer contains unicode string for the value of NAME;
if 3, the buffer contains other data.
@param SubStr Points to the output string. It's caller's
responsibility to free this buffer.
@@ -519,14 +334,15 @@ VOID
GenerateSubStr (
IN CONST EFI_STRING String,
IN UINTN BufferLen,
IN UINT8 *Buffer,
IN BOOLEAN Flag,
IN VOID *Buffer,
IN UINT8 Flag,
OUT EFI_STRING *SubStr
)
{
UINTN Length;
EFI_STRING Str;
EFI_STATUS Status;
EFI_STRING StringHeader;
ASSERT (String != NULL && SubStr != NULL);
@@ -536,20 +352,33 @@ GenerateSubStr (
return ;
}
Length = BufferLen * 2 + 1 + StrLen (String) + 1;
Length = StrLen (String) + BufferLen * 2 + 1 + 1;
Str = AllocateZeroPool (Length * sizeof (CHAR16));
ASSERT (Str != NULL);
StrCpy (Str, String);
Length = (BufferLen * 2 + 1) * sizeof (CHAR16);
Status = BufToHexStringPrivate (
Str + StrLen (String),
&Length,
Buffer,
BufferLen,
Flag
);
Status = EFI_SUCCESS;
StringHeader = Str + StrLen (String);
switch (Flag) {
case 1:
Status = BufferToHexString (StringHeader, (UINT8 *) Buffer, BufferLen);
break;
case 2:
Status = UnicodeToConfigString (StringHeader, &Length, (CHAR16 *) Buffer);
break;
case 3:
Status = BufToHexString (StringHeader, &Length, (UINT8 *) Buffer, BufferLen);
//
// Convert the uppercase to lowercase since <HexAf> is defined in lowercase format.
//
ToLower (StringHeader);
break;
default:
break;
}
ASSERT_EFI_ERROR (Status);
StrCat (Str, L"&");
@@ -1096,7 +925,7 @@ HiiConfigRoutingExportConfig (
if (PathHdr == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Status = BufToHexStringPrivate (PathHdr, &PathHdrSize, (UINT8 *) DevicePath, Length, TRUE);
Status = BufferToHexString (PathHdr, (UINT8 *) DevicePath, Length);
ASSERT_EFI_ERROR (Status);
//
@@ -1104,7 +933,7 @@ HiiConfigRoutingExportConfig (
// It means extract all possible configurations from this specific driver.
//
TmpSize = StrLen (L"GUID=&NAME=&PATH=");
RequestSize = (TmpSize + sizeof (EFI_GUID) * 2 + StrLen (Storage->Name))
RequestSize = (TmpSize + 32 + StrLen (Storage->Name) * 4)
* sizeof (CHAR16) + PathHdrSize;
ConfigRequest = (EFI_STRING) AllocateZeroPool (RequestSize);
if (ConfigRequest == NULL) {
@@ -1115,20 +944,16 @@ HiiConfigRoutingExportConfig (
//
// Add <GuidHdr>
// <GuidHdr> ::= 'GUID='<Guid>
// Convert <Guid> in the same order as it resides in RAM memory.
//
StringPtr = ConfigRequest;
StrnCpy (StringPtr, L"GUID=", StrLen (L"GUID="));
StringPtr += StrLen (L"GUID=");
Status = BufToHexStringPrivate (
StringPtr,
&RequestSize,
(UINT8 *) (&Storage->Guid),
sizeof (EFI_GUID),
FALSE
);
Status = BufferToHexString (StringPtr, (UINT8 *) (&Storage->Guid), sizeof (EFI_GUID));
ASSERT_EFI_ERROR (Status);
StringPtr += RequestSize / 2 - 1;
StringPtr += 32;
ASSERT (*StringPtr == 0);
*StringPtr = L'&';
StringPtr++;
@@ -1139,8 +964,12 @@ HiiConfigRoutingExportConfig (
//
StrnCpy (StringPtr, L"NAME=", StrLen (L"NAME="));
StringPtr += StrLen (L"NAME=");
StrnCpy (StringPtr, Storage->Name, StrLen (Storage->Name));
StringPtr += StrLen (Storage->Name);
Length = (StrLen (Storage->Name) * 4 + 1) * sizeof (CHAR16);
Status = UnicodeToConfigString (StringPtr, &Length, Storage->Name);
ASSERT_EFI_ERROR (Status);
StringPtr += StrLen (Storage->Name) * 4;
*StringPtr = L'&';
StringPtr++;
@@ -1250,7 +1079,7 @@ HiiConfigRoutingExportConfig (
**/
EFI_STATUS
EFIAPI
HiiConfigRoutingRoutConfig (
HiiConfigRoutingRouteConfig (
IN CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *This,
IN CONST EFI_STRING Configuration,
OUT EFI_STRING *Progress
@@ -1609,6 +1438,8 @@ HiiBlockToConfig (
Status = BufToHexString (ValueStr, &Length, Value, Width);
ASSERT_EFI_ERROR (Status);
ToLower (ValueStr);
SafeFreePool (Value);
Value = NULL;
@@ -1955,30 +1786,21 @@ HiiGetAltCfg (
//
// Generate the sub string for later matching.
//
GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (UINT8 *) Guid, FALSE, &GuidStr);
GenerateSubStr (L"GUID=", sizeof (EFI_GUID), (VOID *) Guid, 1, &GuidStr);
GenerateSubStr (
L"PATH=",
GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) DevicePath),
(UINT8 *) DevicePath,
TRUE,
(VOID *) DevicePath,
1,
&PathStr
);
if (AltCfgId != NULL) {
GenerateSubStr (L"ALTCFG=", sizeof (UINT16), (UINT8 *) AltCfgId, FALSE, &AltIdStr);
GenerateSubStr (L"ALTCFG=", sizeof (UINT16), (VOID *) AltCfgId, 3, &AltIdStr);
}
if (Name != NULL) {
Length = StrLen (Name);
Length += StrLen (L"NAME=&") + 1;
NameStr = AllocateZeroPool (Length * sizeof (CHAR16));
if (NameStr == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Exit;
}
StrCpy (NameStr, L"NAME=");
StrCat (NameStr, Name);
StrCat (NameStr, L"&");
GenerateSubStr (L"NAME=", StrLen (Name) * sizeof (CHAR16), (VOID *) Name, 2, &NameStr);
} else {
GenerateSubStr (L"NAME=", 0, NULL, FALSE, &NameStr);
GenerateSubStr (L"NAME=", 0, NULL, 2, &NameStr);
}
while (*StringPtr != 0) {