]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/DataSection.py
BaseTools: Enhance BaseTools supports FixedAtBuild usage in VFR file
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DataSection.py
CommitLineData
30fdf114
LG
1## @file\r
2# process data section generation\r
3#\r
1be2ed90 4# Copyright (c) 2007 - 2014, 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
51 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}):\r
52 #\r
53 # Prepare the parameter of GenSection\r
54 #\r
55 if FfsFile != 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 if os.path.exists(MapFile):\r
73 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
1be2ed90
HC
74 if not os.path.exists(CopyMapFile) or (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
75 CopyLongFilePath(MapFile, CopyMapFile)\r
30fdf114 76\r
9053bc51 77 #Get PE Section alignment when align is set to AUTO\r
78 if self.Alignment == 'Auto' and self.SecType in ('TE', 'PE32'):\r
79 ImageObj = PeImageClass (Filename)\r
80 if ImageObj.SectionAlignment < 0x400:\r
81 self.Alignment = str (ImageObj.SectionAlignment)\r
82 else:\r
83 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
84\r
30fdf114
LG
85 NoStrip = True\r
86 if self.SecType in ('TE', 'PE32'):\r
87 if self.KeepReloc != None:\r
88 NoStrip = self.KeepReloc\r
89\r
90 if not NoStrip:\r
91 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
92 if not os.path.exists(FileBeforeStrip) or \\r
93 (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):\r
1be2ed90 94 CopyLongFilePath(self.SectFileName, FileBeforeStrip)\r
30fdf114
LG
95 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
96 GenFdsGlobalVariable.GenerateFirmwareImage(\r
97 StrippedFile,\r
98 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
99 Strip=True\r
100 )\r
101 self.SectFileName = StrippedFile\r
102\r
103 if self.SecType == 'TE':\r
104 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
105 GenFdsGlobalVariable.GenerateFirmwareImage(\r
106 TeFile,\r
107 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
108 Type='te'\r
109 )\r
110 self.SectFileName = TeFile\r
111\r
112 OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get(self.SecType))\r
113 OutputFile = os.path.normpath(OutputFile)\r
114\r
115 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType))\r
116 FileList = [OutputFile]\r
117 return FileList, self.Alignment\r