]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/GenFds/DataSection.py
BaseTools: fix imports
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DataSection.py
... / ...
CommitLineData
1## @file\r
2# process data section generation\r
3#\r
4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
5#\r
6# This program and the accompanying materials\r
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
18from __future__ import absolute_import\r
19from . import Section\r
20from .GenFdsGlobalVariable import GenFdsGlobalVariable\r
21import subprocess\r
22from .Ffs import SectionSuffix\r
23import Common.LongFilePathOs as os\r
24from CommonDataClass.FdfClass import DataSectionClassObject\r
25from Common.Misc import PeImageClass\r
26from Common.LongFilePathSupport import CopyLongFilePath\r
27from Common.DataType import *\r
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
53 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):\r
54 #\r
55 # Prepare the parameter of GenSection\r
56 #\r
57 if FfsFile is not None:\r
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
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
84\r
85 #Get PE Section alignment when align is set to AUTO\r
86 if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\r
87 ImageObj = PeImageClass (Filename)\r
88 if ImageObj.SectionAlignment < 0x400:\r
89 self.Alignment = str (ImageObj.SectionAlignment)\r
90 elif ImageObj.SectionAlignment < 0x100000:\r
91 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
92 else:\r
93 self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'\r
94\r
95 NoStrip = True\r
96 if self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\r
97 if self.KeepReloc is not None:\r
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
104 CopyLongFilePath(self.SectFileName, FileBeforeStrip)\r
105 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
106 GenFdsGlobalVariable.GenerateFirmwareImage(\r
107 StrippedFile,\r
108 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
109 Strip=True,\r
110 IsMakefile = IsMakefile\r
111 )\r
112 self.SectFileName = StrippedFile\r
113\r
114 if self.SecType == BINARY_FILE_TYPE_TE:\r
115 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
116 GenFdsGlobalVariable.GenerateFirmwareImage(\r
117 TeFile,\r
118 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
119 Type='te',\r
120 IsMakefile = IsMakefile\r
121 )\r
122 self.SectFileName = TeFile\r
123\r
124 OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + SectionSuffix.get(self.SecType))\r
125 OutputFile = os.path.normpath(OutputFile)\r
126 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)\r
127 FileList = [OutputFile]\r
128 return FileList, self.Alignment\r