4 # Copyright (c) 2007-2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
12 from __future__
import absolute_import
13 from CommonDataClass
.FdfClass
import SectionClassObject
14 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
15 import Common
.LongFilePathOs
as os
, glob
16 from Common
import EdkLogger
17 from Common
.BuildToolError
import *
18 from Common
.DataType
import *
23 class Section (SectionClassObject
):
25 'RAW' : 'EFI_SECTION_RAW',
26 'FREEFORM' : 'EFI_SECTION_FREEFORM_SUBTYPE_GUID',
27 BINARY_FILE_TYPE_PE32
: 'EFI_SECTION_PE32',
28 BINARY_FILE_TYPE_PIC
: 'EFI_SECTION_PIC',
29 BINARY_FILE_TYPE_TE
: 'EFI_SECTION_TE',
30 'FV_IMAGE' : 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE',
31 BINARY_FILE_TYPE_DXE_DEPEX
: 'EFI_SECTION_DXE_DEPEX',
32 BINARY_FILE_TYPE_PEI_DEPEX
: 'EFI_SECTION_PEI_DEPEX',
33 'GUIDED' : 'EFI_SECTION_GUID_DEFINED',
34 'COMPRESS' : 'EFI_SECTION_COMPRESSION',
35 BINARY_FILE_TYPE_UI
: 'EFI_SECTION_USER_INTERFACE',
36 BINARY_FILE_TYPE_SMM_DEPEX
: 'EFI_SECTION_SMM_DEPEX'
40 BINARY_FILE_TYPE_GUID
: '.guid',
43 BINARY_FILE_TYPE_UEFI_APP
: '.app',
44 BINARY_FILE_TYPE_LIB
: '.lib',
45 BINARY_FILE_TYPE_PE32
: '.pe32',
46 BINARY_FILE_TYPE_PIC
: '.pic',
47 BINARY_FILE_TYPE_PEI_DEPEX
: '.depex',
48 'SEC_PEI_DEPEX' : '.depex',
49 BINARY_FILE_TYPE_TE
: '.te',
50 BINARY_FILE_TYPE_UNI_VER
: '.ver',
51 BINARY_FILE_TYPE_VER
: '.ver',
52 BINARY_FILE_TYPE_UNI_UI
: '.ui',
53 BINARY_FILE_TYPE_UI
: '.ui',
54 BINARY_FILE_TYPE_BIN
: '.bin',
56 'COMPAT16' : '.comp16',
57 BINARY_FILE_TYPE_FV
: '.fv'
67 'SEC_COMPAT16' : '.sec',
72 '0xa31280ad-0x481e-0x41b6-0x95e8-0x127f-0x4c984779' : 'TianoCompress',
73 '0xee4e5898-0x3914-0x4259-0x9d6e-0xdc7b-0xd79403cf' : 'LzmaCompress'
78 # @param self The object pointer
81 SectionClassObject
.__init
__(self
)
83 ## GenSection() method
87 # @param self The object pointer
88 # @param OutputPath Where to place output file
89 # @param ModuleName Which module this section belongs to
90 # @param SecNum Index of section
91 # @param KeyStringList Filter for inputs of section generation
92 # @param FfsInf FfsInfStatement object that contains this section data
93 # @param Dict dictionary contains macro and its value
95 def GenSection(self
, OutputPath
, GuidName
, SecNum
, keyStringList
, FfsInf
= None, Dict
= None):
98 ## GetFileList() method
100 # Generate compressed section
102 # @param self The object pointer
103 # @param FfsInf FfsInfStatement object that contains file list
104 # @param FileType File type to get
105 # @param FileExtension File extension to get
106 # @param Dict dictionary contains macro and its value
107 # @retval tuple (File list, boolean)
109 def GetFileList(FfsInf
, FileType
, FileExtension
, Dict
= None, IsMakefile
=False, SectionType
=None):
110 IsSect
= FileType
in Section
.SectFileType
112 if FileExtension
is not None:
113 Suffix
= FileExtension
115 Suffix
= Section
.SectionType
.get(FileType
)
117 Suffix
= Section
.BinFileType
.get(FileType
)
119 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'Inf File does not exist!')
122 if FileType
is not None:
123 for File
in FfsInf
.BinFileList
:
124 if File
.Arch
== TAB_ARCH_COMMON
or FfsInf
.CurrentArch
== File
.Arch
:
125 if File
.Type
== FileType
or (int(FfsInf
.PiSpecVersion
, 16) >= 0x0001000A \
126 and FileType
== 'DXE_DPEX' and File
.Type
== BINARY_FILE_TYPE_SMM_DEPEX
) \
127 or (FileType
== BINARY_FILE_TYPE_TE
and File
.Type
== BINARY_FILE_TYPE_PE32
):
128 if TAB_STAR
in FfsInf
.TargetOverrideList
or File
.Target
== TAB_STAR
or File
.Target
in FfsInf
.TargetOverrideList
or FfsInf
.TargetOverrideList
== []:
129 FileList
.append(FfsInf
.PatchEfiFile(File
.Path
, File
.Type
))
131 GenFdsGlobalVariable
.InfLogger ("\nBuild Target \'%s\' of File %s is not in the Scope of %s specified by INF %s in FDF" %(File
.Target
, File
.File
, FfsInf
.TargetOverrideList
, FfsInf
.InfFileName
))
133 GenFdsGlobalVariable
.VerboseLogger ("\nFile Type \'%s\' of File %s in %s is not same with file type \'%s\' from Rule in FDF" %(File
.Type
, File
.File
, FfsInf
.InfFileName
, FileType
))
135 GenFdsGlobalVariable
.InfLogger ("\nCurrent ARCH \'%s\' of File %s is not in the Support Arch Scope of %s specified by INF %s in FDF" %(FfsInf
.CurrentArch
, File
.File
, File
.Arch
, FfsInf
.InfFileName
))
137 elif FileType
is None and SectionType
== BINARY_FILE_TYPE_RAW
:
138 for File
in FfsInf
.BinFileList
:
139 if File
.Ext
== Suffix
:
140 FileList
.append(File
.Path
)
142 if (not IsMakefile
and Suffix
is not None and os
.path
.exists(FfsInf
.EfiOutputPath
)) or (IsMakefile
and Suffix
is not None):
144 # Get Makefile path and time stamp
146 MakefileDir
= FfsInf
.EfiOutputPath
[:-len('OUTPUT')]
147 Makefile
= os
.path
.join(MakefileDir
, 'Makefile')
148 if not os
.path
.exists(Makefile
):
149 Makefile
= os
.path
.join(MakefileDir
, 'GNUmakefile')
150 if os
.path
.exists(Makefile
):
151 # Update to search files with suffix in all sub-dirs.
152 Tuple
= os
.walk(FfsInf
.EfiOutputPath
)
153 for Dirpath
, Dirnames
, Filenames
in Tuple
:
155 if os
.path
.splitext(F
)[1] == Suffix
:
156 FullName
= os
.path
.join(Dirpath
, F
)
157 if os
.path
.getmtime(FullName
) > os
.path
.getmtime(Makefile
):
158 FileList
.append(FullName
)
160 SuffixMap
= FfsInf
.GetFinalTargetSuffixMap()
161 if Suffix
in SuffixMap
:
162 FileList
.extend(SuffixMap
[Suffix
])
164 #Process the file lists is alphabetical for a same section type
165 if len (FileList
) > 1:
168 return FileList
, IsSect
169 GetFileList
= staticmethod(GetFileList
)