]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/GenFds/DataSection.py
BaseTools: skip updating temporary variable.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DataSection.py
... / ...
CommitLineData
1## @file\r
2# process data 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
19from GenFdsGlobalVariable import GenFdsGlobalVariable\r
20import subprocess\r
21from Ffs import Ffs\r
22import Common.LongFilePathOs as os\r
23from CommonDataClass.FdfClass import DataSectionClassObject\r
24from Common.Misc import PeImageClass\r
25from Common.LongFilePathSupport import CopyLongFilePath\r
26\r
27## generate data section\r
28#\r
29#\r
30class DataSection (DataSectionClassObject):\r
31 ## The constructor\r
32 #\r
33 # @param self The object pointer\r
34 #\r
35 def __init__(self):\r
36 DataSectionClassObject.__init__(self)\r
37\r
38 ## GenSection() method\r
39 #\r
40 # Generate compressed section\r
41 #\r
42 # @param self The object pointer\r
43 # @param OutputPath Where to place output file\r
44 # @param ModuleName Which module this section belongs to\r
45 # @param SecNum Index of section\r
46 # @param KeyStringList Filter for inputs of section generation\r
47 # @param FfsInf FfsInfStatement object that contains this section data\r
48 # @param Dict dictionary contains macro and its value\r
49 # @retval tuple (Generated file name list, section alignment)\r
50 #\r
51 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):\r
52 #\r
53 # Prepare the parameter of GenSection\r
54 #\r
55 if FfsFile is not None:\r
56 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
57 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)\r
58 else:\r
59 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
60 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)\r
61\r
62 """Check Section file exist or not !"""\r
63\r
64 if not os.path.exists(self.SectFileName):\r
65 self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,\r
66 self.SectFileName)\r
67\r
68 """Copy Map file to Ffs output"""\r
69 Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName)\r
70 if Filename[(len(Filename)-4):] == '.efi':\r
71 MapFile = Filename.replace('.efi', '.map')\r
72 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
73 if IsMakefile:\r
74 if GenFdsGlobalVariable.CopyList == []:\r
75 GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)]\r
76 else:\r
77 GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile))\r
78 else:\r
79 if os.path.exists(MapFile):\r
80 if not os.path.exists(CopyMapFile) or (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
81 CopyLongFilePath(MapFile, CopyMapFile)\r
82\r
83 #Get PE Section alignment when align is set to AUTO\r
84 if self.Alignment == 'Auto' and self.SecType in ('TE', 'PE32'):\r
85 ImageObj = PeImageClass (Filename)\r
86 if ImageObj.SectionAlignment < 0x400:\r
87 self.Alignment = str (ImageObj.SectionAlignment)\r
88 elif ImageObj.SectionAlignment < 0x100000:\r
89 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
90 else:\r
91 self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'\r
92\r
93 NoStrip = True\r
94 if self.SecType in ('TE', 'PE32'):\r
95 if self.KeepReloc is not None:\r
96 NoStrip = self.KeepReloc\r
97\r
98 if not NoStrip:\r
99 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
100 if not os.path.exists(FileBeforeStrip) or \\r
101 (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):\r
102 CopyLongFilePath(self.SectFileName, FileBeforeStrip)\r
103 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
104 GenFdsGlobalVariable.GenerateFirmwareImage(\r
105 StrippedFile,\r
106 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
107 Strip=True,\r
108 IsMakefile = IsMakefile\r
109 )\r
110 self.SectFileName = StrippedFile\r
111\r
112 if self.SecType == 'TE':\r
113 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
114 GenFdsGlobalVariable.GenerateFirmwareImage(\r
115 TeFile,\r
116 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
117 Type='te',\r
118 IsMakefile = IsMakefile\r
119 )\r
120 self.SectFileName = TeFile\r
121\r
122 OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get(self.SecType))\r
123 OutputFile = os.path.normpath(OutputFile)\r
124 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)\r
125 FileList = [OutputFile]\r
126 return FileList, self.Alignment\r