]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/AutoGen/IdfClassObject.py
MdeModulePkg/Ehci: don't clear port status bits during init
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / IdfClassObject.py
CommitLineData
333ba578
YZ
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
16import Common.EdkLogger as EdkLogger\r
17import StringIO\r
18from Common.BuildToolError import *\r
19from Common.String import GetLineNo\r
20from Common.Misc import PathClass\r
21from Common.LongFilePathSupport import LongFilePath\r
22import re\r
23import os\r
24\r
25IMAGE_TOKEN = re.compile('IMAGE_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)\r
26\r
27#\r
28# Value of different image information block types\r
29#\r
30EFI_HII_IIBT_END = 0x00\r
31EFI_HII_IIBT_IMAGE_1BIT = 0x10\r
32EFI_HII_IIBT_IMAGE_1BIT_TRANS = 0x11\r
33EFI_HII_IIBT_IMAGE_4BIT = 0x12\r
34EFI_HII_IIBT_IMAGE_4BIT_TRANS = 0x13\r
35EFI_HII_IIBT_IMAGE_8BIT = 0x14\r
36EFI_HII_IIBT_IMAGE_8BIT_TRANS = 0x15\r
37EFI_HII_IIBT_IMAGE_24BIT = 0x16\r
38EFI_HII_IIBT_IMAGE_24BIT_TRANS = 0x17\r
39EFI_HII_IIBT_IMAGE_JPEG = 0x18\r
40EFI_HII_IIBT_IMAGE_PNG = 0x19\r
41EFI_HII_IIBT_DUPLICATE = 0x20\r
42EFI_HII_IIBT_SKIP2 = 0x21\r
43EFI_HII_IIBT_SKIP1 = 0x22\r
44EFI_HII_IIBT_EXT1 = 0x30\r
45EFI_HII_IIBT_EXT2 = 0x31\r
46EFI_HII_IIBT_EXT4 = 0x32\r
47\r
48#\r
49# Value of HII package type\r
50#\r
51EFI_HII_PACKAGE_TYPE_ALL = 0x00\r
52EFI_HII_PACKAGE_TYPE_GUID = 0x01\r
53EFI_HII_PACKAGE_FORMS = 0x02\r
54EFI_HII_PACKAGE_STRINGS = 0x04\r
55EFI_HII_PACKAGE_FONTS = 0x05\r
56EFI_HII_PACKAGE_IMAGES = 0x06\r
57EFI_HII_PACKAGE_SIMPLE_FONTS = 0x07\r
58EFI_HII_PACKAGE_DEVICE_PATH = 0x08\r
59EFI_HII_PACKAGE_KEYBOARD_LAYOUT = 0x09\r
60EFI_HII_PACKAGE_ANIMATIONS = 0x0A\r
61EFI_HII_PACKAGE_END = 0xDF\r
62EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN = 0xE0\r
63EFI_HII_PACKAGE_TYPE_SYSTEM_END = 0xFF\r
64\r
65class IdfFileClassObject(object):\r
66 def __init__(self, FileList = []):\r
67 self.FileList = FileList\r
68 self.ImageFilesDict = {}\r
69 self.ImageIDList = []\r
70 if len(self.FileList) > 0:\r
71 self.LoadIdfFiles(FileList)\r
72\r
73 def LoadIdfFiles(self, FileList):\r
74 if len(FileList) > 0:\r
75 for File in FileList:\r
76 self.LoadIdfFile(File)\r
77\r
78 def LoadIdfFile(self, File = None):\r
79 if File == None:\r
80 EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'No Image definition file is given.')\r
81 self.File = File\r
82\r
83 try:\r
84 IdfFile = open(LongFilePath(File.Path), mode='r')\r
85 FileIn = IdfFile.read()\r
86 IdfFile.close()\r
87 except:\r
88 EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File)\r
89\r
90 ImageFileList = []\r
91 for Line in FileIn.splitlines():\r
92 Line = Line.strip()\r
93 Line = self.StripComments(Line)\r
94 if len(Line) == 0:\r
95 continue\r
96\r
97 if Line.find('#image ') >= 0:\r
98 LineDetails = Line.split()\r
99 LineNo = GetLineNo(FileIn, Line, False)\r
100 Len = len(LineDetails)\r
101 if Len != 3 and Len != 4:\r
102 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
103 if Len == 4 and LineDetails[2] != 'TRANSPARENT':\r
104 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
105 MatchString = re.match('^[a-zA-Z][a-zA-Z0-9_]*$', LineDetails[1], re.UNICODE)\r
106 if MatchString == None or MatchString.end(0) != len(LineDetails[1]):\r
107 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
108 if LineDetails[1] not in self.ImageIDList:\r
109 self.ImageIDList.append(LineDetails[1])\r
110 else:\r
111 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
112 if Len == 4:\r
113 ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], True)\r
114 else:\r
115 ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], False)\r
116 ImageFileList.append(ImageFile)\r
117 if ImageFileList:\r
118 self.ImageFilesDict[File] = ImageFileList\r
119\r
120 def StripComments(self, Line):\r
121 Comment = '//'\r
122 CommentPos = Line.find(Comment)\r
123 while CommentPos >= 0:\r
124 # if there are non matched quotes before the comment header\r
125 # then we are in the middle of a string\r
126 # but we need to ignore the escaped quotes and backslashes.\r
127 if ((Line.count('"', 0, CommentPos) - Line.count('\\"', 0, CommentPos)) & 1) == 1:\r
128 CommentPos = Line.find (Comment, CommentPos + 1)\r
129 else:\r
130 return Line[:CommentPos].strip()\r
131 return Line.strip()\r
132\r
133 def ImageDecoder(self, File):\r
134 pass\r
135\r
136def SearchImageID(ImageFileObject, FileList):\r
137 if FileList == []:\r
138 return ImageFileObject\r
139\r
140 for File in FileList:\r
141 if os.path.isfile(File):\r
142 Lines = open(File, 'r')\r
143 for Line in Lines:\r
144 ImageIdList = IMAGE_TOKEN.findall(Line)\r
145 for ID in ImageIdList:\r
146 EdkLogger.debug(EdkLogger.DEBUG_5, "Found ImageID identifier: " + ID)\r
147 ImageFileObject.SetImageIDReferenced(ID)\r
148\r
149class ImageFileObject(object):\r
150 def __init__(self, FileName, ImageID, TransParent = False):\r
151 self.FileName = FileName\r
152 self.File = ''\r
153 self.ImageID = ImageID\r
154 self.TransParent = TransParent\r
155 self.Referenced = False\r
156\r
157 def SetImageIDReferenced(self, ImageID):\r
158 if ImageID == self.ImageID:\r
159 self.Referenced = True\r