]>
Commit | Line | Data |
---|---|---|
1 | ## @file\r | |
2 | # This file is used to collect all defined strings in Image Definition files\r | |
3 | #\r | |
4 | # Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r | |
5 | # This program and the accompanying materials\r | |
6 | # are licensed and made available under the terms and conditions of the BSD License\r | |
7 | # which accompanies this distribution. The full text of the license may be found at\r | |
8 | # http://opensource.org/licenses/bsd-license.php\r | |
9 | #\r | |
10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | ##\r | |
14 | # Import Modules\r | |
15 | #\r | |
16 | import Common.EdkLogger as EdkLogger\r | |
17 | import StringIO\r | |
18 | from Common.BuildToolError import *\r | |
19 | from Common.String import GetLineNo\r | |
20 | from Common.Misc import PathClass\r | |
21 | from Common.LongFilePathSupport import LongFilePath\r | |
22 | import re\r | |
23 | import os\r | |
24 | from Common.GlobalData import gIdentifierPattern\r | |
25 | from UniClassObject import StripComments\r | |
26 | \r | |
27 | IMAGE_TOKEN = re.compile('IMAGE_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)\r | |
28 | \r | |
29 | #\r | |
30 | # Value of different image information block types\r | |
31 | #\r | |
32 | EFI_HII_IIBT_END = 0x00\r | |
33 | EFI_HII_IIBT_IMAGE_1BIT = 0x10\r | |
34 | EFI_HII_IIBT_IMAGE_1BIT_TRANS = 0x11\r | |
35 | EFI_HII_IIBT_IMAGE_4BIT = 0x12\r | |
36 | EFI_HII_IIBT_IMAGE_4BIT_TRANS = 0x13\r | |
37 | EFI_HII_IIBT_IMAGE_8BIT = 0x14\r | |
38 | EFI_HII_IIBT_IMAGE_8BIT_TRANS = 0x15\r | |
39 | EFI_HII_IIBT_IMAGE_24BIT = 0x16\r | |
40 | EFI_HII_IIBT_IMAGE_24BIT_TRANS = 0x17\r | |
41 | EFI_HII_IIBT_IMAGE_JPEG = 0x18\r | |
42 | EFI_HII_IIBT_IMAGE_PNG = 0x19\r | |
43 | EFI_HII_IIBT_DUPLICATE = 0x20\r | |
44 | EFI_HII_IIBT_SKIP2 = 0x21\r | |
45 | EFI_HII_IIBT_SKIP1 = 0x22\r | |
46 | EFI_HII_IIBT_EXT1 = 0x30\r | |
47 | EFI_HII_IIBT_EXT2 = 0x31\r | |
48 | EFI_HII_IIBT_EXT4 = 0x32\r | |
49 | \r | |
50 | #\r | |
51 | # Value of HII package type\r | |
52 | #\r | |
53 | EFI_HII_PACKAGE_TYPE_ALL = 0x00\r | |
54 | EFI_HII_PACKAGE_TYPE_GUID = 0x01\r | |
55 | EFI_HII_PACKAGE_FORMS = 0x02\r | |
56 | EFI_HII_PACKAGE_STRINGS = 0x04\r | |
57 | EFI_HII_PACKAGE_FONTS = 0x05\r | |
58 | EFI_HII_PACKAGE_IMAGES = 0x06\r | |
59 | EFI_HII_PACKAGE_SIMPLE_FONTS = 0x07\r | |
60 | EFI_HII_PACKAGE_DEVICE_PATH = 0x08\r | |
61 | EFI_HII_PACKAGE_KEYBOARD_LAYOUT = 0x09\r | |
62 | EFI_HII_PACKAGE_ANIMATIONS = 0x0A\r | |
63 | EFI_HII_PACKAGE_END = 0xDF\r | |
64 | EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN = 0xE0\r | |
65 | EFI_HII_PACKAGE_TYPE_SYSTEM_END = 0xFF\r | |
66 | \r | |
67 | class IdfFileClassObject(object):\r | |
68 | def __init__(self, FileList = []):\r | |
69 | self.FileList = FileList\r | |
70 | self.ImageFilesDict = {}\r | |
71 | self.ImageIDList = []\r | |
72 | if len(self.FileList) > 0:\r | |
73 | self.LoadIdfFiles(FileList)\r | |
74 | \r | |
75 | def LoadIdfFiles(self, FileList):\r | |
76 | if len(FileList) > 0:\r | |
77 | for File in FileList:\r | |
78 | self.LoadIdfFile(File)\r | |
79 | \r | |
80 | def LoadIdfFile(self, File = None):\r | |
81 | if File is None:\r | |
82 | EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'No Image definition file is given.')\r | |
83 | self.File = File\r | |
84 | \r | |
85 | try:\r | |
86 | IdfFile = open(LongFilePath(File.Path), mode='r')\r | |
87 | FileIn = IdfFile.read()\r | |
88 | IdfFile.close()\r | |
89 | except:\r | |
90 | EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File)\r | |
91 | \r | |
92 | ImageFileList = []\r | |
93 | for Line in FileIn.splitlines():\r | |
94 | Line = Line.strip()\r | |
95 | Line = StripComments(Line)\r | |
96 | if len(Line) == 0:\r | |
97 | continue\r | |
98 | \r | |
99 | LineNo = GetLineNo(FileIn, Line, False)\r | |
100 | if not Line.startswith('#image '):\r | |
101 | EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'The %s in Line %s of File %s is invalid.' % (Line, LineNo, File.Path))\r | |
102 | \r | |
103 | if Line.find('#image ') >= 0:\r | |
104 | LineDetails = Line.split()\r | |
105 | Len = len(LineDetails)\r | |
106 | if Len != 3 and Len != 4:\r | |
107 | 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))\r | |
108 | if Len == 4 and LineDetails[2] != 'TRANSPARENT':\r | |
109 | 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))\r | |
110 | MatchString = gIdentifierPattern.match(LineDetails[1])\r | |
111 | if MatchString is None:\r | |
112 | 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))\r | |
113 | if LineDetails[1] not in self.ImageIDList:\r | |
114 | self.ImageIDList.append(LineDetails[1])\r | |
115 | else:\r | |
116 | EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'The %s in Line %s of File %s is already defined.' % (LineDetails[1], LineNo, File.Path))\r | |
117 | if Len == 4:\r | |
118 | ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], True)\r | |
119 | else:\r | |
120 | ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], False)\r | |
121 | ImageFileList.append(ImageFile)\r | |
122 | if ImageFileList:\r | |
123 | self.ImageFilesDict[File] = ImageFileList\r | |
124 | \r | |
125 | def SearchImageID(ImageFileObject, FileList):\r | |
126 | if FileList == []:\r | |
127 | return ImageFileObject\r | |
128 | \r | |
129 | for File in FileList:\r | |
130 | if os.path.isfile(File):\r | |
131 | Lines = open(File, 'r')\r | |
132 | for Line in Lines:\r | |
133 | ImageIdList = IMAGE_TOKEN.findall(Line)\r | |
134 | for ID in ImageIdList:\r | |
135 | EdkLogger.debug(EdkLogger.DEBUG_5, "Found ImageID identifier: " + ID)\r | |
136 | ImageFileObject.SetImageIDReferenced(ID)\r | |
137 | \r | |
138 | class ImageFileObject(object):\r | |
139 | def __init__(self, FileName, ImageID, TransParent = False):\r | |
140 | self.FileName = FileName\r | |
141 | self.File = ''\r | |
142 | self.ImageID = ImageID\r | |
143 | self.TransParent = TransParent\r | |
144 | self.Referenced = False\r | |
145 | \r | |
146 | def SetImageIDReferenced(self, ImageID):\r | |
147 | if ImageID == self.ImageID:\r | |
148 | self.Referenced = True\r |