]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/GenFds/GuidSection.py
BaseTools: Update SkuId checker to make sure it be valid UINT64 value
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GuidSection.py
... / ...
CommitLineData
1## @file\r
2# process GUIDed section generation\r
3#\r
4# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
5#\r
6# This program and the accompanying materials\r
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
18import Section\r
19import subprocess\r
20from Ffs import Ffs\r
21import Common.LongFilePathOs as os\r
22from GenFdsGlobalVariable import GenFdsGlobalVariable\r
23from CommonDataClass.FdfClass import GuidSectionClassObject\r
24from Common import ToolDefClassObject\r
25import sys\r
26from Common import EdkLogger\r
27from Common.BuildToolError import *\r
28from FvImageSection import FvImageSection\r
29from Common.LongFilePathSupport import OpenLongFilePath as open\r
30from GenFds import FindExtendTool\r
31\r
32## generate GUIDed section\r
33#\r
34#\r
35class GuidSection(GuidSectionClassObject) :\r
36\r
37 ## The constructor\r
38 #\r
39 # @param self The object pointer\r
40 #\r
41 def __init__(self):\r
42 GuidSectionClassObject.__init__(self)\r
43\r
44 ## GenSection() method\r
45 #\r
46 # Generate GUIDed 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, section alignment)\r
56 #\r
57 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf=None, Dict={}, IsMakefile=False):\r
58 #\r
59 # Generate all section\r
60 #\r
61 self.KeyStringList = KeyStringList\r
62 self.CurrentArchList = GenFdsGlobalVariable.ArchList\r
63 if FfsInf != None:\r
64 self.Alignment = FfsInf.__ExtendMacro__(self.Alignment)\r
65 self.NameGuid = FfsInf.__ExtendMacro__(self.NameGuid)\r
66 self.SectionType = FfsInf.__ExtendMacro__(self.SectionType)\r
67 self.CurrentArchList = [FfsInf.CurrentArch]\r
68\r
69 SectFile = tuple()\r
70 SectAlign = []\r
71 Index = 0\r
72 MaxAlign = None\r
73 if self.FvAddr != []:\r
74 FvAddrIsSet = True\r
75 else:\r
76 FvAddrIsSet = False\r
77 \r
78 if self.ProcessRequired in ("TRUE", "1"):\r
79 if self.FvAddr != []:\r
80 #no use FvAddr when the image is processed.\r
81 self.FvAddr = []\r
82 if self.FvParentAddr != None:\r
83 #no use Parent Addr when the image is processed.\r
84 self.FvParentAddr = None\r
85\r
86 for Sect in self.SectionList:\r
87 Index = Index + 1\r
88 SecIndex = '%s.%d' % (SecNum, Index)\r
89 # set base address for inside FvImage\r
90 if isinstance(Sect, FvImageSection):\r
91 if self.FvAddr != []:\r
92 Sect.FvAddr = self.FvAddr.pop(0)\r
93 self.IncludeFvSection = True\r
94 elif isinstance(Sect, GuidSection):\r
95 Sect.FvAddr = self.FvAddr\r
96 Sect.FvParentAddr = self.FvParentAddr\r
97 ReturnSectList, align = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList, FfsInf, Dict, IsMakefile=IsMakefile)\r
98 if isinstance(Sect, GuidSection):\r
99 if Sect.IncludeFvSection:\r
100 self.IncludeFvSection = Sect.IncludeFvSection\r
101\r
102 if align != None:\r
103 if MaxAlign == None:\r
104 MaxAlign = align\r
105 if GenFdsGlobalVariable.GetAlignment (align) > GenFdsGlobalVariable.GetAlignment (MaxAlign):\r
106 MaxAlign = align\r
107 if ReturnSectList != []:\r
108 if align == None:\r
109 align = "1"\r
110 for file in ReturnSectList:\r
111 SectFile += (file,)\r
112 SectAlign.append(align)\r
113\r
114 if MaxAlign != None:\r
115 if self.Alignment == None:\r
116 self.Alignment = MaxAlign\r
117 else:\r
118 if GenFdsGlobalVariable.GetAlignment (MaxAlign) > GenFdsGlobalVariable.GetAlignment (self.Alignment):\r
119 self.Alignment = MaxAlign\r
120\r
121 OutputFile = OutputPath + \\r
122 os.sep + \\r
123 ModuleName + \\r
124 'SEC' + \\r
125 SecNum + \\r
126 Ffs.SectionSuffix['GUIDED']\r
127 OutputFile = os.path.normpath(OutputFile)\r
128\r
129 ExternalTool = None\r
130 ExternalOption = None\r
131 if self.NameGuid != None:\r
132 ExternalTool, ExternalOption = FindExtendTool(self.KeyStringList, self.CurrentArchList, self.NameGuid)\r
133\r
134 #\r
135 # If not have GUID , call default\r
136 # GENCRC32 section\r
137 #\r
138 if self.NameGuid == None :\r
139 GenFdsGlobalVariable.VerboseLogger("Use GenSection function Generate CRC32 Section")\r
140 GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.Section.SectionType[self.SectionType], InputAlign=SectAlign, IsMakefile=IsMakefile)\r
141 OutputFileList = []\r
142 OutputFileList.append(OutputFile)\r
143 return OutputFileList, self.Alignment\r
144 #or GUID not in External Tool List\r
145 elif ExternalTool == None:\r
146 EdkLogger.error("GenFds", GENFDS_ERROR, "No tool found with GUID %s" % self.NameGuid)\r
147 else:\r
148 DummyFile = OutputFile + ".dummy"\r
149 #\r
150 # Call GenSection with DUMMY section type.\r
151 #\r
152 GenFdsGlobalVariable.GenerateSection(DummyFile, SectFile, InputAlign=SectAlign, IsMakefile=IsMakefile)\r
153 #\r
154 # Use external tool process the Output\r
155 #\r
156 TempFile = OutputPath + \\r
157 os.sep + \\r
158 ModuleName + \\r
159 'SEC' + \\r
160 SecNum + \\r
161 '.tmp'\r
162 TempFile = os.path.normpath(TempFile)\r
163 #\r
164 # Remove temp file if its time stamp is older than dummy file\r
165 # Just in case the external tool fails at this time but succeeded before\r
166 # Error should be reported if the external tool does not generate a new output based on new input\r
167 #\r
168 if os.path.exists(TempFile) and os.path.exists(DummyFile) and os.path.getmtime(TempFile) < os.path.getmtime(DummyFile):\r
169 os.remove(TempFile)\r
170\r
171 FirstCall = False\r
172 CmdOption = '-e'\r
173 if ExternalOption != None:\r
174 CmdOption = CmdOption + ' ' + ExternalOption\r
175 if not GenFdsGlobalVariable.EnableGenfdsMultiThread:\r
176 if self.ProcessRequired not in ("TRUE", "1") and self.IncludeFvSection and not FvAddrIsSet and self.FvParentAddr != None:\r
177 #FirstCall is only set for the encapsulated flash FV image without process required attribute.\r
178 FirstCall = True\r
179 #\r
180 # Call external tool\r
181 #\r
182 ReturnValue = [1]\r
183 if FirstCall:\r
184 #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.\r
185 GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, '-z' + ' ' + CmdOption, ReturnValue)\r
186\r
187 #\r
188 # when no call or first call failed, ReturnValue are not 1.\r
189 # Call the guided tool with CmdOption\r
190 #\r
191 if ReturnValue[0] != 0:\r
192 FirstCall = False\r
193 ReturnValue[0] = 0\r
194 GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption)\r
195 #\r
196 # There is external tool which does not follow standard rule which return nonzero if tool fails\r
197 # The output file has to be checked\r
198 #\r
199\r
200 if not os.path.exists(TempFile) :\r
201 EdkLogger.error("GenFds", COMMAND_FAILURE, 'Fail to call %s, no output file was generated' % ExternalTool)\r
202\r
203 FileHandleIn = open(DummyFile, 'rb')\r
204 FileHandleIn.seek(0, 2)\r
205 InputFileSize = FileHandleIn.tell()\r
206\r
207 FileHandleOut = open(TempFile, 'rb')\r
208 FileHandleOut.seek(0, 2)\r
209 TempFileSize = FileHandleOut.tell()\r
210\r
211 Attribute = []\r
212 HeaderLength = None\r
213 if self.ExtraHeaderSize != -1:\r
214 HeaderLength = str(self.ExtraHeaderSize)\r
215\r
216 if self.ProcessRequired == "NONE" and HeaderLength == None:\r
217 if TempFileSize > InputFileSize:\r
218 FileHandleIn.seek(0)\r
219 BufferIn = FileHandleIn.read()\r
220 FileHandleOut.seek(0)\r
221 BufferOut = FileHandleOut.read()\r
222 if BufferIn == BufferOut[TempFileSize - InputFileSize:]:\r
223 HeaderLength = str(TempFileSize - InputFileSize)\r
224 #auto sec guided attribute with process required\r
225 if HeaderLength == None:\r
226 Attribute.append('PROCESSING_REQUIRED')\r
227\r
228 FileHandleIn.close()\r
229 FileHandleOut.close()\r
230\r
231 if FirstCall and 'PROCESSING_REQUIRED' in Attribute:\r
232 # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.\r
233 GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption)\r
234\r
235 #\r
236 # Call Gensection Add Section Header\r
237 #\r
238 if self.ProcessRequired in ("TRUE", "1"):\r
239 if 'PROCESSING_REQUIRED' not in Attribute:\r
240 Attribute.append('PROCESSING_REQUIRED')\r
241\r
242 if self.AuthStatusValid in ("TRUE", "1"):\r
243 Attribute.append('AUTH_STATUS_VALID')\r
244 GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],\r
245 Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength)\r
246\r
247 else:\r
248 #add input file for GenSec get PROCESSING_REQUIRED\r
249 GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption, IsMakefile=IsMakefile)\r
250 Attribute = []\r
251 HeaderLength = None\r
252 if self.ExtraHeaderSize != -1:\r
253 HeaderLength = str(self.ExtraHeaderSize)\r
254 if self.AuthStatusValid in ("TRUE", "1"):\r
255 Attribute.append('AUTH_STATUS_VALID')\r
256 if self.ProcessRequired == "NONE" and HeaderLength == None:\r
257 GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],\r
258 Guid=self.NameGuid, GuidAttr=Attribute,\r
259 GuidHdrLen=HeaderLength, DummyFile=DummyFile, IsMakefile=IsMakefile)\r
260 else:\r
261 if self.ProcessRequired in ("TRUE", "1"):\r
262 if 'PROCESSING_REQUIRED' not in Attribute:\r
263 Attribute.append('PROCESSING_REQUIRED')\r
264 GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],\r
265 Guid=self.NameGuid, GuidAttr=Attribute,\r
266 GuidHdrLen=HeaderLength, IsMakefile=IsMakefile)\r
267\r
268 OutputFileList = []\r
269 OutputFileList.append(OutputFile)\r
270 if 'PROCESSING_REQUIRED' in Attribute:\r
271 # reset guided section alignment to none for the processed required guided data\r
272 self.Alignment = None\r
273 self.IncludeFvSection = False\r
274 self.ProcessRequired = "TRUE"\r
275 return OutputFileList, self.Alignment\r
276\r
277\r
278\r