]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/DataSection.py
2 # process data section generation
4 # Copyright (c) 2007 - 2018, 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
22 import Common
.LongFilePathOs
as os
23 from CommonDataClass
.FdfClass
import DataSectionClassObject
24 from Common
.Misc
import PeImageClass
25 from Common
.LongFilePathSupport
import CopyLongFilePath
26 from Common
.DataType
import *
28 ## generate data section
31 class DataSection (DataSectionClassObject
):
34 # @param self The object pointer
37 DataSectionClassObject
.__init
__(self
)
39 ## GenSection() method
41 # Generate compressed section
43 # @param self The object pointer
44 # @param OutputPath Where to place output file
45 # @param ModuleName Which module this section belongs to
46 # @param SecNum Index of section
47 # @param KeyStringList Filter for inputs of section generation
48 # @param FfsInf FfsInfStatement object that contains this section data
49 # @param Dict dictionary contains macro and its value
50 # @retval tuple (Generated file name list, section alignment)
52 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, keyStringList
, FfsFile
= None, Dict
= {}, IsMakefile
= False):
54 # Prepare the parameter of GenSection
56 if FfsFile
is not None:
57 self
.SectFileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.SectFileName
)
58 self
.SectFileName
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
, FfsFile
.CurrentArch
)
60 self
.SectFileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.SectFileName
)
61 self
.SectFileName
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)
63 """Check Section file exist or not !"""
65 if not os
.path
.exists(self
.SectFileName
):
66 self
.SectFileName
= os
.path
.join (GenFdsGlobalVariable
.WorkSpaceDir
,
69 """Copy Map file to Ffs output"""
70 Filename
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
)
71 if Filename
[(len(Filename
)-4):] == '.efi':
72 MapFile
= Filename
.replace('.efi', '.map')
73 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
75 if GenFdsGlobalVariable
.CopyList
== []:
76 GenFdsGlobalVariable
.CopyList
= [(MapFile
, CopyMapFile
)]
78 GenFdsGlobalVariable
.CopyList
.append((MapFile
, CopyMapFile
))
80 if os
.path
.exists(MapFile
):
81 if not os
.path
.exists(CopyMapFile
) or (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
82 CopyLongFilePath(MapFile
, CopyMapFile
)
84 #Get PE Section alignment when align is set to AUTO
85 if self
.Alignment
== 'Auto' and self
.SecType
in (BINARY_FILE_TYPE_TE
, BINARY_FILE_TYPE_PE32
):
86 ImageObj
= PeImageClass (Filename
)
87 if ImageObj
.SectionAlignment
< 0x400:
88 self
.Alignment
= str (ImageObj
.SectionAlignment
)
89 elif ImageObj
.SectionAlignment
< 0x100000:
90 self
.Alignment
= str (ImageObj
.SectionAlignment
/ 0x400) + 'K'
92 self
.Alignment
= str (ImageObj
.SectionAlignment
/ 0x100000) + 'M'
95 if self
.SecType
in (BINARY_FILE_TYPE_TE
, BINARY_FILE_TYPE_PE32
):
96 if self
.KeepReloc
is not None:
97 NoStrip
= self
.KeepReloc
100 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
101 if not os
.path
.exists(FileBeforeStrip
) or \
102 (os
.path
.getmtime(self
.SectFileName
) > os
.path
.getmtime(FileBeforeStrip
)):
103 CopyLongFilePath(self
.SectFileName
, FileBeforeStrip
)
104 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
105 GenFdsGlobalVariable
.GenerateFirmwareImage(
107 [GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)],
109 IsMakefile
= IsMakefile
111 self
.SectFileName
= StrippedFile
113 if self
.SecType
== BINARY_FILE_TYPE_TE
:
114 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
115 GenFdsGlobalVariable
.GenerateFirmwareImage(
117 [GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)],
119 IsMakefile
= IsMakefile
121 self
.SectFileName
= TeFile
123 OutputFile
= os
.path
.join (OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ SecNum
+ Ffs
.SectionSuffix
.get(self
.SecType
))
124 OutputFile
= os
.path
.normpath(OutputFile
)
125 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [self
.SectFileName
], Section
.Section
.SectionType
.get(self
.SecType
), IsMakefile
= IsMakefile
)
126 FileList
= [OutputFile
]
127 return FileList
, self
.Alignment