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