From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 808161A1E3D for ; Tue, 20 Sep 2016 19:41:42 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP; 20 Sep 2016 19:41:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,371,1470726000"; d="scan'208";a="11538336" Received: from shwde7172.ccr.corp.intel.com ([10.239.9.23]) by fmsmga005.fm.intel.com with ESMTP; 20 Sep 2016 19:41:41 -0700 From: Liming Gao To: edk2-devel@lists.01.org Date: Wed, 21 Sep 2016 10:39:11 +0800 Message-Id: <1474425551-9056-4-git-send-email-liming.gao@intel.com> X-Mailer: git-send-email 2.8.0.windows.1 In-Reply-To: <1474425551-9056-1-git-send-email-liming.gao@intel.com> References: <1474425551-9056-1-git-send-email-liming.gao@intel.com> Subject: [Patch 3/3] BaseTools: support generating image package from BMP/JPEG/PNG files X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Sep 2016 02:41:42 -0000 From: Yonghong Zhu BaseTools add support to generating image package from BMP/JPEG/PNG files. 1) New file type *.idf Image definition file to describe HII image resource. It is the ASCII text file, and includes one or more "#image IMAGE_ID [TRANSPARENT] ImageFileName". 2) New IMAGE_TOKEN macro is used to refer to IMAGE_ID. 3) New AutoGen header file $(MODULE_NAME)ImgDefs.h to include the generated ImageId definition. 4) New $(MODULE_NAME)Idf.hpk or $(MODULE_NAME)Images are generated as the output binary HII image package. Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yonghong Zhu --- BaseTools/Conf/build_rule.template | 21 ++ BaseTools/Source/Python/AutoGen/AutoGen.py | 31 ++- BaseTools/Source/Python/AutoGen/GenC.py | 245 +++++++++++++++++++++- BaseTools/Source/Python/AutoGen/IdfClassObject.py | 159 ++++++++++++++ BaseTools/Source/Python/AutoGen/StrGather.py | 4 +- BaseTools/Source/Python/Common/DataType.py | 1 + 6 files changed, 455 insertions(+), 6 deletions(-) create mode 100644 BaseTools/Source/Python/AutoGen/IdfClassObject.py diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template index 7e2c6a9..1db94b6 100755 --- a/BaseTools/Conf/build_rule.template +++ b/BaseTools/Conf/build_rule.template @@ -568,6 +568,17 @@ +[Image-Definition-File] + + *.idf, *.Idf, *.IDF + + + $(DEBUG_DIR)(+)AutoGen.c + $(DEBUG_DIR)(+)$(MODULE_NAME)ImgDefs.h + $(OUTPUT_DIR)(+)$(MODULE_NAME)Idf.hpk + + + [Efi-Image.UEFI_OPTIONROM] ?.efi, ?.EFI, ?.Efi @@ -588,6 +599,16 @@ +[Image-Definition-File.UEFI_HII] + + *.idf, *.Idf, *.IDF + + + $(DEBUG_DIR)(+)$(MODULE_NAME)ImgDefs.h + $(OUTPUT_DIR)(+)$(MODULE_NAME)Idf.hpk + + + [Visual-Form-Representation-File.UEFI_HII] ?.vfr diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py index 79bc7c6..f35ae25 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -72,7 +72,8 @@ gAutoGenHeaderFileName = "AutoGen.h" gAutoGenStringFileName = "%(module_name)sStrDefs.h" gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk" gAutoGenDepexFileName = "%(module_name)s.depex" - +gAutoGenImageDefFileName = "%(module_name)sImgDefs.h" +gAutoGenIdfFileName = "%(module_name)sIdf.hpk" gInfSpecVersion = "0x00010017" # @@ -2590,6 +2591,7 @@ class ModuleAutoGen(AutoGen): self._IncludePathLength = 0 self._AutoGenFileList = None self._UnicodeFileList = None + self._IdfFileList = None self._SourceFileList = None self._ObjectFileList = None self._BinaryFileList = None @@ -3114,6 +3116,15 @@ class ModuleAutoGen(AutoGen): self._UnicodeFileList = [] return self._UnicodeFileList + ## Return the list of Image Definition files + def _GetIdfFileList(self): + if self._IdfFileList == None: + if TAB_IMAGE_FILE in self.FileTypes: + self._IdfFileList = self.FileTypes[TAB_IMAGE_FILE] + else: + self._IdfFileList = [] + return self._IdfFileList + ## Return a list of files which can be built from binary # # "Build" binary files are just to copy them to build directory. @@ -3276,15 +3287,19 @@ class ModuleAutoGen(AutoGen): # def _GetAutoGenFileList(self): UniStringAutoGenC = True + IdfStringAutoGenC = True UniStringBinBuffer = StringIO() + IdfGenBinBuffer = StringIO() if self.BuildType == 'UEFI_HII': UniStringAutoGenC = False + IdfStringAutoGenC = False if self._AutoGenFileList == None: self._AutoGenFileList = {} AutoGenC = TemplateString() AutoGenH = TemplateString() StringH = TemplateString() - GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer) + StringIdf = TemplateString() + GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer, StringIdf, IdfStringAutoGenC, IdfGenBinBuffer) # # AutoGen.c is generated if there are library classes in inf, or there are object files # @@ -3308,6 +3323,17 @@ class ModuleAutoGen(AutoGen): self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE) if UniStringBinBuffer != None: UniStringBinBuffer.close() + if str(StringIdf) != "": + AutoFile = PathClass(gAutoGenImageDefFileName % {"module_name":self.Name}, self.DebugDir) + self._AutoGenFileList[AutoFile] = str(StringIdf) + self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE) + if IdfGenBinBuffer != None and IdfGenBinBuffer.getvalue() != "": + AutoFile = PathClass(gAutoGenIdfFileName % {"module_name":self.Name}, self.OutputDir) + self._AutoGenFileList[AutoFile] = IdfGenBinBuffer.getvalue() + AutoFile.IsBinary = True + self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE) + if IdfGenBinBuffer != None: + IdfGenBinBuffer.close() return self._AutoGenFileList ## Return the list of library modules explicitly or implicityly used by this module @@ -4061,6 +4087,7 @@ class ModuleAutoGen(AutoGen): CodaTargetList = property(_GetFinalTargetList) FileTypes = property(_GetFileTypes) BuildRules = property(_GetBuildRules) + IdfFileList = property(_GetIdfFileList) DependentPackageList = property(_GetDependentPackageList) DependentLibraryList = property(_GetLibraryList) diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py index 29951e3..8089e3a 100644 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -14,7 +14,8 @@ ## Import Modules # import string - +import collections +import struct from Common import EdkLogger from Common.BuildToolError import * @@ -23,6 +24,7 @@ from Common.Misc import * from Common.String import StringToArray from StrGather import * from GenPcdDb import CreatePcdDatabaseCode +from IdfClassObject import * ## PCD type string gItemTypeStringDatabase = { @@ -1619,6 +1621,232 @@ def CreateUnicodeStringCode(Info, AutoGenC, AutoGenH, UniGenCFlag, UniGenBinBuff AutoGenH.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info.Name) os.chdir(WorkingDir) +def CreateIdfFileCode(Info, AutoGenC, StringH, IdfGenCFlag, IdfGenBinBuffer): + if len(Info.IdfFileList) > 0: + ImageFiles = IdfFileClassObject(sorted (Info.IdfFileList)) + if ImageFiles.ImageFilesDict: + Index = 1 + PaletteIndex = 1 + IncList = [Info.MetaFile.Dir] + SrcList = [F for F in Info.SourceFileList] + SkipList = ['.jpg', '.png', '.bmp', '.inf', '.idf'] + FileList = GetFileList(SrcList, IncList, SkipList) + ValueStartPtr = 60 + StringH.Append("\n//\n//Image ID\n//\n") + ImageInfoOffset = 0 + PaletteInfoOffset = 0 + ImageBuffer = pack('x') + PaletteBuffer = pack('x') + BufferStr = '' + PaletteStr = '' + for Idf in ImageFiles.ImageFilesDict: + if ImageFiles.ImageFilesDict[Idf]: + for FileObj in ImageFiles.ImageFilesDict[Idf]: + for sourcefile in Info.SourceFileList: + if FileObj.FileName == sourcefile.File: + if not sourcefile.Ext.upper() in ['.PNG', '.BMP', '.JPG']: + EdkLogger.error("build", AUTOGEN_ERROR, "The %s's postfix must be one of .bmp, .jpg, .png" % (FileObj.FileName), ExtraData="[%s]" % str(Info)) + FileObj.File = sourcefile + break + else: + EdkLogger.error("build", AUTOGEN_ERROR, "The %s in %s is not defined in the driver's [Sources] section" % (FileObj.FileName, Idf), ExtraData="[%s]" % str(Info)) + + for FileObj in ImageFiles.ImageFilesDict[Idf]: + ID = FileObj.ImageID + File = FileObj.File + if not os.path.exists(File.Path) or not os.path.isfile(File.Path): + EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=File.Path) + SearchImageID (FileObj, FileList) + if FileObj.Referenced: + if (ValueStartPtr - len(DEFINE_STR + ID)) <= 0: + Line = DEFINE_STR + ' ' + ID + ' ' + DecToHexStr(Index, 4) + '\n' + else: + Line = DEFINE_STR + ' ' + ID + ' ' * (ValueStartPtr - len(DEFINE_STR + ID)) + DecToHexStr(Index, 4) + '\n' + + TmpFile = open(File.Path, 'rb') + Buffer = TmpFile.read() + TmpFile.close() + if File.Ext.upper() == '.PNG': + TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_PNG) + TempBuffer += pack('I', len(Buffer)) + TempBuffer += Buffer + elif File.Ext.upper() == '.JPG': + ImageType, = struct.unpack('4s', Buffer[6:10]) + if ImageType != 'JFIF': + EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard JPG file." % File.Path) + TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_JPEG) + TempBuffer += pack('I', len(Buffer)) + TempBuffer += Buffer + elif File.Ext.upper() == '.BMP': + TempBuffer, TempPalette = BmpImageDecoder(File, Buffer, PaletteIndex, FileObj.TransParent) + if len(TempPalette) > 1: + PaletteIndex += 1 + PaletteBuffer += pack('H', len(TempPalette)) + PaletteBuffer += TempPalette + PaletteStr = WriteLine(PaletteStr, '// %s: %s: %s' % (DecToHexStr(PaletteIndex - 1, 4), ID, DecToHexStr(PaletteIndex - 1, 4))) + TempPaletteList = AscToHexList(TempPalette) + PaletteStr = WriteLine(PaletteStr, CreateArrayItem(TempPaletteList, 16) + '\n') + ImageBuffer += TempBuffer + BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4))) + TempBufferList = AscToHexList(TempBuffer) + BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n') + + StringH.Append(Line) + Index += 1 + + BufferStr = WriteLine(BufferStr, '// End of the Image Info') + BufferStr = WriteLine(BufferStr, CreateArrayItem(DecToHexList(EFI_HII_IIBT_END, 2)) + '\n') + ImageEnd = pack('B', EFI_HII_IIBT_END) + ImageBuffer += ImageEnd + + if len(ImageBuffer) > 1: + ImageInfoOffset = 12 + if len(PaletteBuffer) > 1: + PaletteInfoOffset = 12 + len(ImageBuffer) - 1 # -1 is for the first empty pad byte of ImageBuffer + + IMAGE_PACKAGE_HDR = pack('=II', ImageInfoOffset, PaletteInfoOffset) + # PACKAGE_HEADER_Length = PACKAGE_HEADER + ImageInfoOffset + PaletteInfoOffset + ImageBuffer Length + PaletteCount + PaletteBuffer Length + if len(PaletteBuffer) > 1: + PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1 + 2 + len(PaletteBuffer) - 1 + else: + PACKAGE_HEADER_Length = 4 + 4 + 4 + len(ImageBuffer) - 1 + if PaletteIndex > 1: + PALETTE_INFO_HEADER = pack('H', PaletteIndex - 1) + # EFI_HII_PACKAGE_HEADER length max value is 0xFFFFFF + Hex_Length = '%06X' % PACKAGE_HEADER_Length + if PACKAGE_HEADER_Length > 0xFFFFFF: + EdkLogger.error("build", AUTOGEN_ERROR, "The Length of EFI_HII_PACKAGE_HEADER exceed its maximum value", ExtraData="[%s]" % str(Info)) + PACKAGE_HEADER = pack('=HBB', int('0x' + Hex_Length[2:], 16), int('0x' + Hex_Length[0:2], 16), EFI_HII_PACKAGE_IMAGES) + + IdfGenBinBuffer.write(PACKAGE_HEADER) + IdfGenBinBuffer.write(IMAGE_PACKAGE_HDR) + if len(ImageBuffer) > 1 : + IdfGenBinBuffer.write(ImageBuffer[1:]) + if PaletteIndex > 1: + IdfGenBinBuffer.write(PALETTE_INFO_HEADER) + if len(PaletteBuffer) > 1: + IdfGenBinBuffer.write(PaletteBuffer[1:]) + + if IdfGenCFlag: + TotalLength = EFI_HII_ARRAY_SIZE_LENGTH + PACKAGE_HEADER_Length + AutoGenC.Append("\n//\n//Image Pack Definition\n//\n") + AllStr = WriteLine('', CHAR_ARRAY_DEFIN + ' ' + Info.Module.BaseName + 'Images' + '[] = {\n') + AllStr = WriteLine(AllStr, '// STRGATHER_OUTPUT_HEADER') + AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(TotalLength)) + '\n') + AllStr = WriteLine(AllStr, '// Image PACKAGE HEADER\n') + IMAGE_PACKAGE_HDR_List = AscToHexList(PACKAGE_HEADER) + IMAGE_PACKAGE_HDR_List += AscToHexList(IMAGE_PACKAGE_HDR) + AllStr = WriteLine(AllStr, CreateArrayItem(IMAGE_PACKAGE_HDR_List, 16) + '\n') + AllStr = WriteLine(AllStr, '// Image DATA\n') + if BufferStr: + AllStr = WriteLine(AllStr, BufferStr) + if PaletteStr: + AllStr = WriteLine(AllStr, '// Palette Header\n') + PALETTE_INFO_HEADER_List = AscToHexList(PALETTE_INFO_HEADER) + AllStr = WriteLine(AllStr, CreateArrayItem(PALETTE_INFO_HEADER_List, 16) + '\n') + AllStr = WriteLine(AllStr, '// Palette Data\n') + AllStr = WriteLine(AllStr, PaletteStr) + AllStr = WriteLine(AllStr, '};') + AutoGenC.Append(AllStr) + AutoGenC.Append("\n") + StringH.Append('\nextern unsigned char ' + Info.Module.BaseName + 'Images[];\n') + StringH.Append("\n#define IMAGE_ARRAY_NAME %sImages\n" % Info.Module.BaseName) + +# typedef struct _EFI_HII_IMAGE_PACKAGE_HDR { +# EFI_HII_PACKAGE_HEADER Header; # Standard package header, where Header.Type = EFI_HII_PACKAGE_IMAGES +# UINT32 ImageInfoOffset; +# UINT32 PaletteInfoOffset; +# } EFI_HII_IMAGE_PACKAGE_HDR; + +# typedef struct { +# UINT32 Length:24; +# UINT32 Type:8; +# UINT8 Data[]; +# } EFI_HII_PACKAGE_HEADER; + +# typedef struct _EFI_HII_IMAGE_BLOCK { +# UINT8 BlockType; +# UINT8 BlockBody[]; +# } EFI_HII_IMAGE_BLOCK; + +def BmpImageDecoder(File, Buffer, PaletteIndex, TransParent): + ImageType, = struct.unpack('2s', Buffer[0:2]) + if ImageType!= 'BM': # BMP file type is 'BM' + EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard BMP file." % File.Path) + BMP_IMAGE_HEADER = collections.namedtuple('BMP_IMAGE_HEADER', ['bfSize','bfReserved1','bfReserved2','bfOffBits','biSize','biWidth','biHeight','biPlanes','biBitCount', 'biCompression', 'biSizeImage','biXPelsPerMeter','biYPelsPerMeter','biClrUsed','biClrImportant']) + BMP_IMAGE_HEADER_STRUCT = struct.Struct('IHHIIIIHHIIIIII') + BmpHeader = BMP_IMAGE_HEADER._make(BMP_IMAGE_HEADER_STRUCT.unpack_from(Buffer[2:])) + # + # Doesn't support compress. + # + if BmpHeader.biCompression != 0: + EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The compress BMP file %s is not support." % File.Path) + + # The Width and Height is UINT16 type in Image Package + if BmpHeader.biWidth > 0xFFFF: + EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Width is exceed 0xFFFF." % File.Path) + if BmpHeader.biHeight > 0xFFFF: + EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "The BMP file %s Height is exceed 0xFFFF." % File.Path) + + PaletteBuffer = pack('x') + if BmpHeader.biBitCount == 1: + if TransParent: + ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS) + else: + ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_1BIT) + ImageBuffer += pack('B', PaletteIndex) + Width = (BmpHeader.biWidth + 7)/8 + if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2: + PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits] + elif BmpHeader.biBitCount == 4: + if TransParent: + ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS) + else: + ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_4BIT) + ImageBuffer += pack('B', PaletteIndex) + Width = (BmpHeader.biWidth + 1)/2 + if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2: + PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits] + elif BmpHeader.biBitCount == 8: + if TransParent: + ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT_TRANS) + else: + ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_8BIT) + ImageBuffer += pack('B', PaletteIndex) + Width = BmpHeader.biWidth + if BmpHeader.bfOffBits > BMP_IMAGE_HEADER_STRUCT.size + 2: + PaletteBuffer = Buffer[BMP_IMAGE_HEADER_STRUCT.size + 2 : BmpHeader.bfOffBits] + elif BmpHeader.biBitCount == 24: + if TransParent: + ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT_TRANS) + else: + ImageBuffer = pack('B', EFI_HII_IIBT_IMAGE_24BIT) + Width = BmpHeader.biWidth * 3 + else: + EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "Only support the 1 bit, 4 bit, 8bit, 24 bit BMP files.", ExtraData="[%s]" % str(File.Path)) + + ImageBuffer += pack('H', BmpHeader.biWidth) + ImageBuffer += pack('H', BmpHeader.biHeight) + Start = BmpHeader.bfOffBits + End = BmpHeader.bfSize - 1 + for Height in range(0, BmpHeader.biHeight): + if Width % 4 != 0: + Start = End + (Width % 4) - 4 - Width + else: + Start = End - Width + ImageBuffer += Buffer[Start + 1 : Start + Width + 1] + End = Start + + # handle the Palette info, BMP use 4 bytes for R, G, B and Reserved info while EFI_HII_RGB_PIXEL only have the R, G, B info + if PaletteBuffer and len(PaletteBuffer) > 1: + PaletteTemp = pack('x') + for Index in range(0, len(PaletteBuffer)): + if Index % 4 == 3: + continue + PaletteTemp += PaletteBuffer[Index] + PaletteBuffer = PaletteTemp[1:] + return ImageBuffer, PaletteBuffer + ## Create common code # # @param Info The ModuleAutoGen object @@ -1684,10 +1912,14 @@ def CreateFooterCode(Info, AutoGenC, AutoGenH): # @param Info The ModuleAutoGen object # @param AutoGenC The TemplateString object for C code # @param AutoGenH The TemplateString object for header file +# @param StringH The TemplateString object for header file # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True # @param UniGenBinBuffer Buffer to store uni string package data +# @param StringIdf The TemplateString object for header file +# @param IdfGenCFlag IdfString is generated into AutoGen C file when it is set to True +# @param IdfGenBinBuffer Buffer to store Idf string package data # -def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer): +def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer, StringIdf, IdfGenCFlag, IdfGenBinBuffer): CreateHeaderCode(Info, AutoGenC, AutoGenH) if Info.AutoGenVersion >= 0x00010005: @@ -1719,6 +1951,15 @@ def CreateCode(Info, AutoGenC, AutoGenH, StringH, UniGenCFlag, UniGenBinBuffer): StringH.Append("\n#endif\n") AutoGenH.Append('#include "%s"\n' % FileName) + if Info.IdfFileList: + FileName = "%sImgDefs.h" % Info.Name + StringIdf.Append(gAutoGenHeaderString.Replace({'FileName':FileName})) + StringIdf.Append(gAutoGenHPrologueString.Replace({'File':'IMAGEDEFS', 'Guid':Info.Guid.replace('-','_')})) + CreateIdfFileCode(Info, AutoGenC, StringIdf, IdfGenCFlag, IdfGenBinBuffer) + + StringIdf.Append("\n#endif\n") + AutoGenH.Append('#include "%s"\n' % FileName) + CreateFooterCode(Info, AutoGenC, AutoGenH) # no generation of AutoGen.c for Edk modules without unicode file diff --git a/BaseTools/Source/Python/AutoGen/IdfClassObject.py b/BaseTools/Source/Python/AutoGen/IdfClassObject.py new file mode 100644 index 0000000..76bc6d1 --- /dev/null +++ b/BaseTools/Source/Python/AutoGen/IdfClassObject.py @@ -0,0 +1,159 @@ +## @file +# This file is used to collect all defined strings in Image Definition files +# +# Copyright (c) 2016, Intel Corporation. All rights reserved.
+# 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 +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +## +# Import Modules +# +import Common.EdkLogger as EdkLogger +import StringIO +from Common.BuildToolError import * +from Common.String import GetLineNo +from Common.Misc import PathClass +from Common.LongFilePathSupport import LongFilePath +import re +import os + +IMAGE_TOKEN = re.compile('IMAGE_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE) + +# +# Value of different image information block types +# +EFI_HII_IIBT_END = 0x00 +EFI_HII_IIBT_IMAGE_1BIT = 0x10 +EFI_HII_IIBT_IMAGE_1BIT_TRANS = 0x11 +EFI_HII_IIBT_IMAGE_4BIT = 0x12 +EFI_HII_IIBT_IMAGE_4BIT_TRANS = 0x13 +EFI_HII_IIBT_IMAGE_8BIT = 0x14 +EFI_HII_IIBT_IMAGE_8BIT_TRANS = 0x15 +EFI_HII_IIBT_IMAGE_24BIT = 0x16 +EFI_HII_IIBT_IMAGE_24BIT_TRANS = 0x17 +EFI_HII_IIBT_IMAGE_JPEG = 0x18 +EFI_HII_IIBT_IMAGE_PNG = 0x19 +EFI_HII_IIBT_DUPLICATE = 0x20 +EFI_HII_IIBT_SKIP2 = 0x21 +EFI_HII_IIBT_SKIP1 = 0x22 +EFI_HII_IIBT_EXT1 = 0x30 +EFI_HII_IIBT_EXT2 = 0x31 +EFI_HII_IIBT_EXT4 = 0x32 + +# +# Value of HII package type +# +EFI_HII_PACKAGE_TYPE_ALL = 0x00 +EFI_HII_PACKAGE_TYPE_GUID = 0x01 +EFI_HII_PACKAGE_FORMS = 0x02 +EFI_HII_PACKAGE_STRINGS = 0x04 +EFI_HII_PACKAGE_FONTS = 0x05 +EFI_HII_PACKAGE_IMAGES = 0x06 +EFI_HII_PACKAGE_SIMPLE_FONTS = 0x07 +EFI_HII_PACKAGE_DEVICE_PATH = 0x08 +EFI_HII_PACKAGE_KEYBOARD_LAYOUT = 0x09 +EFI_HII_PACKAGE_ANIMATIONS = 0x0A +EFI_HII_PACKAGE_END = 0xDF +EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN = 0xE0 +EFI_HII_PACKAGE_TYPE_SYSTEM_END = 0xFF + +class IdfFileClassObject(object): + def __init__(self, FileList = []): + self.FileList = FileList + self.ImageFilesDict = {} + self.ImageIDList = [] + if len(self.FileList) > 0: + self.LoadIdfFiles(FileList) + + def LoadIdfFiles(self, FileList): + if len(FileList) > 0: + for File in FileList: + self.LoadIdfFile(File) + + def LoadIdfFile(self, File = None): + if File == None: + EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'No Image definition file is given.') + self.File = File + + try: + IdfFile = open(LongFilePath(File.Path), mode='r') + FileIn = IdfFile.read() + IdfFile.close() + except: + EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File) + + ImageFileList = [] + for Line in FileIn.splitlines(): + Line = Line.strip() + Line = self.StripComments(Line) + if len(Line) == 0: + continue + + if Line.find('#image ') >= 0: + LineDetails = Line.split() + LineNo = GetLineNo(FileIn, Line, False) + Len = len(LineDetails) + if Len != 3 and Len != 4: + EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'The format is not match #image IMAGE_ID [TRANSPARENT] ImageFileName in Line %s of File %s.' % (LineNo, File.Path)) + if Len == 4 and LineDetails[2] != 'TRANSPARENT': + EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'Please use the keyword "TRANSPARENT" to describe the transparency setting in Line %s of File %s.' % (LineNo, File.Path)) + MatchString = re.match('^[a-zA-Z][a-zA-Z0-9_]*$', LineDetails[1], re.UNICODE) + if MatchString == None or MatchString.end(0) != len(LineDetails[1]): + EdkLogger.error('Image Definition File Parser', FORMAT_INVALID, 'The Image token name %s defined in Idf file %s contains the invalid character.' % (LineDetails[1], File.Path)) + if LineDetails[1] not in self.ImageIDList: + self.ImageIDList.append(LineDetails[1]) + else: + EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'The %s in Line %s of File %s is already defined.' % (LineDetails[1], LineNo, File.Path)) + if Len == 4: + ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], True) + else: + ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], False) + ImageFileList.append(ImageFile) + if ImageFileList: + self.ImageFilesDict[File] = ImageFileList + + def StripComments(self, Line): + Comment = '//' + CommentPos = Line.find(Comment) + while CommentPos >= 0: + # if there are non matched quotes before the comment header + # then we are in the middle of a string + # but we need to ignore the escaped quotes and backslashes. + if ((Line.count('"', 0, CommentPos) - Line.count('\\"', 0, CommentPos)) & 1) == 1: + CommentPos = Line.find (Comment, CommentPos + 1) + else: + return Line[:CommentPos].strip() + return Line.strip() + + def ImageDecoder(self, File): + pass + +def SearchImageID(ImageFileObject, FileList): + if FileList == []: + return ImageFileObject + + for File in FileList: + if os.path.isfile(File): + Lines = open(File, 'r') + for Line in Lines: + ImageIdList = IMAGE_TOKEN.findall(Line) + for ID in ImageIdList: + EdkLogger.debug(EdkLogger.DEBUG_5, "Found ImageID identifier: " + ID) + ImageFileObject.SetImageIDReferenced(ID) + +class ImageFileObject(object): + def __init__(self, FileName, ImageID, TransParent = False): + self.FileName = FileName + self.File = '' + self.ImageID = ImageID + self.TransParent = TransParent + self.Referenced = False + + def SetImageIDReferenced(self, ImageID): + if ImageID == self.ImageID: + self.Referenced = True diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Source/Python/AutoGen/StrGather.py index 6084004..ed33554 100644 --- a/BaseTools/Source/Python/AutoGen/StrGather.py +++ b/BaseTools/Source/Python/AutoGen/StrGather.py @@ -19,7 +19,7 @@ import Common.EdkLogger as EdkLogger from Common.BuildToolError import * from UniClassObject import * from StringIO import StringIO -from struct import pack +from struct import pack, unpack from Common.LongFilePathSupport import OpenLongFilePath as open ## @@ -131,7 +131,7 @@ def DecToHexList(Dec, Digit = 8): def AscToHexList(Ascii): List = [] for Item in Ascii: - List.append('0x%2X' % ord(Item)) + List.append('0x%02X' % ord(Item)) return List diff --git a/BaseTools/Source/Python/Common/DataType.py b/BaseTools/Source/Python/Common/DataType.py index 1fe1ee4..60cbfbe 100644 --- a/BaseTools/Source/Python/Common/DataType.py +++ b/BaseTools/Source/Python/Common/DataType.py @@ -469,6 +469,7 @@ TAB_FRAMEWORK_IMAGE = "EFI-IMAGE-FILE" TAB_C_CODE_FILE = "C-CODE-FILE" TAB_C_HEADER_FILE = "C-HEADER-FILE" TAB_UNICODE_FILE = "UNICODE-TEXT-FILE" +TAB_IMAGE_FILE = "IMAGE-DEFINITION-FILE" TAB_DEPENDENCY_EXPRESSION_FILE = "DEPENDENCY-EXPRESSION-FILE" TAB_UNKNOWN_FILE = "UNKNOWN-TYPE-FILE" TAB_DEFAULT_BINARY_FILE = "_BINARY_FILE_" -- 2.8.0.windows.1