]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # process rule section generation\r | |
3 | #\r | |
40d841f6 | 4 | # Copyright (c) 2007, 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 | |
56 | def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}) :\r | |
57 | \r | |
58 | if self.FileName != None and self.FileName.startswith('PCD('):\r | |
59 | self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName)\r | |
60 | """Prepare the parameter of GenSection"""\r | |
61 | if FfsInf != None :\r | |
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 | |
67 | NoStrip = True\r | |
68 | if FfsInf.ModuleType in ('SEC', 'PEI_CORE', 'PEIM') and SectionType in ('TE', 'PE32'):\r | |
69 | if FfsInf.KeepReloc != None:\r | |
70 | NoStrip = FfsInf.KeepReloc\r | |
71 | elif FfsInf.KeepRelocFromRule != None:\r | |
72 | NoStrip = FfsInf.KeepRelocFromRule\r | |
73 | elif self.KeepReloc != None:\r | |
74 | NoStrip = self.KeepReloc\r | |
75 | elif FfsInf.ShadowFromInfFile != None:\r | |
76 | NoStrip = FfsInf.ShadowFromInfFile\r | |
77 | else:\r | |
78 | EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s apply rule for None!" %ModuleName)\r | |
79 | \r | |
80 | """If the file name was pointed out, add it in FileList"""\r | |
81 | FileList = []\r | |
82 | if Filename != None:\r | |
83 | Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict)\r | |
f51461c8 LG |
84 | # check if the path is absolute or relative\r |
85 | if os.path.isabs(Filename):\r | |
86 | Filename = os.path.normpath(Filename)\r | |
87 | else:\r | |
88 | Filename = os.path.normpath(os.path.join(FfsInf.EfiOutputPath, Filename))\r | |
52302d4d | 89 | \r |
30fdf114 LG |
90 | if not self.Optional:\r |
91 | FileList.append(Filename)\r | |
92 | elif os.path.exists(Filename):\r | |
93 | FileList.append(Filename)\r | |
94 | else:\r | |
95 | FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict)\r | |
96 | if IsSect :\r | |
97 | return FileList, self.Alignment\r | |
98 | \r | |
99 | Index = 0\r | |
100 | \r | |
101 | """ If Section type is 'VERSION'"""\r | |
102 | OutputFileList = []\r | |
103 | if SectionType == 'VERSION':\r | |
104 | \r | |
105 | InfOverrideVerString = False\r | |
106 | if FfsInf.Version != None:\r | |
107 | #StringData = FfsInf.Version\r | |
108 | BuildNum = FfsInf.Version\r | |
109 | InfOverrideVerString = True\r | |
110 | \r | |
111 | if InfOverrideVerString:\r | |
112 | #VerTuple = ('-n', '"' + StringData + '"')\r | |
113 | if BuildNum != None and BuildNum != '':\r | |
114 | BuildNumTuple = ('-j', BuildNum)\r | |
115 | else:\r | |
116 | BuildNumTuple = tuple()\r | |
117 | \r | |
118 | Num = SecNum\r | |
119 | OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r | |
120 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r | |
121 | #Ui=StringData, \r | |
122 | Ver=BuildNum)\r | |
123 | OutputFileList.append(OutputFile)\r | |
124 | \r | |
125 | elif FileList != []:\r | |
126 | for File in FileList:\r | |
127 | Index = Index + 1\r | |
128 | Num = '%s.%d' %(SecNum , Index)\r | |
129 | OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r | |
130 | f = open(File, 'r')\r | |
131 | VerString = f.read()\r | |
132 | f.close()\r | |
30fdf114 LG |
133 | BuildNum = VerString\r |
134 | if BuildNum != None and BuildNum != '':\r | |
135 | BuildNumTuple = ('-j', BuildNum)\r | |
136 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r | |
137 | #Ui=VerString, \r | |
138 | Ver=BuildNum)\r | |
139 | OutputFileList.append(OutputFile)\r | |
140 | \r | |
141 | else:\r | |
30fdf114 LG |
142 | BuildNum = StringData\r |
143 | if BuildNum != None and BuildNum != '':\r | |
144 | BuildNumTuple = ('-j', BuildNum)\r | |
145 | else:\r | |
146 | BuildNumTuple = tuple()\r | |
147 | BuildNumString = ' ' + ' '.join(BuildNumTuple)\r | |
148 | \r | |
149 | #if VerString == '' and \r | |
150 | if BuildNumString == '':\r | |
151 | if self.Optional == True :\r | |
152 | GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r | |
153 | return [], None\r | |
154 | else:\r | |
155 | EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss Version Section value" %InfFileName)\r | |
156 | Num = SecNum\r | |
157 | OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r | |
158 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION',\r | |
159 | #Ui=VerString, \r | |
160 | Ver=BuildNum)\r | |
161 | OutputFileList.append(OutputFile)\r | |
162 | \r | |
163 | #\r | |
164 | # If Section Type is 'UI'\r | |
165 | #\r | |
166 | elif SectionType == 'UI':\r | |
167 | \r | |
168 | InfOverrideUiString = False\r | |
169 | if FfsInf.Ui != None:\r | |
170 | StringData = FfsInf.Ui\r | |
171 | InfOverrideUiString = True\r | |
172 | \r | |
173 | if InfOverrideUiString:\r | |
174 | Num = SecNum\r | |
175 | OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r | |
176 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r | |
177 | Ui=StringData)\r | |
178 | OutputFileList.append(OutputFile)\r | |
179 | \r | |
180 | elif FileList != []:\r | |
181 | for File in FileList:\r | |
182 | Index = Index + 1\r | |
183 | Num = '%s.%d' %(SecNum , Index)\r | |
184 | OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r | |
185 | f = open(File, 'r')\r | |
186 | UiString = f.read()\r | |
187 | f.close()\r | |
188 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r | |
189 | Ui=UiString)\r | |
190 | OutputFileList.append(OutputFile)\r | |
191 | else:\r | |
192 | if StringData != None and len(StringData) > 0:\r | |
193 | UiTuple = ('-n', '"' + StringData + '"')\r | |
194 | else:\r | |
195 | UiTuple = tuple()\r | |
196 | \r | |
197 | if self.Optional == True :\r | |
198 | GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r | |
199 | return '', None\r | |
200 | else:\r | |
201 | EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss UI Section value" %InfFileName)\r | |
202 | \r | |
203 | Num = SecNum\r | |
204 | OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + Ffs.SectionSuffix.get(SectionType))\r | |
205 | GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE',\r | |
206 | Ui=StringData)\r | |
207 | OutputFileList.append(OutputFile)\r | |
208 | \r | |
209 | \r | |
210 | else:\r | |
211 | """If File List is empty"""\r | |
212 | if FileList == [] :\r | |
213 | if self.Optional == True:\r | |
214 | GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!")\r | |
215 | return [], None\r | |
216 | else:\r | |
217 | EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName))\r | |
218 | \r | |
219 | else:\r | |
220 | """Convert the File to Section file one by one """\r | |
221 | for File in FileList:\r | |
222 | """ Copy Map file to FFS output path """\r | |
223 | Index = Index + 1\r | |
224 | Num = '%s.%d' %(SecNum , Index)\r | |
225 | OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get(SectionType))\r | |
226 | File = GenFdsGlobalVariable.MacroExtend(File, Dict)\r | |
52302d4d LG |
227 | \r |
228 | #Get PE Section alignment when align is set to AUTO\r | |
229 | if self.Alignment == 'Auto' and (SectionType == 'PE32' or SectionType == 'TE'):\r | |
230 | ImageObj = PeImageClass (File)\r | |
231 | if ImageObj.SectionAlignment < 0x400:\r | |
232 | self.Alignment = str (ImageObj.SectionAlignment)\r | |
233 | else:\r | |
234 | self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r | |
235 | \r | |
30fdf114 LG |
236 | if File[(len(File)-4):] == '.efi':\r |
237 | MapFile = File.replace('.efi', '.map')\r | |
238 | if os.path.exists(MapFile):\r | |
239 | CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r | |
240 | if not os.path.exists(CopyMapFile) or \\r | |
1be2ed90 HC |
241 | (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r |
242 | CopyLongFilePath(MapFile, CopyMapFile)\r | |
30fdf114 LG |
243 | \r |
244 | if not NoStrip:\r | |
245 | FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r | |
246 | if not os.path.exists(FileBeforeStrip) or \\r | |
247 | (os.path.getmtime(File) > os.path.getmtime(FileBeforeStrip)):\r | |
1be2ed90 | 248 | CopyLongFilePath(File, FileBeforeStrip)\r |
30fdf114 LG |
249 | StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r |
250 | GenFdsGlobalVariable.GenerateFirmwareImage(\r | |
251 | StrippedFile,\r | |
52302d4d | 252 | [File],\r |
30fdf114 LG |
253 | Strip=True\r |
254 | )\r | |
255 | File = StrippedFile\r | |
52302d4d | 256 | \r |
30fdf114 LG |
257 | """For TE Section call GenFw to generate TE image"""\r |
258 | \r | |
259 | if SectionType == 'TE':\r | |
260 | TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r | |
261 | GenFdsGlobalVariable.GenerateFirmwareImage(\r | |
262 | TeFile,\r | |
52302d4d | 263 | [File],\r |
30fdf114 LG |
264 | Type='te'\r |
265 | )\r | |
266 | File = TeFile\r | |
267 | \r | |
268 | """Call GenSection"""\r | |
269 | GenFdsGlobalVariable.GenerateSection(OutputFile,\r | |
52302d4d | 270 | [File],\r |
30fdf114 LG |
271 | Section.Section.SectionType.get (SectionType)\r |
272 | )\r | |
273 | OutputFileList.append(OutputFile)\r | |
274 | \r | |
275 | return OutputFileList, self.Alignment\r |