]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/DataSection.py
ShellPkg: Fix EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL_GUID to match UEFI Shell 2.1 spec
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DataSection.py
CommitLineData
30fdf114
LG
1## @file\r
2# process data section generation\r
3#\r
40d841f6 4# Copyright (c) 2007, 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
22import os\r
23from CommonDataClass.FdfClass import DataSectionClassObject\r
9053bc51 24from Common.Misc import PeImageClass\r
30fdf114
LG
25import shutil\r
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
74 if not os.path.exists(CopyMapFile) or \\r
75 (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)):\r
76 shutil.copyfile(MapFile, CopyMapFile)\r
77\r
9053bc51 78 #Get PE Section alignment when align is set to AUTO\r
79 if self.Alignment == 'Auto' and self.SecType in ('TE', 'PE32'):\r
80 ImageObj = PeImageClass (Filename)\r
81 if ImageObj.SectionAlignment < 0x400:\r
82 self.Alignment = str (ImageObj.SectionAlignment)\r
83 else:\r
84 self.Alignment = str (ImageObj.SectionAlignment / 0x400) + 'K'\r
85\r
30fdf114
LG
86 NoStrip = True\r
87 if self.SecType in ('TE', 'PE32'):\r
88 if self.KeepReloc != None:\r
89 NoStrip = self.KeepReloc\r
90\r
91 if not NoStrip:\r
92 FileBeforeStrip = os.path.join(OutputPath, ModuleName + '.efi')\r
93 if not os.path.exists(FileBeforeStrip) or \\r
94 (os.path.getmtime(self.SectFileName) > os.path.getmtime(FileBeforeStrip)):\r
95 shutil.copyfile(self.SectFileName, FileBeforeStrip)\r
96 StrippedFile = os.path.join(OutputPath, ModuleName + '.stripped')\r
97 GenFdsGlobalVariable.GenerateFirmwareImage(\r
98 StrippedFile,\r
99 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
100 Strip=True\r
101 )\r
102 self.SectFileName = StrippedFile\r
103\r
104 if self.SecType == 'TE':\r
105 TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
106 GenFdsGlobalVariable.GenerateFirmwareImage(\r
107 TeFile,\r
108 [GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict)],\r
109 Type='te'\r
110 )\r
111 self.SectFileName = TeFile\r
112\r
113 OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get(self.SecType))\r
114 OutputFile = os.path.normpath(OutputFile)\r
115\r
116 GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType))\r
117 FileList = [OutputFile]\r
118 return FileList, self.Alignment\r