]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/DataSection.py
989e33c43fff56234a60b5ad80c019f58454de42
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.
18 from __future__
import absolute_import
20 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
22 from .Ffs
import SectionSuffix
23 import Common
.LongFilePathOs
as os
24 from CommonDataClass
.FdfClass
import DataSectionClassObject
25 from Common
.Misc
import PeImageClass
26 from Common
.LongFilePathSupport
import CopyLongFilePath
27 from Common
.DataType
import *
29 ## generate data section
32 class DataSection (DataSectionClassObject
):
35 # @param self The object pointer
38 DataSectionClassObject
.__init
__(self
)
40 ## GenSection() method
42 # Generate compressed section
44 # @param self The object pointer
45 # @param OutputPath Where to place output file
46 # @param ModuleName Which module this section belongs to
47 # @param SecNum Index of section
48 # @param KeyStringList Filter for inputs of section generation
49 # @param FfsInf FfsInfStatement object that contains this section data
50 # @param Dict dictionary contains macro and its value
51 # @retval tuple (Generated file name list, section alignment)
53 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, keyStringList
, FfsFile
= None, Dict
= {}, IsMakefile
= False):
55 # Prepare the parameter of GenSection
57 if FfsFile
is not None:
58 self
.SectFileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.SectFileName
)
59 self
.SectFileName
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
, FfsFile
.CurrentArch
)
61 self
.SectFileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.SectFileName
)
62 self
.SectFileName
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)
64 """Check Section file exist or not !"""
66 if not os
.path
.exists(self
.SectFileName
):
67 self
.SectFileName
= os
.path
.join (GenFdsGlobalVariable
.WorkSpaceDir
,
70 """Copy Map file to Ffs output"""
71 Filename
= GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
)
72 if Filename
[(len(Filename
)-4):] == '.efi':
73 MapFile
= Filename
.replace('.efi', '.map')
74 CopyMapFile
= os
.path
.join(OutputPath
, ModuleName
+ '.map')
76 if GenFdsGlobalVariable
.CopyList
== []:
77 GenFdsGlobalVariable
.CopyList
= [(MapFile
, CopyMapFile
)]
79 GenFdsGlobalVariable
.CopyList
.append((MapFile
, CopyMapFile
))
81 if os
.path
.exists(MapFile
):
82 if not os
.path
.exists(CopyMapFile
) or (os
.path
.getmtime(MapFile
) > os
.path
.getmtime(CopyMapFile
)):
83 CopyLongFilePath(MapFile
, CopyMapFile
)
85 #Get PE Section alignment when align is set to AUTO
86 if self
.Alignment
== 'Auto' and self
.SecType
in (BINARY_FILE_TYPE_TE
, BINARY_FILE_TYPE_PE32
):
87 ImageObj
= PeImageClass (Filename
)
88 if ImageObj
.SectionAlignment
< 0x400:
89 self
.Alignment
= str (ImageObj
.SectionAlignment
)
90 elif ImageObj
.SectionAlignment
< 0x100000:
91 self
.Alignment
= str (ImageObj
.SectionAlignment
// 0x400) + 'K'
93 self
.Alignment
= str (ImageObj
.SectionAlignment
// 0x100000) + 'M'
96 if self
.SecType
in (BINARY_FILE_TYPE_TE
, BINARY_FILE_TYPE_PE32
):
97 if self
.KeepReloc
is not None:
98 NoStrip
= self
.KeepReloc
101 FileBeforeStrip
= os
.path
.join(OutputPath
, ModuleName
+ '.efi')
102 if not os
.path
.exists(FileBeforeStrip
) or \
103 (os
.path
.getmtime(self
.SectFileName
) > os
.path
.getmtime(FileBeforeStrip
)):
104 CopyLongFilePath(self
.SectFileName
, FileBeforeStrip
)
105 StrippedFile
= os
.path
.join(OutputPath
, ModuleName
+ '.stripped')
106 GenFdsGlobalVariable
.GenerateFirmwareImage(
108 [GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)],
110 IsMakefile
= IsMakefile
112 self
.SectFileName
= StrippedFile
114 if self
.SecType
== BINARY_FILE_TYPE_TE
:
115 TeFile
= os
.path
.join( OutputPath
, ModuleName
+ 'Te.raw')
116 GenFdsGlobalVariable
.GenerateFirmwareImage(
118 [GenFdsGlobalVariable
.MacroExtend(self
.SectFileName
, Dict
)],
120 IsMakefile
= IsMakefile
122 self
.SectFileName
= TeFile
124 OutputFile
= os
.path
.join (OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ SecNum
+ SectionSuffix
.get(self
.SecType
))
125 OutputFile
= os
.path
.normpath(OutputFile
)
126 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [self
.SectFileName
], Section
.Section
.SectionType
.get(self
.SecType
), IsMakefile
= IsMakefile
)
127 FileList
= [OutputFile
]
128 return FileList
, self
.Alignment