]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/GenFds/FvImageSection.py
BaseTools: Adjust the spaces around commas and colons
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FvImageSection.py
... / ...
CommitLineData
1## @file\r
2# process FV image 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
18import Section\r
19import StringIO\r
20from Ffs import Ffs\r
21import subprocess\r
22from GenFdsGlobalVariable import GenFdsGlobalVariable\r
23import Common.LongFilePathOs as os\r
24from CommonDataClass.FdfClass import FvImageSectionClassObject\r
25from Common import EdkLogger\r
26from Common.BuildToolError import *\r
27from Common.DataType import *\r
28\r
29## generate FV image section\r
30#\r
31#\r
32class FvImageSection(FvImageSectionClassObject):\r
33\r
34 ## The constructor\r
35 #\r
36 # @param self The object pointer\r
37 #\r
38 def __init__(self):\r
39 FvImageSectionClassObject.__init__(self)\r
40\r
41 ## GenSection() method\r
42 #\r
43 # Generate FV image section\r
44 #\r
45 # @param self The object pointer\r
46 # @param OutputPath Where to place output file\r
47 # @param ModuleName Which module this section belongs to\r
48 # @param SecNum Index of section\r
49 # @param KeyStringList Filter for inputs of section generation\r
50 # @param FfsInf FfsInfStatement object that contains this section data\r
51 # @param Dict dictionary contains macro and its value\r
52 # @retval tuple (Generated file name, section alignment)\r
53 #\r
54 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):\r
55\r
56 OutputFileList = []\r
57 if self.FvFileType is not None:\r
58 FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FvFileType, self.FvFileExtension)\r
59 if IsSect :\r
60 return FileList, self.Alignment\r
61\r
62 Num = SecNum\r
63\r
64 MaxFvAlignment = 0\r
65 for FvFileName in FileList:\r
66 FvAlignmentValue = 0\r
67 if os.path.isfile(FvFileName):\r
68 FvFileObj = open (FvFileName, 'rb')\r
69 FvFileObj.seek(0)\r
70 # PI FvHeader is 0x48 byte\r
71 FvHeaderBuffer = FvFileObj.read(0x48)\r
72 # FV alignment position.\r
73 FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r
74 FvFileObj.close()\r
75 if FvAlignmentValue > MaxFvAlignment:\r
76 MaxFvAlignment = FvAlignmentValue\r
77\r
78 OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get("FV_IMAGE"))\r
79 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
80 OutputFileList.append(OutputFile)\r
81\r
82 # MaxFvAlignment is larger than or equal to 1K\r
83 if MaxFvAlignment >= 0x400:\r
84 if MaxFvAlignment >= 0x100000:\r
85 #The max alignment supported by FFS is 16M.\r
86 if MaxFvAlignment >= 0x1000000:\r
87 self.Alignment = "16M"\r
88 else:\r
89 self.Alignment = str(MaxFvAlignment / 0x100000) + "M"\r
90 else:\r
91 self.Alignment = str (MaxFvAlignment / 0x400) + "K"\r
92 else:\r
93 # MaxFvAlignment is less than 1K\r
94 self.Alignment = str (MaxFvAlignment)\r
95\r
96 return OutputFileList, self.Alignment\r
97 #\r
98 # Generate Fv\r
99 #\r
100 if self.FvName is not None:\r
101 Buffer = StringIO.StringIO('')\r
102 Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)\r
103 if Fv is not None:\r
104 self.Fv = Fv\r
105 FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict, Flag=IsMakefile)\r
106 if Fv.FvAlignment is not None:\r
107 if self.Alignment is None:\r
108 self.Alignment = Fv.FvAlignment\r
109 else:\r
110 if GenFdsGlobalVariable.GetAlignment (Fv.FvAlignment) > GenFdsGlobalVariable.GetAlignment (self.Alignment):\r
111 self.Alignment = Fv.FvAlignment\r
112 else:\r
113 if self.FvFileName is not None:\r
114 FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)\r
115 if os.path.isfile(FvFileName):\r
116 FvFileObj = open (FvFileName, 'rb')\r
117 FvFileObj.seek(0)\r
118 # PI FvHeader is 0x48 byte\r
119 FvHeaderBuffer = FvFileObj.read(0x48)\r
120 # FV alignment position.\r
121 FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r
122 # FvAlignmentValue is larger than or equal to 1K\r
123 if FvAlignmentValue >= 0x400:\r
124 if FvAlignmentValue >= 0x100000:\r
125 #The max alignment supported by FFS is 16M.\r
126 if FvAlignmentValue >= 0x1000000:\r
127 self.Alignment = "16M"\r
128 else:\r
129 self.Alignment = str(FvAlignmentValue / 0x100000) + "M"\r
130 else:\r
131 self.Alignment = str (FvAlignmentValue / 0x400) + "K"\r
132 else:\r
133 # FvAlignmentValue is less than 1K\r
134 self.Alignment = str (FvAlignmentValue)\r
135 FvFileObj.close()\r
136 else:\r
137 if len (mws.getPkgPath()) == 0:\r
138 EdkLogger.error("GenFds", FILE_NOT_FOUND, "%s is not found in WORKSPACE: %s" % self.FvFileName, GenFdsGlobalVariable.WorkSpaceDir)\r
139 else:\r
140 EdkLogger.error("GenFds", FILE_NOT_FOUND, "%s is not found in packages path:\n\t%s" % (self.FvFileName, '\n\t'.join(mws.getPkgPath())))\r
141\r
142 else:\r
143 EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName)\r
144\r
145 #\r
146 # Prepare the parameter of GenSection\r
147 #\r
148 OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r
149 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
150 OutputFileList.append(OutputFile)\r
151\r
152 return OutputFileList, self.Alignment\r