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