]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Section.py
BaseTools: Use absolute import in GenFds
[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 __future__ import absolute_import
19 from CommonDataClass.FdfClass import SectionClassObject
20 from .GenFdsGlobalVariable import GenFdsGlobalVariable
21 import Common.LongFilePathOs as os, glob
22 from Common import EdkLogger
23 from Common.BuildToolError import *
24 from Common.DataType import *
25
26 ## section base class
27 #
28 #
29 class Section (SectionClassObject):
30 SectionType = {
31 'RAW' : 'EFI_SECTION_RAW',
32 'FREEFORM' : 'EFI_SECTION_FREEFORM_SUBTYPE_GUID',
33 BINARY_FILE_TYPE_PE32 : 'EFI_SECTION_PE32',
34 BINARY_FILE_TYPE_PIC : 'EFI_SECTION_PIC',
35 BINARY_FILE_TYPE_TE : 'EFI_SECTION_TE',
36 'FV_IMAGE' : 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE',
37 BINARY_FILE_TYPE_DXE_DEPEX : 'EFI_SECTION_DXE_DEPEX',
38 BINARY_FILE_TYPE_PEI_DEPEX : 'EFI_SECTION_PEI_DEPEX',
39 'GUIDED' : 'EFI_SECTION_GUID_DEFINED',
40 'COMPRESS' : 'EFI_SECTION_COMPRESSION',
41 BINARY_FILE_TYPE_UI : 'EFI_SECTION_USER_INTERFACE',
42 BINARY_FILE_TYPE_SMM_DEPEX : 'EFI_SECTION_SMM_DEPEX'
43 }
44
45 BinFileType = {
46 BINARY_FILE_TYPE_GUID : '.guid',
47 'ACPI' : '.acpi',
48 'ASL' : '.asl' ,
49 BINARY_FILE_TYPE_UEFI_APP : '.app',
50 BINARY_FILE_TYPE_LIB : '.lib',
51 BINARY_FILE_TYPE_PE32 : '.pe32',
52 BINARY_FILE_TYPE_PIC : '.pic',
53 BINARY_FILE_TYPE_PEI_DEPEX : '.depex',
54 'SEC_PEI_DEPEX' : '.depex',
55 BINARY_FILE_TYPE_TE : '.te',
56 BINARY_FILE_TYPE_UNI_VER : '.ver',
57 BINARY_FILE_TYPE_VER : '.ver',
58 BINARY_FILE_TYPE_UNI_UI : '.ui',
59 BINARY_FILE_TYPE_UI : '.ui',
60 BINARY_FILE_TYPE_BIN : '.bin',
61 'RAW' : '.raw',
62 'COMPAT16' : '.comp16',
63 BINARY_FILE_TYPE_FV : '.fv'
64 }
65
66 SectFileType = {
67 'SEC_GUID' : '.sec' ,
68 'SEC_PE32' : '.sec' ,
69 'SEC_PIC' : '.sec',
70 'SEC_TE' : '.sec',
71 'SEC_VER' : '.sec',
72 'SEC_UI' : '.sec',
73 'SEC_COMPAT16' : '.sec',
74 'SEC_BIN' : '.sec'
75 }
76
77 ToolGuid = {
78 '0xa31280ad-0x481e-0x41b6-0x95e8-0x127f-0x4c984779' : 'TianoCompress',
79 '0xee4e5898-0x3914-0x4259-0x9d6e-0xdc7b-0xd79403cf' : 'LzmaCompress'
80 }
81
82 ## The constructor
83 #
84 # @param self The object pointer
85 #
86 def __init__(self):
87 SectionClassObject.__init__(self)
88
89 ## GenSection() method
90 #
91 # virtual function
92 #
93 # @param self The object pointer
94 # @param OutputPath Where to place output file
95 # @param ModuleName Which module this section belongs to
96 # @param SecNum Index of section
97 # @param KeyStringList Filter for inputs of section generation
98 # @param FfsInf FfsInfStatement object that contains this section data
99 # @param Dict dictionary contains macro and its value
100 #
101 def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = {}):
102 pass
103
104 ## GetFileList() method
105 #
106 # Generate compressed section
107 #
108 # @param self The object pointer
109 # @param FfsInf FfsInfStatement object that contains file list
110 # @param FileType File type to get
111 # @param FileExtension File extension to get
112 # @param Dict dictionary contains macro and its value
113 # @retval tuple (File list, boolean)
114 #
115 def GetFileList(FfsInf, FileType, FileExtension, Dict = {}, IsMakefile=False):
116 IsSect = FileType in Section.SectFileType
117
118 if FileExtension is not None:
119 Suffix = FileExtension
120 elif IsSect :
121 Suffix = Section.SectionType.get(FileType)
122 else:
123 Suffix = Section.BinFileType.get(FileType)
124 if FfsInf is None:
125 EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exist!')
126
127 FileList = []
128 if FileType is not None:
129 for File in FfsInf.BinFileList:
130 if File.Arch == TAB_ARCH_COMMON or FfsInf.CurrentArch == File.Arch:
131 if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A \
132 and FileType == 'DXE_DPEX' and File.Type == BINARY_FILE_TYPE_SMM_DEPEX) \
133 or (FileType == BINARY_FILE_TYPE_TE and File.Type == BINARY_FILE_TYPE_PE32):
134 if '*' in FfsInf.TargetOverrideList or File.Target == '*' or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []:
135 FileList.append(FfsInf.PatchEfiFile(File.Path, File.Type))
136 else:
137 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))
138 else:
139 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))
140 else:
141 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))
142
143 if (not IsMakefile and Suffix is not None and os.path.exists(FfsInf.EfiOutputPath)) or (IsMakefile and Suffix is not None):
144 #
145 # Get Makefile path and time stamp
146 #
147 MakefileDir = FfsInf.EfiOutputPath[:-len('OUTPUT')]
148 Makefile = os.path.join(MakefileDir, 'Makefile')
149 if not os.path.exists(Makefile):
150 Makefile = os.path.join(MakefileDir, 'GNUmakefile')
151 if os.path.exists(Makefile):
152 # Update to search files with suffix in all sub-dirs.
153 Tuple = os.walk(FfsInf.EfiOutputPath)
154 for Dirpath, Dirnames, Filenames in Tuple:
155 for F in Filenames:
156 if os.path.splitext(F)[1] == Suffix:
157 FullName = os.path.join(Dirpath, F)
158 if os.path.getmtime(FullName) > os.path.getmtime(Makefile):
159 FileList.append(FullName)
160 if not FileList:
161 SuffixMap = FfsInf.GetFinalTargetSuffixMap()
162 if Suffix in SuffixMap:
163 FileList.extend(SuffixMap[Suffix])
164
165 #Process the file lists is alphabetical for a same section type
166 if len (FileList) > 1:
167 FileList.sort()
168
169 return FileList, IsSect
170 GetFileList = staticmethod(GetFileList)