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