]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/DataSection.py
BaseTools: use set instead of list for a variable to be used with in
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DataSection.py
CommitLineData
30fdf114
LG
1## @file\r
2# process data section generation\r
3#\r
e921f58d 4# Copyright (c) 2007 - 2017, 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
18import Section\r
19from GenFdsGlobalVariable import GenFdsGlobalVariable\r
20import subprocess\r
21from Ffs import Ffs\r
1be2ed90 22import Common.LongFilePathOs as os\r
30fdf114 23from CommonDataClass.FdfClass import DataSectionClassObject\r
9053bc51 24from Common.Misc import PeImageClass\r
1be2ed90 25from Common.LongFilePathSupport import CopyLongFilePath\r
30fdf114
LG
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
37de70b7 51 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):\r
30fdf114
LG
52 #\r
53 # Prepare the parameter of GenSection\r
54 #\r
4231a819 55 if FfsFile is not None:\r
30fdf114
LG
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
37de70b7
YZ
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
30fdf114 82\r
9053bc51 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
e921f58d 88 elif ImageObj.SectionAlignment < 0x100000:\r
9053bc51 89 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
e921f58d
YZ
90 else:\r
91 self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'\r
9053bc51 92\r
30fdf114
LG
93 NoStrip = True\r
94 if self.SecType in ('TE', 'PE32'):\r
4231a819 95 if self.KeepReloc is not None:\r
30fdf114
LG
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
1be2ed90 102 CopyLongFilePath(self.SectFileName, FileBeforeStrip)\r
30fdf114
LG
103 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
104 GenFdsGlobalVariable.GenerateFirmwareImage(\r
37de70b7
YZ
105 StrippedFile,\r
106 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
107 Strip=True,\r
108 IsMakefile = IsMakefile\r
109 )\r
30fdf114
LG
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
37de70b7
YZ
115 TeFile,\r
116 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
117 Type='te',\r
118 IsMakefile = IsMakefile\r
119 )\r
30fdf114
LG
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
37de70b7 124 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)\r
30fdf114
LG
125 FileList = [OutputFile]\r
126 return FileList, self.Alignment\r