]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # process rule section generation\r | |
3 | #\r | |
a146c532 | 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 | |
52302d4d | 18 | from struct import *\r |
30fdf114 LG |
19 | import Section\r |
20 | from GenFdsGlobalVariable import GenFdsGlobalVariable\r | |
21 | import subprocess\r | |
22 | from Ffs import Ffs\r | |
1be2ed90 | 23 | import Common.LongFilePathOs as os\r |
30fdf114 | 24 | from CommonDataClass.FdfClass import EfiSectionClassObject\r |
30fdf114 LG |
25 | from Common import EdkLogger\r |
26 | from Common.BuildToolError import *\r | |
52302d4d | 27 | from Common.Misc import PeImageClass\r |
1be2ed90 HC |
28 | from Common.LongFilePathSupport import OpenLongFilePath as open\r |
29 | from Common.LongFilePathSupport import CopyLongFilePath\r | |
8bb63e37 | 30 | from Common.DataType import *\r |
30fdf114 LG |
31 | \r |
32 | ## generate rule section\r | |
33 | #\r | |
34 | #\r | |
35 | class EfiSection (EfiSectionClassObject):\r | |
36 | \r | |
37 | ## The constructor\r | |
38 | #\r | |
39 | # @param self The object pointer\r | |
40 | #\r | |
41 | def __init__(self):\r | |
42 | EfiSectionClassObject.__init__(self)\r | |
43 | \r | |
44 | ## GenSection() method\r | |
45 | #\r | |
46 | # Generate rule section\r | |
47 | #\r | |
48 | # @param self The object pointer\r | |
49 | # @param OutputPath Where to place output file\r | |
50 | # @param ModuleName Which module this section belongs to\r | |
51 | # @param SecNum Index of section\r | |
52 | # @param KeyStringList Filter for inputs of section generation\r | |
53 | # @param FfsInf FfsInfStatement object that contains this section data\r | |
54 | # @param Dict dictionary contains macro and its value\r | |
55 | # @retval tuple (Generated file name list, section alignment)\r | |
56 | #\r | |
37de70b7 | 57 | def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False) :\r |
30fdf114 | 58 | \r |
4231a819 | 59 | if self.FileName is not None and self.FileName.startswith('PCD('):\r |
30fdf114 LG |
60 | self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName)\r |
61 | """Prepare the parameter of GenSection"""\r | |
4231a819 | 62 | if FfsInf is not None :\r |
30fdf114 LG |
63 | InfFileName = FfsInf.InfFileName\r |
64 | SectionType = FfsInf.__ExtendMacro__(self.SectionType)\r | |
65 | Filename = FfsInf.__ExtendMacro__(self.FileName)\r | |
66 | BuildNum = FfsInf.__ExtendMacro__(self.BuildNum)\r | |
67 | StringData = FfsInf.__ExtendMacro__(self.StringData)\r | |
a146c532 | 68 | ModuleNameStr = FfsInf.__ExtendMacro__('$(MODULE_NAME)')\r |
30fdf114 | 69 | NoStrip = True\r |
8bb63e37 | 70 | if FfsInf.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM) and SectionType in ('TE', 'PE32'):\r |
4231a819 | 71 | if FfsInf.KeepReloc is not None:\r |
30fdf114 | 72 | NoStrip = FfsInf.KeepReloc\r |
4231a819 | 73 | elif FfsInf.KeepRelocFromRule is not None:\r |
30fdf114 | 74 | NoStrip = FfsInf.KeepRelocFromRule\r |
4231a819 | 75 | elif self.KeepReloc is not None:\r |
30fdf114 | 76 | NoStrip = self.KeepReloc\r |
4231a819 | 77 | elif FfsInf.ShadowFromInfFile is not None:\r |
30fdf114 LG |
78 | NoStrip = FfsInf.ShadowFromInfFile\r |
79 | else:\r | |
80 | EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s apply rule for None!" %ModuleName)\r | |
81 | \r | |
82 | """If the file name was pointed out, add it in FileList"""\r | |
83 | FileList = []\r | |
4231a819 | 84 | if Filename is not None:\r |
30fdf114 | 85 | Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)\r |
f51461c8 LG |
86 | # check if the path is absolute or relative\r |
87 | if os.path.isabs(Filename):\r | |
88 | Filename = os.path.normpath(Filename)\r | |
89 | else:\r | |
90 | Filename = os.path.normpath(os.path.join(FfsInf.EfiOutputPath, Filename))\r | |
52302d4d | 91 | \r |
30fdf114 LG |
92 | if not self.Optional:\r |
93 | FileList.append(Filename)\r | |
94 | elif os.path.exists(Filename):\r | |
95 | FileList.append(Filename)\r | |
a146c532 FY |
96 | elif IsMakefile:\r |
97 | SuffixMap = FfsInf.GetFinalTargetSuffixMap()\r | |
98 | if '.depex' in SuffixMap:\r | |
cf245466 | 99 | FileList.append(Filename)\r |
30fdf114 | 100 | else:\r |
cf245466 | 101 | FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict, IsMakefile=IsMakefile)\r |
30fdf114 LG |
102 | if IsSect :\r |
103 | return FileList, self.Alignment\r | |
104 | \r | |
105 | Index = 0\r | |
547a6507 | 106 | Align = self.Alignment\r |
30fdf114 LG |
107 | \r |
108 | """ If Section type is 'VERSION'"""\r | |
109 | OutputFileList = []\r | |
110 | if SectionType == 'VERSION':\r | |
111 | \r | |
112 | InfOverrideVerString = False\r | |
4231a819 | 113 | if FfsInf.Version is not None:\r |
30fdf114 LG |
114 | #StringData = FfsInf.Version\r |
115 | BuildNum = FfsInf.Version\r | |
116 | InfOverrideVerString = True\r | |
117 | \r | |
118 | if InfOverrideVerString:\r | |
119 | #VerTuple = ('-n', '"' + StringData + '"')\r | |
4231a819 | 120 | if BuildNum is not None and BuildNum != '':\r |
30fdf114 LG |
121 | BuildNumTuple = ('-j', BuildNum)\r |
122 | else:\r | |
123 | BuildNumTuple = tuple()\r | |
124 | \r | |
125 | Num = SecNum\r | |
8bb63e37 | 126 | OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType))\r |
30fdf114 | 127 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r |
37de70b7 YZ |
128 | #Ui=StringData,\r |
129 | Ver=BuildNum,\r | |
130 | IsMakefile=IsMakefile)\r | |
30fdf114 LG |
131 | OutputFileList.append(OutputFile)\r |
132 | \r | |
133 | elif FileList != []:\r | |
134 | for File in FileList:\r | |
135 | Index = Index + 1\r | |
136 | Num = '%s.%d' %(SecNum , Index)\r | |
8bb63e37 | 137 | OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get(SectionType))\r |
30fdf114 LG |
138 | f = open(File, 'r')\r |
139 | VerString = f.read()\r | |
140 | f.close()\r | |
30fdf114 | 141 | BuildNum = VerString\r |
4231a819 | 142 | if BuildNum is not None and BuildNum != '':\r |
30fdf114 LG |
143 | BuildNumTuple = ('-j', BuildNum)\r |
144 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r | |
37de70b7 YZ |
145 | #Ui=VerString,\r |
146 | Ver=BuildNum,\r | |
147 | IsMakefile=IsMakefile)\r | |
30fdf114 LG |
148 | OutputFileList.append(OutputFile)\r |
149 | \r | |
150 | else:\r | |
30fdf114 | 151 | BuildNum = StringData\r |
4231a819 | 152 | if BuildNum is not None and BuildNum != '':\r |
30fdf114 LG |
153 | BuildNumTuple = ('-j', BuildNum)\r |
154 | else:\r | |
155 | BuildNumTuple = tuple()\r | |
156 | BuildNumString = ' ' + ' '.join(BuildNumTuple)\r | |
157 | \r | |
158 | #if VerString == '' and \r | |
159 | if BuildNumString == '':\r | |
160 | if self.Optional == True :\r | |
161 | GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r | |
162 | return [], None\r | |
163 | else:\r | |
164 | EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss Version Section value" %InfFileName)\r | |
165 | Num = SecNum\r | |
8bb63e37 | 166 | OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType))\r |
30fdf114 | 167 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r |
37de70b7 YZ |
168 | #Ui=VerString,\r |
169 | Ver=BuildNum,\r | |
170 | IsMakefile=IsMakefile)\r | |
30fdf114 LG |
171 | OutputFileList.append(OutputFile)\r |
172 | \r | |
173 | #\r | |
174 | # If Section Type is 'UI'\r | |
175 | #\r | |
176 | elif SectionType == 'UI':\r | |
177 | \r | |
178 | InfOverrideUiString = False\r | |
4231a819 | 179 | if FfsInf.Ui is not None:\r |
30fdf114 LG |
180 | StringData = FfsInf.Ui\r |
181 | InfOverrideUiString = True\r | |
182 | \r | |
183 | if InfOverrideUiString:\r | |
184 | Num = SecNum\r | |
a146c532 FY |
185 | if IsMakefile and StringData == ModuleNameStr:\r |
186 | StringData = "$(MODULE_NAME)"\r | |
8bb63e37 | 187 | OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType))\r |
30fdf114 | 188 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r |
37de70b7 | 189 | Ui=StringData, IsMakefile=IsMakefile)\r |
30fdf114 LG |
190 | OutputFileList.append(OutputFile)\r |
191 | \r | |
192 | elif FileList != []:\r | |
193 | for File in FileList:\r | |
194 | Index = Index + 1\r | |
195 | Num = '%s.%d' %(SecNum , Index)\r | |
8bb63e37 | 196 | OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get(SectionType))\r |
30fdf114 LG |
197 | f = open(File, 'r')\r |
198 | UiString = f.read()\r | |
199 | f.close()\r | |
a146c532 FY |
200 | if IsMakefile and UiString == ModuleNameStr:\r |
201 | UiString = "$(MODULE_NAME)"\r | |
30fdf114 | 202 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r |
37de70b7 | 203 | Ui=UiString, IsMakefile=IsMakefile)\r |
30fdf114 LG |
204 | OutputFileList.append(OutputFile)\r |
205 | else:\r | |
4231a819 | 206 | if StringData is not None and len(StringData) > 0:\r |
30fdf114 LG |
207 | UiTuple = ('-n', '"' + StringData + '"')\r |
208 | else:\r | |
209 | UiTuple = tuple()\r | |
210 | \r | |
211 | if self.Optional == True :\r | |
212 | GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r | |
213 | return '', None\r | |
214 | else:\r | |
215 | EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss UI Section value" %InfFileName)\r | |
216 | \r | |
217 | Num = SecNum\r | |
a146c532 FY |
218 | if IsMakefile and StringData == ModuleNameStr:\r |
219 | StringData = "$(MODULE_NAME)"\r | |
8bb63e37 | 220 | OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + str(Num) + Ffs.SectionSuffix.get(SectionType))\r |
30fdf114 | 221 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r |
37de70b7 | 222 | Ui=StringData, IsMakefile=IsMakefile)\r |
30fdf114 LG |
223 | OutputFileList.append(OutputFile)\r |
224 | \r | |
225 | \r | |
226 | else:\r | |
227 | """If File List is empty"""\r | |
228 | if FileList == [] :\r | |
229 | if self.Optional == True:\r | |
97fa0ee9 YL |
230 | GenFdsGlobalVariable.VerboseLogger("Optional Section don't exist!")\r |
231 | return [], None\r | |
30fdf114 | 232 | else:\r |
97fa0ee9 | 233 | EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName))\r |
30fdf114 LG |
234 | \r |
235 | else:\r | |
236 | """Convert the File to Section file one by one """\r | |
237 | for File in FileList:\r | |
238 | """ Copy Map file to FFS output path """\r | |
239 | Index = Index + 1\r | |
240 | Num = '%s.%d' %(SecNum , Index)\r | |
8bb63e37 | 241 | OutputFile = os.path.join( OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get(SectionType))\r |
30fdf114 | 242 | File = GenFdsGlobalVariable.MacroExtend(File, Dict)\r |
52302d4d LG |
243 | \r |
244 | #Get PE Section alignment when align is set to AUTO\r | |
245 | if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):\r | |
246 | ImageObj = PeImageClass (File)\r | |
247 | if ImageObj.SectionAlignment < 0x400:\r | |
547a6507 | 248 | Align = str (ImageObj.SectionAlignment)\r |
e921f58d | 249 | elif ImageObj.SectionAlignment < 0x100000:\r |
547a6507 | 250 | Align = str (ImageObj.SectionAlignment / 0x400) + 'K'\r |
e921f58d YZ |
251 | else:\r |
252 | Align = str (ImageObj.SectionAlignment / 0x100000) + 'M'\r | |
52302d4d | 253 | \r |
30fdf114 LG |
254 | if File[(len(File)-4):] == '.efi':\r |
255 | MapFile = File.replace('.efi', '.map')\r | |
37de70b7 YZ |
256 | CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r |
257 | if IsMakefile:\r | |
258 | if GenFdsGlobalVariable.CopyList == []:\r | |
259 | GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)]\r | |
260 | else:\r | |
261 | GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile))\r | |
262 | else:\r | |
263 | if os.path.exists(MapFile):\r | |
264 | if not os.path.exists(CopyMapFile) or \\r | |
265 | (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r | |
266 | CopyLongFilePath(MapFile, CopyMapFile)\r | |
30fdf114 LG |
267 | \r |
268 | if not NoStrip:\r | |
269 | FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r | |
37de70b7 YZ |
270 | if IsMakefile:\r |
271 | if GenFdsGlobalVariable.CopyList == []:\r | |
272 | GenFdsGlobalVariable.CopyList = [(File, FileBeforeStrip)]\r | |
273 | else:\r | |
274 | GenFdsGlobalVariable.CopyList.append((File, FileBeforeStrip))\r | |
275 | else:\r | |
276 | if not os.path.exists(FileBeforeStrip) or \\r | |
277 | (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r | |
278 | CopyLongFilePath(File, FileBeforeStrip)\r | |
30fdf114 LG |
279 | StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r |
280 | GenFdsGlobalVariable.GenerateFirmwareImage(\r | |
37de70b7 YZ |
281 | StrippedFile,\r |
282 | [File],\r | |
283 | Strip=True,\r | |
284 | IsMakefile = IsMakefile\r | |
285 | )\r | |
30fdf114 | 286 | File = StrippedFile\r |
52302d4d | 287 | \r |
30fdf114 LG |
288 | """For TE Section call GenFw to generate TE image"""\r |
289 | \r | |
290 | if SectionType == 'TE':\r | |
291 | TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r | |
292 | GenFdsGlobalVariable.GenerateFirmwareImage(\r | |
37de70b7 YZ |
293 | TeFile,\r |
294 | [File],\r | |
295 | Type='te',\r | |
296 | IsMakefile = IsMakefile\r | |
297 | )\r | |
30fdf114 LG |
298 | File = TeFile\r |
299 | \r | |
300 | """Call GenSection"""\r | |
301 | GenFdsGlobalVariable.GenerateSection(OutputFile,\r | |
37de70b7 YZ |
302 | [File],\r |
303 | Section.Section.SectionType.get (SectionType),\r | |
304 | IsMakefile=IsMakefile\r | |
305 | )\r | |
30fdf114 LG |
306 | OutputFileList.append(OutputFile)\r |
307 | \r | |
547a6507 | 308 | return OutputFileList, Align\r |