]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/DataSection.py
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DataSection.py
CommitLineData
30fdf114
LG
1## @file\r
2# process data section generation\r
3#\r
4# Copyright (c) 2007, Intel Corporation\r
5#\r
6# All rights reserved. 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 os\r
23from CommonDataClass.FdfClass import DataSectionClassObject\r
24import shutil\r
25\r
26## generate data section\r
27#\r
28#\r
29class DataSection (DataSectionClassObject):\r
30 ## The constructor\r
31 #\r
32 # @param self The object pointer\r
33 #\r
34 def __init__(self):\r
35 DataSectionClassObject.__init__(self)\r
36\r
37 ## GenSection() method\r
38 #\r
39 # Generate compressed section\r
40 #\r
41 # @param self The object pointer\r
42 # @param OutputPath Where to place output file\r
43 # @param ModuleName Which module this section belongs to\r
44 # @param SecNum Index of section\r
45 # @param KeyStringList Filter for inputs of section generation\r
46 # @param FfsInf FfsInfStatement object that contains this section data\r
47 # @param Dict dictionary contains macro and its value\r
48 # @retval tuple (Generated file name list, section alignment)\r
49 #\r
50 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}):\r
51 #\r
52 # Prepare the parameter of GenSection\r
53 #\r
54 if FfsFile != None:\r
55 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
56 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)\r
57 else:\r
58 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
59 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)\r
60\r
61 """Check Section file exist or not !"""\r
62\r
63 if not os.path.exists(self.SectFileName):\r
64 self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,\r
65 self.SectFileName)\r
66\r
67 """Copy Map file to Ffs output"""\r
68 Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName)\r
69 if Filename[(len(Filename)-4):] == '.efi':\r
70 MapFile = Filename.replace('.efi', '.map')\r
71 if os.path.exists(MapFile):\r
72 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
73 if not os.path.exists(CopyMapFile) or \\r
74 (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
75 shutil.copyfile(MapFile, CopyMapFile)\r
76\r
77 NoStrip = True\r
78 if self.SecType in ('TE', 'PE32'):\r
79 if self.KeepReloc != None:\r
80 NoStrip = self.KeepReloc\r
81\r
82 if not NoStrip:\r
83 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
84 if not os.path.exists(FileBeforeStrip) or \\r
85 (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):\r
86 shutil.copyfile(self.SectFileName, FileBeforeStrip)\r
87 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
88 GenFdsGlobalVariable.GenerateFirmwareImage(\r
89 StrippedFile,\r
90 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
91 Strip=True\r
92 )\r
93 self.SectFileName = StrippedFile\r
94\r
95 if self.SecType == 'TE':\r
96 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
97 GenFdsGlobalVariable.GenerateFirmwareImage(\r
98 TeFile,\r
99 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
100 Type='te'\r
101 )\r
102 self.SectFileName = TeFile\r
103\r
104 OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get(self.SecType))\r
105 OutputFile = os.path.normpath(OutputFile)\r
106\r
107 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType))\r
108 FileList = [OutputFile]\r
109 return FileList, self.Alignment\r