]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/DataSection.py
Sync EDKII BaseTools to BaseTools project r1971
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DataSection.py
1 ## @file
2 # process data section generation
3 #
4 # Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 ##
16 # Import Modules
17 #
18 import Section
19 from GenFdsGlobalVariable import GenFdsGlobalVariable
20 import subprocess
21 from Ffs import Ffs
22 import os
23 from CommonDataClass.FdfClass import DataSectionClassObject
24 import shutil
25
26 ## generate data section
27 #
28 #
29 class DataSection (DataSectionClassObject):
30 ## The constructor
31 #
32 # @param self The object pointer
33 #
34 def __init__(self):
35 DataSectionClassObject.__init__(self)
36
37 ## GenSection() method
38 #
39 # Generate compressed section
40 #
41 # @param self The object pointer
42 # @param OutputPath Where to place output file
43 # @param ModuleName Which module this section belongs to
44 # @param SecNum Index of section
45 # @param KeyStringList Filter for inputs of section generation
46 # @param FfsInf FfsInfStatement object that contains this section data
47 # @param Dict dictionary contains macro and its value
48 # @retval tuple (Generated file name list, section alignment)
49 #
50 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}):
51 #
52 # Prepare the parameter of GenSection
53 #
54 if FfsFile != None:
55 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
56 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)
57 else:
58 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)
59 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)
60
61 """Check Section file exist or not !"""
62
63 if not os.path.exists(self.SectFileName):
64 self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,
65 self.SectFileName)
66
67 """Copy Map file to Ffs output"""
68 Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName)
69 if Filename[(len(Filename)-4):] == '.efi':
70 MapFile = Filename.replace('.efi', '.map')
71 if os.path.exists(MapFile):
72 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')
73 if not os.path.exists(CopyMapFile) or \
74 (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):
75 shutil.copyfile(MapFile, CopyMapFile)
76
77 NoStrip = True
78 if self.SecType in ('TE', 'PE32'):
79 if self.KeepReloc != None:
80 NoStrip = self.KeepReloc
81
82 if not NoStrip:
83 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')
84 if not os.path.exists(FileBeforeStrip) or \
85 (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):
86 shutil.copyfile(self.SectFileName, FileBeforeStrip)
87 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')
88 GenFdsGlobalVariable.GenerateFirmwareImage(
89 StrippedFile,
90 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],
91 Strip=True
92 )
93 self.SectFileName = StrippedFile
94
95 if self.SecType == 'TE':
96 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')
97 GenFdsGlobalVariable.GenerateFirmwareImage(
98 TeFile,
99 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],
100 Type='te'
101 )
102 self.SectFileName = TeFile
103
104 OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get(self.SecType))
105 OutputFile = os.path.normpath(OutputFile)
106
107 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType))
108 FileList = [OutputFile]
109 return FileList, self.Alignment