Sync BaseTools Trunk (version r2518) to EDKII main trunk.

Signed-off-by: Liming Gao <liming.gao@intel.com>


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13178 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lgao4
2012-04-10 07:18:20 +00:00
parent 09e4dbeb5c
commit 64b2609fcf
109 changed files with 1572 additions and 10912 deletions

View File

@@ -1,7 +1,7 @@
## @file
# GNU Make makefile for C tools build.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -22,10 +22,7 @@ ifndef ARCH
ifeq ($(uname_m),x86_64)
ARCH=X64
endif
ifeq ($(uname_m),i386)
ARCH=IA32
endif
ifeq ($(uname_m),i686)
ifeq ($(patsubst i%86,IA32,$(uname_m)),IA32)
ARCH=IA32
endif
ifndef ARCH

View File

@@ -14,4 +14,4 @@
**/
#define __BUILD_VERSION "Build 2474"
#define __BUILD_VERSION "Build 2518"

View File

@@ -3,7 +3,7 @@
IFR is primarily consumed by the EFI presentation engine, and produced by EFI
internal application and drivers as well as all add-in card option-ROM drivers
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
@@ -613,7 +613,7 @@ typedef union {
#define EFI_IFR_INCONSISTENT_IF_OP 0x11
#define EFI_IFR_EQ_ID_VAL_OP 0x12
#define EFI_IFR_EQ_ID_ID_OP 0x13
#define EFI_IFR_EQ_ID_LIST_OP 0x14
#define EFI_IFR_EQ_ID_VAL_LIST_OP 0x14
#define EFI_IFR_AND_OP 0x15
#define EFI_IFR_OR_OP 0x16
#define EFI_IFR_NOT_OP 0x17

View File

@@ -1,7 +1,7 @@
## @file
# Windows makefile for 'LzmaCompress' module build.
#
# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -24,7 +24,8 @@ OBJECTS = \
$(SDK_C)/LzmaDec.o \
$(SDK_C)/LzmaEnc.o \
$(SDK_C)/7zFile.o \
$(SDK_C)/7zStream.o
$(SDK_C)/7zStream.o \
$(SDK_C)/Bra86.o
include $(MAKEROOT)/Makefiles/app.makefile

View File

@@ -5,7 +5,7 @@
LzmaUtil.c -- Test application for LZMA compression
2008-11-23 : Igor Pavlov : Public domain
Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -27,8 +27,17 @@
#include "Sdk/C/7zVersion.h"
#include "Sdk/C/LzmaDec.h"
#include "Sdk/C/LzmaEnc.h"
#include "Sdk/C/Bra.h"
#include "CommonLib.h"
#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + 8)
typedef enum {
NoConverter,
X86Converter,
MaxConverter
} CONVERTER_TYPE;
const char *kCantReadMessage = "Can not read input file";
const char *kCantWriteMessage = "Can not write output file";
const char *kCantAllocateMessage = "Can not allocate memory";
@@ -39,12 +48,13 @@ static void SzFree(void *p, void *address) { p = p; MyFree(address); }
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
static Bool mQuietMode = False;
static CONVERTER_TYPE mConType = NoConverter;
#define UTILITY_NAME "LzmaCompress"
#define UTILITY_MAJOR_VERSION 0
#define UTILITY_MINOR_VERSION 1
#define UTILITY_MINOR_VERSION 2
#define INTEL_COPYRIGHT \
"Copyright (c) 2009, Intel Corporation. All rights reserved."
"Copyright (c) 2009-2012, Intel Corporation. All rights reserved."
void PrintHelp(char *buffer)
{
strcat(buffer,
@@ -54,6 +64,7 @@ void PrintHelp(char *buffer)
" -e: encode file\n"
" -d: decode file\n"
" -o FileName, --output FileName: specify the output filename\n"
" --f86: enable converter for x86 code\n"
" -v, --verbose: increase output messages\n"
" -q, --quiet: reduce output messages\n"
" --debug [0-9]: set debug level\n"
@@ -86,121 +97,151 @@ void PrintVersion(char *buffer)
sprintf (buffer, "%s Version %d.%d %s ", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
}
#define IN_BUF_SIZE (1 << 16)
#define OUT_BUF_SIZE (1 << 16)
static SRes Decode2(CLzmaDec *state, ISeqOutStream *outStream, ISeqInStream *inStream,
UInt64 unpackSize)
static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize)
{
int thereIsSize = (unpackSize != (UInt64)(Int64)-1);
Byte inBuf[IN_BUF_SIZE];
Byte outBuf[OUT_BUF_SIZE];
size_t inPos = 0, inSize = 0, outPos = 0;
LzmaDec_Init(state);
for (;;)
SRes res;
size_t inSize = (size_t)fileSize;
Byte *inBuffer = 0;
Byte *outBuffer = 0;
Byte *filteredStream = 0;
size_t outSize;
CLzmaEncProps props;
LzmaEncProps_Init(&props);
LzmaEncProps_Normalize(&props);
if (inSize != 0) {
inBuffer = (Byte *)MyAlloc(inSize);
if (inBuffer == 0)
return SZ_ERROR_MEM;
} else {
return SZ_ERROR_INPUT_EOF;
}
if (SeqInStream_Read(inStream, inBuffer, inSize) != SZ_OK) {
res = SZ_ERROR_READ;
goto Done;
}
// we allocate 105% of original size + 64KB for output buffer
outSize = (size_t)fileSize / 20 * 21 + (1 << 16);
outBuffer = (Byte *)MyAlloc(outSize);
if (outBuffer == 0) {
res = SZ_ERROR_MEM;
goto Done;
}
{
if (inPos == inSize)
{
inSize = IN_BUF_SIZE;
RINOK(inStream->Read(inStream, inBuf, &inSize));
inPos = 0;
int i;
for (i = 0; i < 8; i++)
outBuffer[i + LZMA_PROPS_SIZE] = (Byte)(fileSize >> (8 * i));
}
if (mConType != NoConverter)
{
filteredStream = (Byte *)MyAlloc(inSize);
if (filteredStream == 0) {
res = SZ_ERROR_MEM;
goto Done;
}
{
SRes res;
SizeT inProcessed = inSize - inPos;
SizeT outProcessed = OUT_BUF_SIZE - outPos;
ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
ELzmaStatus status;
if (thereIsSize && outProcessed > unpackSize)
memcpy(filteredStream, inBuffer, inSize);
if (mConType == X86Converter) {
{
outProcessed = (SizeT)unpackSize;
finishMode = LZMA_FINISH_END;
}
res = LzmaDec_DecodeToBuf(state, outBuf + outPos, &outProcessed,
inBuf + inPos, &inProcessed, finishMode, &status);
inPos += inProcessed;
outPos += outProcessed;
unpackSize -= outProcessed;
if (outStream)
if (outStream->Write(outStream, outBuf, outPos) != outPos)
return SZ_ERROR_WRITE;
outPos = 0;
if (res != SZ_OK || (thereIsSize && unpackSize == 0))
return res;
if (inProcessed == 0 && outProcessed == 0)
{
if (thereIsSize || status != LZMA_STATUS_FINISHED_WITH_MARK)
return SZ_ERROR_DATA;
return res;
UInt32 x86State;
x86_Convert_Init(x86State);
x86_Convert(filteredStream, (SizeT) inSize, 0, &x86State, 1);
}
}
}
}
static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream)
{
UInt64 unpackSize;
int i;
SRes res = 0;
{
size_t outSizeProcessed = outSize - LZMA_HEADER_SIZE;
size_t outPropsSize = LZMA_PROPS_SIZE;
res = LzmaEncode(outBuffer + LZMA_HEADER_SIZE, &outSizeProcessed,
mConType != NoConverter ? filteredStream : inBuffer, inSize,
&props, outBuffer, &outPropsSize, 0,
NULL, &g_Alloc, &g_Alloc);
if (res != SZ_OK)
goto Done;
CLzmaDec state;
outSize = LZMA_HEADER_SIZE + outSizeProcessed;
}
/* header: 5 bytes of LZMA properties and 8 bytes of uncompressed size */
unsigned char header[LZMA_PROPS_SIZE + 8];
if (outStream->Write(outStream, outBuffer, outSize) != outSize)
res = SZ_ERROR_WRITE;
/* Read and parse header */
Done:
MyFree(outBuffer);
MyFree(inBuffer);
MyFree(filteredStream);
RINOK(SeqInStream_Read(inStream, header, sizeof(header)));
unpackSize = 0;
for (i = 0; i < 8; i++)
unpackSize += (UInt64)header[LZMA_PROPS_SIZE + i] << (i * 8);
LzmaDec_Construct(&state);
RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));
res = Decode2(&state, outStream, inStream, unpackSize);
LzmaDec_Free(&state, &g_Alloc);
return res;
}
static SRes Encode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize, char *rs)
static SRes Decode(ISeqOutStream *outStream, ISeqInStream *inStream, UInt64 fileSize)
{
CLzmaEncHandle enc;
SRes res;
CLzmaEncProps props;
size_t inSize = (size_t)fileSize;
Byte *inBuffer = 0;
Byte *outBuffer = 0;
size_t outSize = 0;
size_t inSizePure;
ELzmaStatus status;
UInt64 outSize64 = 0;
rs = rs;
int i;
enc = LzmaEnc_Create(&g_Alloc);
if (enc == 0)
if (inSize < LZMA_HEADER_SIZE)
return SZ_ERROR_INPUT_EOF;
inBuffer = (Byte *)MyAlloc(inSize);
if (inBuffer == 0)
return SZ_ERROR_MEM;
LzmaEncProps_Init(&props);
res = LzmaEnc_SetProps(enc, &props);
if (res == SZ_OK)
{
Byte header[LZMA_PROPS_SIZE + 8];
size_t headerSize = LZMA_PROPS_SIZE;
int i;
res = LzmaEnc_WriteProperties(enc, header, &headerSize);
for (i = 0; i < 8; i++)
header[headerSize++] = (Byte)(fileSize >> (8 * i));
if (outStream->Write(outStream, header, headerSize) != headerSize)
res = SZ_ERROR_WRITE;
else
{
if (res == SZ_OK)
res = LzmaEnc_Encode(enc, outStream, inStream, NULL, &g_Alloc, &g_Alloc);
}
if (SeqInStream_Read(inStream, inBuffer, inSize) != SZ_OK) {
res = SZ_ERROR_READ;
goto Done;
}
LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
for (i = 0; i < 8; i++)
outSize64 += ((UInt64)inBuffer[LZMA_PROPS_SIZE + i]) << (i * 8);
outSize = (size_t)outSize64;
if (outSize != 0) {
outBuffer = (Byte *)MyAlloc(outSize);
if (outBuffer == 0) {
res = SZ_ERROR_MEM;
goto Done;
}
} else {
res = SZ_OK;
goto Done;
}
inSizePure = inSize - LZMA_HEADER_SIZE;
res = LzmaDecode(outBuffer, &outSize, inBuffer + LZMA_HEADER_SIZE, &inSizePure,
inBuffer, LZMA_PROPS_SIZE, LZMA_FINISH_END, &status, &g_Alloc);
if (res != SZ_OK)
goto Done;
if (mConType == X86Converter)
{
UInt32 x86State;
x86_Convert_Init(x86State);
x86_Convert(outBuffer, (SizeT) outSize, 0, &x86State, 0);
}
if (outStream->Write(outStream, outBuffer, outSize) != outSize)
res = SZ_ERROR_WRITE;
Done:
MyFree(outBuffer);
MyFree(inBuffer);
return res;
}
@@ -214,6 +255,7 @@ int main2(int numArgs, const char *args[], char *rs)
const char *inputFile = NULL;
const char *outputFile = "file.tmp";
int param;
UInt64 fileSize;
FileSeqInStream_CreateVTable(&inStream);
File_Construct(&inStream.file);
@@ -231,6 +273,8 @@ int main2(int numArgs, const char *args[], char *rs)
if (strcmp(args[param], "-e") == 0 || strcmp(args[param], "-d") == 0) {
encodeMode = (args[param][1] == 'e');
modeWasSet = True;
} else if (strcmp(args[param], "--f86") == 0) {
mConType = X86Converter;
} else if (strcmp(args[param], "-o") == 0 ||
strcmp(args[param], "--output") == 0) {
if (numArgs < (param + 2)) {
@@ -292,21 +336,21 @@ int main2(int numArgs, const char *args[], char *rs)
if (OutFile_Open(&outStream.file, outputFile) != 0)
return PrintError(rs, "Can not open output file");
File_GetLength(&inStream.file, &fileSize);
if (encodeMode)
{
UInt64 fileSize;
File_GetLength(&inStream.file, &fileSize);
if (!mQuietMode) {
printf("Encoding\n");
}
res = Encode(&outStream.s, &inStream.s, fileSize, rs);
res = Encode(&outStream.s, &inStream.s, fileSize);
}
else
{
if (!mQuietMode) {
printf("Decoding\n");
}
res = Decode(&outStream.s, &inStream.s);
res = Decode(&outStream.s, &inStream.s, fileSize);
}
File_Close(&outStream.file);

View File

@@ -0,0 +1,31 @@
@REM
@REM This script will exec LzmaCompress tool with --f86 option that enables converter for x86 code.
@REM
@REM Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
@REM This program and the accompanying materials
@REM are licensed and made available under the terms and conditions of the BSD License
@REM which accompanies this distribution. The full text of the license may be found at
@REM http://opensource.org/licenses/bsd-license.php
@REM
@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@REM
@echo off
@setlocal
:Begin
if "%1"=="" goto End
if "%1"=="-e" (
set FLAG=--f86
)
if "%1"=="-d" (
set FLAG=--f86
)
set ARGS=%ARGS% %1
shift
goto Begin
:End
LzmaCompress %ARGS% %FLAG%
@echo on

View File

@@ -1,7 +1,7 @@
## @file
# Windows makefile for 'LzmaCompress' module build.
#
# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -25,7 +25,17 @@ OBJECTS = \
$(SDK_C)\LzmaDec.obj \
$(SDK_C)\LzmaEnc.obj \
$(SDK_C)\7zFile.obj \
$(SDK_C)\7zStream.obj
$(SDK_C)\7zStream.obj \
$(SDK_C)\Bra86.obj
!INCLUDE ..\Makefiles\ms.app
all: $(BIN_PATH)\LzmaF86Compress.bat
$(BIN_PATH)\LzmaF86Compress.bat: LzmaF86Compress.bat
copy LzmaF86Compress.bat $(BIN_PATH)\LzmaF86Compress.bat /Y
cleanall: localCleanall
localCleanall:
del /f /q $(BIN_PATH)\LzmaF86Compress.bat > nul

View File

@@ -0,0 +1,60 @@
/* Bra.h -- Branch converters for executables
2008-10-04 : Igor Pavlov : Public domain */
#ifndef __BRA_H
#define __BRA_H
#include "Types.h"
/*
These functions convert relative addresses to absolute addresses
in CALL instructions to increase the compression ratio.
In:
data - data buffer
size - size of data
ip - current virtual Instruction Pinter (IP) value
state - state variable for x86 converter
encoding - 0 (for decoding), 1 (for encoding)
Out:
state - state variable for x86 converter
Returns:
The number of processed bytes. If you call these functions with multiple calls,
you must start next call with first byte after block of processed bytes.
Type Endian Alignment LookAhead
x86 little 1 4
ARMT little 2 2
ARM little 4 0
PPC big 4 0
SPARC big 4 0
IA64 little 16 0
size must be >= Alignment + LookAhead, if it's not last block.
If (size < Alignment + LookAhead), converter returns 0.
Example:
UInt32 ip = 0;
for ()
{
; size must be >= Alignment + LookAhead, if it's not last block
SizeT processed = Convert(data, size, ip, 1);
data += processed;
size -= processed;
ip += processed;
}
*/
#define x86_Convert_Init(state) { state = 0; }
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
#endif

View File

@@ -0,0 +1,85 @@
/* Bra86.c -- Converter for x86 code (BCJ)
2008-10-04 : Igor Pavlov : Public domain */
#include "Bra.h"
#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
{
SizeT bufferPos = 0, prevPosT;
UInt32 prevMask = *state & 0x7;
if (size < 5)
return 0;
ip += 5;
prevPosT = (SizeT)0 - 1;
for (;;)
{
Byte *p = data + bufferPos;
Byte *limit = data + size - 4;
for (; p < limit; p++)
if ((*p & 0xFE) == 0xE8)
break;
bufferPos = (SizeT)(p - data);
if (p >= limit)
break;
prevPosT = bufferPos - prevPosT;
if (prevPosT > 3)
prevMask = 0;
else
{
prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;
if (prevMask != 0)
{
Byte b = p[4 - kMaskToBitNumber[prevMask]];
if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))
{
prevPosT = bufferPos;
prevMask = ((prevMask << 1) & 0x7) | 1;
bufferPos++;
continue;
}
}
}
prevPosT = bufferPos;
if (Test86MSByte(p[4]))
{
UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
UInt32 dest;
for (;;)
{
Byte b;
int index;
if (encoding)
dest = (ip + (UInt32)bufferPos) + src;
else
dest = src - (ip + (UInt32)bufferPos);
if (prevMask == 0)
break;
index = kMaskToBitNumber[prevMask] * 8;
b = (Byte)(dest >> (24 - index));
if (!Test86MSByte(b))
break;
src = dest ^ ((1 << (32 - index)) - 1);
}
p[4] = (Byte)(~(((dest >> 24) & 1) - 1));
p[3] = (Byte)(dest >> 16);
p[2] = (Byte)(dest >> 8);
p[1] = (Byte)dest;
bufferPos += 5;
}
else
{
prevMask = ((prevMask << 1) & 0x7) | 1;
bufferPos++;
}
}
prevPosT = bufferPos - prevPosT;
*state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));
return bufferPos;
}

View File

@@ -1,7 +1,7 @@
## @file
# Windows makefile for C tools build.
#
# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -59,6 +59,7 @@ install: $(LIB_PATH) $(BIN_PATH)
@echo ######################
@-xcopy $(LIB_PATH)\*.lib $(SYS_LIB_PATH) /I /D /E /F /Y > NUL 2>&1
@-xcopy $(BIN_PATH)\*.exe $(SYS_BIN_PATH) /I /D /E /F /Y > NUL 2>&1
@-xcopy $(BIN_PATH)\*.bat $(SYS_BIN_PATH) /I /D /E /F /Y > NUL 2>&1
.PHONY: clean
clean:

View File

@@ -2,7 +2,7 @@
The definition of CFormPkg's member function
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -963,7 +963,7 @@ CIfrRecordInfoDB::CheckIdOpCode (
switch (OpCode) {
case EFI_IFR_EQ_ID_VAL_OP:
case EFI_IFR_EQ_ID_ID_OP:
case EFI_IFR_EQ_ID_LIST_OP:
case EFI_IFR_EQ_ID_VAL_LIST_OP:
case EFI_IFR_QUESTION_REF1_OP:
return TRUE;
default:

View File

@@ -2,7 +2,7 @@
The definition of CFormPkg's member function
Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -1885,8 +1885,8 @@ private:
public:
CIfrEqIdList (
IN UINT32 LineNo
) : CIfrObj (EFI_IFR_EQ_ID_LIST_OP, (CHAR8 **)&mEqIdVList, sizeof (EFI_IFR_EQ_ID_VAL_LIST), TRUE),
CIfrOpHeader (EFI_IFR_EQ_ID_LIST_OP, &mEqIdVList->Header) {
) : CIfrObj (EFI_IFR_EQ_ID_VAL_LIST_OP, (CHAR8 **)&mEqIdVList, sizeof (EFI_IFR_EQ_ID_VAL_LIST), TRUE),
CIfrOpHeader (EFI_IFR_EQ_ID_VAL_LIST_OP, &mEqIdVList->Header) {
SetLineNo (LineNo);
mEqIdVList->QuestionId = EFI_QUESTION_ID_INVALID;
mEqIdVList->ListLength = 0;

View File

@@ -2,7 +2,7 @@
Vfr common library functions.
Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -3067,6 +3067,83 @@ CVfrStringDB::SetStringFileName(IN CHAR8 *StringFileName)
mStringFileName[FileLen - 1] = '\0';
}
/**
Returns TRUE or FALSE whether SupportedLanguages contains the best matching language
from a set of supported languages.
@param[in] SupportedLanguages A pointer to a Null-terminated ASCII string that
contains a set of language codes.
@param[in] Language A variable that contains pointers to Null-terminated
ASCII strings that contain one language codes.
@retval FALSE The best matching language could not be found in SupportedLanguages.
@retval TRUE The best matching language could be found in SupportedLanguages.
**/
BOOLEAN
CVfrStringDB::GetBestLanguage (
IN CONST CHAR8 *SupportedLanguages,
IN CHAR8 *Language
)
{
UINTN CompareLength;
UINTN LanguageLength;
CONST CHAR8 *Supported;
if (SupportedLanguages == NULL || Language == NULL){
return FALSE;
}
//
// Determine the length of the first RFC 4646 language code in Language
//
for (LanguageLength = 0; Language[LanguageLength] != 0 && Language[LanguageLength] != ';'; LanguageLength++);
//
// Trim back the length of Language used until it is empty
//
while (LanguageLength > 0) {
//
// Loop through all language codes in SupportedLanguages
//
for (Supported = SupportedLanguages; *Supported != '\0'; Supported += CompareLength) {
//
// Skip ';' characters in Supported
//
for (; *Supported != '\0' && *Supported == ';'; Supported++);
//
// Determine the length of the next language code in Supported
//
for (CompareLength = 0; Supported[CompareLength] != 0 && Supported[CompareLength] != ';'; CompareLength++);
//
// If Language is longer than the Supported, then skip to the next language
//
if (LanguageLength > CompareLength) {
continue;
}
//
// See if the first LanguageLength characters in Supported match Language
//
if (strncmp (Supported, Language, LanguageLength) == 0) {
return TRUE;
}
}
//
// Trim Language from the right to the next '-' character
//
for (LanguageLength--; LanguageLength > 0 && Language[LanguageLength] != '-'; LanguageLength--);
}
//
// No matches were found
//
return FALSE;
}
CHAR8 *
CVfrStringDB::GetVarStoreNameFormStringId (
IN EFI_STRING_ID StringId
@@ -3122,17 +3199,18 @@ CVfrStringDB::GetVarStoreNameFormStringId (
}
//
// Search the language, only search the "en-US".
// Search the language, get best language base on RFC 4647 matching algorithm.
//
Current = StringPtr;
while (strcmp (PkgHeader->Language, "en-US") != 0) {
while (!GetBestLanguage ("en", PkgHeader->Language)) {
Current += PkgHeader->Header.Length;
PkgHeader = (EFI_HII_STRING_PACKAGE_HDR *) Current;
//
// If can't find "en-US" string package, just return the first string package.
// If can't find string package base on language, just return the first string package.
//
if (Current - StringPtr >= Length) {
Current = StringPtr;
PkgHeader = (EFI_HII_STRING_PACKAGE_HDR *) StringPtr;
break;
}
}

View File

@@ -2,7 +2,7 @@
Vfr common library functions.
Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -438,6 +438,11 @@ private:
UINT32 GetUnicodeStringTextSize (
IN UINT8 *StringSrc
);
BOOLEAN GetBestLanguage (
IN CONST CHAR8 *SupportedLanguages,
IN CHAR8 *Language
);
public:
CVfrStringDB ();