]>
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 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
7 | ##\r | |
8 | # Import Modules\r | |
9 | #\r | |
10 | from __future__ import absolute_import\r | |
11 | import Common.EdkLogger as EdkLogger\r | |
12 | from Common.BuildToolError import *\r | |
13 | from Common.StringUtils import GetLineNo\r | |
14 | from Common.Misc import PathClass\r | |
15 | from Common.LongFilePathSupport import LongFilePath\r | |
16 | import re\r | |
17 | import os\r | |
18 | from Common.GlobalData import gIdentifierPattern\r | |
19 | from .UniClassObject import StripComments\r | |
20 | \r | |
21 | IMAGE_TOKEN = re.compile('IMAGE_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)\r | |
22 | \r | |
23 | #\r | |
24 | # Value of different image information block types\r | |
25 | #\r | |
26 | EFI_HII_IIBT_END = 0x00\r | |
27 | EFI_HII_IIBT_IMAGE_1BIT = 0x10\r | |
28 | EFI_HII_IIBT_IMAGE_1BIT_TRANS = 0x11\r | |
29 | EFI_HII_IIBT_IMAGE_4BIT = 0x12\r | |
30 | EFI_HII_IIBT_IMAGE_4BIT_TRANS = 0x13\r | |
31 | EFI_HII_IIBT_IMAGE_8BIT = 0x14\r | |
32 | EFI_HII_IIBT_IMAGE_8BIT_TRANS = 0x15\r | |
33 | EFI_HII_IIBT_IMAGE_24BIT = 0x16\r | |
34 | EFI_HII_IIBT_IMAGE_24BIT_TRANS = 0x17\r | |
35 | EFI_HII_IIBT_IMAGE_JPEG = 0x18\r | |
36 | EFI_HII_IIBT_IMAGE_PNG = 0x19\r | |
37 | EFI_HII_IIBT_DUPLICATE = 0x20\r | |
38 | EFI_HII_IIBT_SKIP2 = 0x21\r | |
39 | EFI_HII_IIBT_SKIP1 = 0x22\r | |
40 | EFI_HII_IIBT_EXT1 = 0x30\r | |
41 | EFI_HII_IIBT_EXT2 = 0x31\r | |
42 | EFI_HII_IIBT_EXT4 = 0x32\r | |
43 | \r | |
44 | #\r | |
45 | # Value of HII package type\r | |
46 | #\r | |
47 | EFI_HII_PACKAGE_TYPE_ALL = 0x00\r | |
48 | EFI_HII_PACKAGE_TYPE_GUID = 0x01\r | |
49 | EFI_HII_PACKAGE_FORMS = 0x02\r | |
50 | EFI_HII_PACKAGE_STRINGS = 0x04\r | |
51 | EFI_HII_PACKAGE_FONTS = 0x05\r | |
52 | EFI_HII_PACKAGE_IMAGES = 0x06\r | |
53 | EFI_HII_PACKAGE_SIMPLE_FONTS = 0x07\r | |
54 | EFI_HII_PACKAGE_DEVICE_PATH = 0x08\r | |
55 | EFI_HII_PACKAGE_KEYBOARD_LAYOUT = 0x09\r | |
56 | EFI_HII_PACKAGE_ANIMATIONS = 0x0A\r | |
57 | EFI_HII_PACKAGE_END = 0xDF\r | |
58 | EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN = 0xE0\r | |
59 | EFI_HII_PACKAGE_TYPE_SYSTEM_END = 0xFF\r | |
60 | \r | |
61 | class IdfFileClassObject(object):\r | |
62 | def __init__(self, FileList = []):\r | |
63 | self.ImageFilesDict = {}\r | |
64 | self.ImageIDList = []\r | |
65 | for File in FileList:\r | |
66 | if File is None:\r | |
67 | EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'No Image definition file is given.')\r | |
68 | \r | |
69 | try:\r | |
70 | IdfFile = open(LongFilePath(File.Path), mode='r')\r | |
71 | FileIn = IdfFile.read()\r | |
72 | IdfFile.close()\r | |
73 | except:\r | |
74 | EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File)\r | |
75 | \r | |
76 | ImageFileList = []\r | |
77 | for Line in FileIn.splitlines():\r | |
78 | Line = Line.strip()\r | |
79 | Line = StripComments(Line)\r | |
80 | if len(Line) == 0:\r | |
81 | continue\r | |
82 | \r | |
83 | LineNo = GetLineNo(FileIn, Line, False)\r | |
84 | if not Line.startswith('#image '):\r | |
85 | EdkLogger.error("Image Definition File Parser", PARSER_ERROR, 'The %s in Line %s of File %s is invalid.' % (Line, LineNo, File.Path))\r | |
86 | \r | |
87 | if Line.find('#image ') >= 0:\r | |
88 | LineDetails = Line.split()\r | |
89 | Len = len(LineDetails)\r | |
90 | if Len != 3 and Len != 4:\r | |
91 | 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 | |
92 | if Len == 4 and LineDetails[2] != 'TRANSPARENT':\r | |
93 | 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 | |
94 | MatchString = gIdentifierPattern.match(LineDetails[1])\r | |
95 | if MatchString is None:\r | |
96 | 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 | |
97 | if LineDetails[1] not in self.ImageIDList:\r | |
98 | self.ImageIDList.append(LineDetails[1])\r | |
99 | else:\r | |
100 | 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 | |
101 | if Len == 4:\r | |
102 | ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], True)\r | |
103 | else:\r | |
104 | ImageFile = ImageFileObject(LineDetails[Len-1], LineDetails[1], False)\r | |
105 | ImageFileList.append(ImageFile)\r | |
106 | if ImageFileList:\r | |
107 | self.ImageFilesDict[File] = ImageFileList\r | |
108 | \r | |
109 | def SearchImageID(ImageFileObject, FileList):\r | |
110 | if FileList == []:\r | |
111 | return ImageFileObject\r | |
112 | \r | |
113 | for File in FileList:\r | |
114 | if os.path.isfile(File):\r | |
115 | Lines = open(File, 'r')\r | |
116 | for Line in Lines:\r | |
117 | ImageIdList = IMAGE_TOKEN.findall(Line)\r | |
118 | for ID in ImageIdList:\r | |
119 | EdkLogger.debug(EdkLogger.DEBUG_5, "Found ImageID identifier: " + ID)\r | |
120 | ImageFileObject.SetImageIDReferenced(ID)\r | |
121 | \r | |
122 | class ImageFileObject(object):\r | |
123 | def __init__(self, FileName, ImageID, TransParent = False):\r | |
124 | self.FileName = FileName\r | |
125 | self.File = ''\r | |
126 | self.ImageID = ImageID\r | |
127 | self.TransParent = TransParent\r | |
128 | self.Referenced = False\r | |
129 | \r | |
130 | def SetImageIDReferenced(self, ImageID):\r | |
131 | if ImageID == self.ImageID:\r | |
132 | self.Referenced = True\r |