]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/GenFds/GuidSection.py
BaseTools: correct to use specific arch to generate DSC database
[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 - 2016, 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={}):\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)\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)\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)\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 self.ProcessRequired not in ("TRUE", "1") and self.IncludeFvSection and not FvAddrIsSet and self.FvParentAddr != None:\r
176 #FirstCall is only set for the encapsulated flash FV image without process required attribute.\r
177 FirstCall = True\r
178 #\r
179 # Call external tool\r
180 #\r
181 ReturnValue = [1]\r
182 if FirstCall:\r
183 #first try to call the guided tool with -z option and CmdOption for the no process required guided tool.\r
184 GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, '-z' + ' ' + CmdOption, ReturnValue)\r
185\r
186 #\r
187 # when no call or first call failed, ReturnValue are not 1.\r
188 # Call the guided tool with CmdOption\r
189 #\r
190 if ReturnValue[0] != 0:\r
191 FirstCall = False\r
192 ReturnValue[0] = 0\r
193 GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption)\r
194 #\r
195 # There is external tool which does not follow standard rule which return nonzero if tool fails\r
196 # The output file has to be checked\r
197 #\r
198 if not os.path.exists(TempFile):\r
199 EdkLogger.error("GenFds", COMMAND_FAILURE, 'Fail to call %s, no output file was generated' % ExternalTool)\r
200\r
201 FileHandleIn = open(DummyFile, 'rb')\r
202 FileHandleIn.seek(0, 2)\r
203 InputFileSize = FileHandleIn.tell()\r
204\r
205 FileHandleOut = open(TempFile, 'rb')\r
206 FileHandleOut.seek(0, 2)\r
207 TempFileSize = FileHandleOut.tell()\r
208\r
209 Attribute = []\r
210 HeaderLength = None\r
211 if self.ExtraHeaderSize != -1:\r
212 HeaderLength = str(self.ExtraHeaderSize)\r
213\r
214 if self.ProcessRequired == "NONE" and HeaderLength == None:\r
215 if TempFileSize > InputFileSize:\r
216 FileHandleIn.seek(0)\r
217 BufferIn = FileHandleIn.read()\r
218 FileHandleOut.seek(0)\r
219 BufferOut = FileHandleOut.read()\r
220 if BufferIn == BufferOut[TempFileSize - InputFileSize:]:\r
221 HeaderLength = str(TempFileSize - InputFileSize)\r
222 #auto sec guided attribute with process required\r
223 if HeaderLength == None:\r
224 Attribute.append('PROCESSING_REQUIRED')\r
225\r
226 FileHandleIn.close()\r
227 FileHandleOut.close()\r
228\r
229 if FirstCall and 'PROCESSING_REQUIRED' in Attribute:\r
230 # Guided data by -z option on first call is the process required data. Call the guided tool with the real option.\r
231 GenFdsGlobalVariable.GuidTool(TempFile, [DummyFile], ExternalTool, CmdOption)\r
232\r
233 #\r
234 # Call Gensection Add Section Header\r
235 #\r
236 if self.ProcessRequired in ("TRUE", "1"):\r
237 if 'PROCESSING_REQUIRED' not in Attribute:\r
238 Attribute.append('PROCESSING_REQUIRED')\r
239\r
240 if self.AuthStatusValid in ("TRUE", "1"):\r
241 Attribute.append('AUTH_STATUS_VALID')\r
242 GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'],\r
243 Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength)\r
244 OutputFileList = []\r
245 OutputFileList.append(OutputFile)\r
246 if 'PROCESSING_REQUIRED' in Attribute:\r
247 # reset guided section alignment to none for the processed required guided data\r
248 self.Alignment = None\r
249 self.IncludeFvSection = False\r
250 self.ProcessRequired = "TRUE"\r
251 return OutputFileList, self.Alignment\r
252\r
253\r
254\r