]>
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 # SPDX-License-Identifier: BSD-2-Clause-Patent
12 from __future__
import absolute_import
14 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
16 from .Ffs
import SectionSuffix
17 import Common
.LongFilePathOs
as os
18 from CommonDataClass
.FdfClass
import DataSectionClassObject
19 from Common
.Misc
import PeImageClass
20 from Common
.LongFilePathSupport
import CopyLongFilePath
21 from Common
.DataType
import *
23 ## generate data section
26 class DataSection (DataSectionClassObject
):
29 # @param self The object pointer
32 DataSectionClassObject
.__init
__(self
)
34 ## GenSection() method
36 # Generate compressed section
38 # @param self The object pointer
39 # @param OutputPath Where to place output file
40 # @param ModuleName Which module this section belongs to
41 # @param SecNum Index of section
42 # @param KeyStringList Filter for inputs of section generation
43 # @param FfsInf FfsInfStatement object that contains this section data
44 # @param Dict dictionary contains macro and its value
45 # @retval tuple (Generated file name list, section alignment)
47 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, keyStringList
, FfsFile
= None, Dict
= {}, IsMakefile
= False):
49 # Prepare the parameter of GenSection
51 if FfsFile
is not None:
52 self
.SectFileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.SectFileName
)
53 self
.SectFileName
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
, FfsFile
.CurrentArch
)
55 self
.SectFileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.SectFileName
)
56 self
.SectFileName
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)
58 """Check Section file exist or not !"""
60 if not os
.path
.exists(self
.SectFileName
):
61 self
.SectFileName
= os
.path
.join (GenFdsGlobalVariable
.WorkSpaceDir
,
64 """Copy Map file to Ffs output"""
65 Filename
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
)
66 if Filename
[(len(Filename
)-4):] == '.efi':
67 MapFile
= Filename
.replace('.efi', '.map')
68 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
70 if GenFdsGlobalVariable
.CopyList
== []:
71 GenFdsGlobalVariable
.CopyList
= [(MapFile
, CopyMapFile
)]
73 GenFdsGlobalVariable
.CopyList
.append((MapFile
, CopyMapFile
))
75 if os
.path
.exists(MapFile
):
76 if not os
.path
.exists(CopyMapFile
) or (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
77 CopyLongFilePath(MapFile
, CopyMapFile
)
79 #Get PE Section alignment when align is set to AUTO
80 if self
.Alignment
== 'Auto' and self
.SecType
in (BINARY_FILE_TYPE_TE
, BINARY_FILE_TYPE_PE32
):
81 ImageObj
= PeImageClass (Filename
)
82 if ImageObj
.SectionAlignment
< 0x400:
83 self
.Alignment
= str (ImageObj
.SectionAlignment
)
84 elif ImageObj
.SectionAlignment
< 0x100000:
85 self
.Alignment
= str (ImageObj
.SectionAlignment
// 0x400) + 'K'
87 self
.Alignment
= str (ImageObj
.SectionAlignment
// 0x100000) + 'M'
90 if self
.SecType
in (BINARY_FILE_TYPE_TE
, BINARY_FILE_TYPE_PE32
):
91 if self
.KeepReloc
is not None:
92 NoStrip
= self
.KeepReloc
95 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
96 if not os
.path
.exists(FileBeforeStrip
) or \
97 (os
.path
.getmtime(self
.SectFileName
) > os
.path
.getmtime(FileBeforeStrip
)):
98 CopyLongFilePath(self
.SectFileName
, FileBeforeStrip
)
99 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
100 GenFdsGlobalVariable
.GenerateFirmwareImage(
102 [GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)],
104 IsMakefile
= IsMakefile
106 self
.SectFileName
= StrippedFile
108 if self
.SecType
== BINARY_FILE_TYPE_TE
:
109 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
110 GenFdsGlobalVariable
.GenerateFirmwareImage(
112 [GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)],
114 IsMakefile
= IsMakefile
116 self
.SectFileName
= TeFile
118 OutputFile
= os
.path
.join (OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ SecNum
+ SectionSuffix
.get(self
.SecType
))
119 OutputFile
= os
.path
.normpath(OutputFile
)
120 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [self
.SectFileName
], Section
.Section
.SectionType
.get(self
.SecType
), IsMakefile
= IsMakefile
)
121 FileList
= [OutputFile
]
122 return FileList
, self
.Alignment