]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/DataSection.py
2 # process data section generation
4 # Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
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
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.
19 from GenFdsGlobalVariable
import GenFdsGlobalVariable
23 from CommonDataClass
.FdfClass
import DataSectionClassObject
24 from Common
.Misc
import PeImageClass
27 ## generate data section
30 class DataSection (DataSectionClassObject
):
33 # @param self The object pointer
36 DataSectionClassObject
.__init
__(self
)
38 ## GenSection() method
40 # Generate compressed section
42 # @param self The object pointer
43 # @param OutputPath Where to place output file
44 # @param ModuleName Which module this section belongs to
45 # @param SecNum Index of section
46 # @param KeyStringList Filter for inputs of section generation
47 # @param FfsInf FfsInfStatement object that contains this section data
48 # @param Dict dictionary contains macro and its value
49 # @retval tuple (Generated file name list, section alignment)
51 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, keyStringList
, FfsFile
= None, Dict
= {}):
53 # Prepare the parameter of GenSection
56 self
.SectFileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.SectFileName
)
57 self
.SectFileName
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
, FfsFile
.CurrentArch
)
59 self
.SectFileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.SectFileName
)
60 self
.SectFileName
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)
62 """Check Section file exist or not !"""
64 if not os
.path
.exists(self
.SectFileName
):
65 self
.SectFileName
= os
.path
.join (GenFdsGlobalVariable
.WorkSpaceDir
,
68 """Copy Map file to Ffs output"""
69 Filename
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
)
70 if Filename
[(len(Filename
)-4):] == '.efi':
71 MapFile
= Filename
.replace('.efi', '.map')
72 if os
.path
.exists(MapFile
):
73 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
74 if not os
.path
.exists(CopyMapFile
) or \
75 (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
76 shutil
.copyfile(MapFile
, CopyMapFile
)
78 #Get PE Section alignment when align is set to AUTO
79 if self
.Alignment
== 'Auto' and self
.SecType
in ('TE', 'PE32'):
80 ImageObj
= PeImageClass (Filename
)
81 if ImageObj
.SectionAlignment
< 0x400:
82 self
.Alignment
= str (ImageObj
.SectionAlignment
)
84 self
.Alignment
= str (ImageObj
.SectionAlignment
/ 0x400) + 'K'
87 if self
.SecType
in ('TE', 'PE32'):
88 if self
.KeepReloc
!= None:
89 NoStrip
= self
.KeepReloc
92 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
93 if not os
.path
.exists(FileBeforeStrip
) or \
94 (os
.path
.getmtime(self
.SectFileName
) > os
.path
.getmtime(FileBeforeStrip
)):
95 shutil
.copyfile(self
.SectFileName
, FileBeforeStrip
)
96 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
97 GenFdsGlobalVariable
.GenerateFirmwareImage(
99 [GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)],
102 self
.SectFileName
= StrippedFile
104 if self
.SecType
== 'TE':
105 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
106 GenFdsGlobalVariable
.GenerateFirmwareImage(
108 [GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)],
111 self
.SectFileName
= TeFile
113 OutputFile
= os
.path
.join (OutputPath
, ModuleName
+ 'SEC' + SecNum
+ Ffs
.SectionSuffix
.get(self
.SecType
))
114 OutputFile
= os
.path
.normpath(OutputFile
)
116 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [self
.SectFileName
], Section
.Section
.SectionType
.get(self
.SecType
))
117 FileList
= [OutputFile
]
118 return FileList
, self
.Alignment