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