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