]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Section.py
BaseTools: Clean up source files
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Section.py
1 ## @file
2 # section base class
3 #
4 # Copyright (c) 2007-2018, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 ##
16 # Import Modules
17 #
18 from CommonDataClass.FdfClass import SectionClassObject
19 from GenFdsGlobalVariable import GenFdsGlobalVariable
20 import Common.LongFilePathOs as os, glob
21 from Common import EdkLogger
22 from Common.BuildToolError import *
23 from Common.DataType import *
24
25 ## section base class
26 #
27 #
28 class Section (SectionClassObject):
29 SectionType = {
30 'RAW' : 'EFI_SECTION_RAW',
31 'FREEFORM' : 'EFI_SECTION_FREEFORM_SUBTYPE_GUID',
32 BINARY_FILE_TYPE_PE32 : 'EFI_SECTION_PE32',
33 BINARY_FILE_TYPE_PIC : 'EFI_SECTION_PIC',
34 BINARY_FILE_TYPE_TE : 'EFI_SECTION_TE',
35 'FV_IMAGE' : 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE',
36 BINARY_FILE_TYPE_DXE_DEPEX : 'EFI_SECTION_DXE_DEPEX',
37 BINARY_FILE_TYPE_PEI_DEPEX : 'EFI_SECTION_PEI_DEPEX',
38 'GUIDED' : 'EFI_SECTION_GUID_DEFINED',
39 'COMPRESS' : 'EFI_SECTION_COMPRESSION',
40 BINARY_FILE_TYPE_UI : 'EFI_SECTION_USER_INTERFACE',
41 BINARY_FILE_TYPE_SMM_DEPEX : 'EFI_SECTION_SMM_DEPEX'
42 }
43
44 BinFileType = {
45 BINARY_FILE_TYPE_GUID : '.guid',
46 'ACPI' : '.acpi',
47 'ASL' : '.asl' ,
48 BINARY_FILE_TYPE_UEFI_APP : '.app',
49 BINARY_FILE_TYPE_LIB : '.lib',
50 BINARY_FILE_TYPE_PE32 : '.pe32',
51 BINARY_FILE_TYPE_PIC : '.pic',
52 BINARY_FILE_TYPE_PEI_DEPEX : '.depex',
53 'SEC_PEI_DEPEX' : '.depex',
54 BINARY_FILE_TYPE_TE : '.te',
55 BINARY_FILE_TYPE_UNI_VER : '.ver',
56 BINARY_FILE_TYPE_VER : '.ver',
57 BINARY_FILE_TYPE_UNI_UI : '.ui',
58 BINARY_FILE_TYPE_UI : '.ui',
59 BINARY_FILE_TYPE_BIN : '.bin',
60 'RAW' : '.raw',
61 'COMPAT16' : '.comp16',
62 BINARY_FILE_TYPE_FV : '.fv'
63 }
64
65 SectFileType = {
66 'SEC_GUID' : '.sec' ,
67 'SEC_PE32' : '.sec' ,
68 'SEC_PIC' : '.sec',
69 'SEC_TE' : '.sec',
70 'SEC_VER' : '.sec',
71 'SEC_UI' : '.sec',
72 'SEC_COMPAT16' : '.sec',
73 'SEC_BIN' : '.sec'
74 }
75
76 ToolGuid = {
77 '0xa31280ad-0x481e-0x41b6-0x95e8-0x127f-0x4c984779' : 'TianoCompress',
78 '0xee4e5898-0x3914-0x4259-0x9d6e-0xdc7b-0xd79403cf' : 'LzmaCompress'
79 }
80
81 ## The constructor
82 #
83 # @param self The object pointer
84 #
85 def __init__(self):
86 SectionClassObject.__init__(self)
87
88 ## GenSection() method
89 #
90 # virtual function
91 #
92 # @param self The object pointer
93 # @param OutputPath Where to place output file
94 # @param ModuleName Which module this section belongs to
95 # @param SecNum Index of section
96 # @param KeyStringList Filter for inputs of section generation
97 # @param FfsInf FfsInfStatement object that contains this section data
98 # @param Dict dictionary contains macro and its value
99 #
100 def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = {}):
101 pass
102
103 ## GetFileList() method
104 #
105 # Generate compressed section
106 #
107 # @param self The object pointer
108 # @param FfsInf FfsInfStatement object that contains file list
109 # @param FileType File type to get
110 # @param FileExtension File extension to get
111 # @param Dict dictionary contains macro and its value
112 # @retval tuple (File list, boolean)
113 #
114 def GetFileList(FfsInf, FileType, FileExtension, Dict = {}, IsMakefile=False):
115 IsSect = FileType in Section.SectFileType
116
117 if FileExtension is not None:
118 Suffix = FileExtension
119 elif IsSect :
120 Suffix = Section.SectionType.get(FileType)
121 else:
122 Suffix = Section.BinFileType.get(FileType)
123 if FfsInf is None:
124 EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exist!')
125
126 FileList = []
127 if FileType is not None:
128 for File in FfsInf.BinFileList:
129 if File.Arch == TAB_ARCH_COMMON or FfsInf.CurrentArch == File.Arch:
130 if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A \
131 and FileType == 'DXE_DPEX' and File.Type == BINARY_FILE_TYPE_SMM_DEPEX) \
132 or (FileType == BINARY_FILE_TYPE_TE and File.Type == BINARY_FILE_TYPE_PE32):
133 if '*' in FfsInf.TargetOverrideList or File.Target == '*' or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []:
134 FileList.append(FfsInf.PatchEfiFile(File.Path, File.Type))
135 else:
136 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))
137 else:
138 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))
139 else:
140 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))
141
142 if (not IsMakefile and Suffix is not None and os.path.exists(FfsInf.EfiOutputPath)) or (IsMakefile and Suffix is not None):
143 #
144 # Get Makefile path and time stamp
145 #
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:
154 for F in Filenames:
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)
159 if not FileList:
160 SuffixMap = FfsInf.GetFinalTargetSuffixMap()
161 if Suffix in SuffixMap:
162 FileList.extend(SuffixMap[Suffix])
163
164 #Process the file lists is alphabetical for a same section type
165 if len (FileList) > 1:
166 FileList.sort()
167
168 return FileList, IsSect
169 GetFileList = staticmethod(GetFileList)