]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/DataSection.py
BaseTools: Use absolute import in GenFds
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DataSection.py
CommitLineData
30fdf114
LG
1## @file\r
2# process data section generation\r
3#\r
8bb63e37 4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
30fdf114 5#\r
40d841f6 6# This program and the accompanying materials\r
30fdf114
LG
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15##\r
16# Import Modules\r
17#\r
bfa65b61
GL
18from __future__ import absolute_import\r
19from . import Section\r
20from .GenFdsGlobalVariable import GenFdsGlobalVariable\r
30fdf114 21import subprocess\r
bfa65b61 22from .Ffs import Ffs\r
1be2ed90 23import Common.LongFilePathOs as os\r
30fdf114 24from CommonDataClass.FdfClass import DataSectionClassObject\r
9053bc51 25from Common.Misc import PeImageClass\r
1be2ed90 26from Common.LongFilePathSupport import CopyLongFilePath\r
8bb63e37 27from Common.DataType import *\r
30fdf114
LG
28\r
29## generate data section\r
30#\r
31#\r
32class DataSection (DataSectionClassObject):\r
33 ## The constructor\r
34 #\r
35 # @param self The object pointer\r
36 #\r
37 def __init__(self):\r
38 DataSectionClassObject.__init__(self)\r
39\r
40 ## GenSection() method\r
41 #\r
42 # Generate compressed section\r
43 #\r
44 # @param self The object pointer\r
45 # @param OutputPath Where to place output file\r
46 # @param ModuleName Which module this section belongs to\r
47 # @param SecNum Index of section\r
48 # @param KeyStringList Filter for inputs of section generation\r
49 # @param FfsInf FfsInfStatement object that contains this section data\r
50 # @param Dict dictionary contains macro and its value\r
51 # @retval tuple (Generated file name list, section alignment)\r
52 #\r
37de70b7 53 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):\r
30fdf114
LG
54 #\r
55 # Prepare the parameter of GenSection\r
56 #\r
4231a819 57 if FfsFile is not None:\r
30fdf114
LG
58 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
59 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)\r
60 else:\r
61 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
62 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)\r
63\r
64 """Check Section file exist or not !"""\r
65\r
66 if not os.path.exists(self.SectFileName):\r
67 self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,\r
68 self.SectFileName)\r
69\r
70 """Copy Map file to Ffs output"""\r
71 Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName)\r
72 if Filename[(len(Filename)-4):] == '.efi':\r
73 MapFile = Filename.replace('.efi', '.map')\r
37de70b7
YZ
74 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
75 if IsMakefile:\r
76 if GenFdsGlobalVariable.CopyList == []:\r
77 GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)]\r
78 else:\r
79 GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile))\r
80 else:\r
81 if os.path.exists(MapFile):\r
82 if not os.path.exists(CopyMapFile) or (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
83 CopyLongFilePath(MapFile, CopyMapFile)\r
30fdf114 84\r
9053bc51 85 #Get PE Section alignment when align is set to AUTO\r
91fa33ee 86 if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\r
9053bc51 87 ImageObj = PeImageClass (Filename)\r
88 if ImageObj.SectionAlignment < 0x400:\r
89 self.Alignment = str (ImageObj.SectionAlignment)\r
e921f58d 90 elif ImageObj.SectionAlignment < 0x100000:\r
9053bc51 91 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
e921f58d
YZ
92 else:\r
93 self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'\r
9053bc51 94\r
30fdf114 95 NoStrip = True\r
91fa33ee 96 if self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\r
4231a819 97 if self.KeepReloc is not None:\r
30fdf114
LG
98 NoStrip = self.KeepReloc\r
99\r
100 if not NoStrip:\r
101 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
102 if not os.path.exists(FileBeforeStrip) or \\r
103 (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):\r
1be2ed90 104 CopyLongFilePath(self.SectFileName, FileBeforeStrip)\r
30fdf114
LG
105 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
106 GenFdsGlobalVariable.GenerateFirmwareImage(\r
37de70b7
YZ
107 StrippedFile,\r
108 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
109 Strip=True,\r
110 IsMakefile = IsMakefile\r
111 )\r
30fdf114
LG
112 self.SectFileName = StrippedFile\r
113\r
91fa33ee 114 if self.SecType == BINARY_FILE_TYPE_TE:\r
30fdf114
LG
115 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
116 GenFdsGlobalVariable.GenerateFirmwareImage(\r
37de70b7
YZ
117 TeFile,\r
118 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
119 Type='te',\r
120 IsMakefile = IsMakefile\r
121 )\r
30fdf114
LG
122 self.SectFileName = TeFile\r
123\r
8bb63e37 124 OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get(self.SecType))\r
30fdf114 125 OutputFile = os.path.normpath(OutputFile)\r
37de70b7 126 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)\r
30fdf114
LG
127 FileList = [OutputFile]\r
128 return FileList, self.Alignment\r