]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/DataSection.py
BaseTools: remove redundant if comparison
[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
18import Section\r
19from GenFdsGlobalVariable import GenFdsGlobalVariable\r
20import subprocess\r
21from Ffs import Ffs\r
1be2ed90 22import Common.LongFilePathOs as os\r
30fdf114 23from CommonDataClass.FdfClass import DataSectionClassObject\r
9053bc51 24from Common.Misc import PeImageClass\r
1be2ed90 25from Common.LongFilePathSupport import CopyLongFilePath\r
8bb63e37 26from Common.DataType import *\r
30fdf114
LG
27\r
28## generate data section\r
29#\r
30#\r
31class DataSection (DataSectionClassObject):\r
32 ## The constructor\r
33 #\r
34 # @param self The object pointer\r
35 #\r
36 def __init__(self):\r
37 DataSectionClassObject.__init__(self)\r
38\r
39 ## GenSection() method\r
40 #\r
41 # Generate compressed section\r
42 #\r
43 # @param self The object pointer\r
44 # @param OutputPath Where to place output file\r
45 # @param ModuleName Which module this section belongs to\r
46 # @param SecNum Index of section\r
47 # @param KeyStringList Filter for inputs of section generation\r
48 # @param FfsInf FfsInfStatement object that contains this section data\r
49 # @param Dict dictionary contains macro and its value\r
50 # @retval tuple (Generated file name list, section alignment)\r
51 #\r
37de70b7 52 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):\r
30fdf114
LG
53 #\r
54 # Prepare the parameter of GenSection\r
55 #\r
4231a819 56 if FfsFile is not None:\r
30fdf114
LG
57 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
58 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch)\r
59 else:\r
60 self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName)\r
61 self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)\r
62\r
63 """Check Section file exist or not !"""\r
64\r
65 if not os.path.exists(self.SectFileName):\r
66 self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir,\r
67 self.SectFileName)\r
68\r
69 """Copy Map file to Ffs output"""\r
70 Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName)\r
71 if Filename[(len(Filename)-4):] == '.efi':\r
72 MapFile = Filename.replace('.efi', '.map')\r
37de70b7
YZ
73 CopyMapFile = os.path.join(OutputPath, ModuleName + '.map')\r
74 if IsMakefile:\r
75 if GenFdsGlobalVariable.CopyList == []:\r
76 GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)]\r
77 else:\r
78 GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile))\r
79 else:\r
80 if os.path.exists(MapFile):\r
81 if not os.path.exists(CopyMapFile) or (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
82 CopyLongFilePath(MapFile, CopyMapFile)\r
30fdf114 83\r
9053bc51 84 #Get PE Section alignment when align is set to AUTO\r
91fa33ee 85 if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\r
9053bc51 86 ImageObj = PeImageClass (Filename)\r
87 if ImageObj.SectionAlignment < 0x400:\r
88 self.Alignment = str (ImageObj.SectionAlignment)\r
e921f58d 89 elif ImageObj.SectionAlignment < 0x100000:\r
9053bc51 90 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
e921f58d
YZ
91 else:\r
92 self.Alignment = str (ImageObj.SectionAlignment / 0x100000) + 'M'\r
9053bc51 93\r
30fdf114 94 NoStrip = True\r
91fa33ee 95 if self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32):\r
4231a819 96 if self.KeepReloc is not None:\r
30fdf114
LG
97 NoStrip = self.KeepReloc\r
98\r
99 if not NoStrip:\r
100 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
101 if not os.path.exists(FileBeforeStrip) or \\r
102 (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):\r
1be2ed90 103 CopyLongFilePath(self.SectFileName, FileBeforeStrip)\r
30fdf114
LG
104 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
105 GenFdsGlobalVariable.GenerateFirmwareImage(\r
37de70b7
YZ
106 StrippedFile,\r
107 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
108 Strip=True,\r
109 IsMakefile = IsMakefile\r
110 )\r
30fdf114
LG
111 self.SectFileName = StrippedFile\r
112\r
91fa33ee 113 if self.SecType == BINARY_FILE_TYPE_TE:\r
30fdf114
LG
114 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
115 GenFdsGlobalVariable.GenerateFirmwareImage(\r
37de70b7
YZ
116 TeFile,\r
117 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
118 Type='te',\r
119 IsMakefile = IsMakefile\r
120 )\r
30fdf114
LG
121 self.SectFileName = TeFile\r
122\r
8bb63e37 123 OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get(self.SecType))\r
30fdf114 124 OutputFile = os.path.normpath(OutputFile)\r
37de70b7 125 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile)\r
30fdf114
LG
126 FileList = [OutputFile]\r
127 return FileList, self.Alignment\r