]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/FvImageSection.py
BaseTools: Fix some build and report file issue
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FvImageSection.py
CommitLineData
30fdf114
LG
1## @file\r
2# process FV image section generation\r
3#\r
1dc287c3 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
bfa65b61 18from . import Section\r
86379ac4 19from io import BytesIO\r
bfa65b61 20from .Ffs import Ffs\r
30fdf114 21import subprocess\r
bfa65b61 22from .GenFdsGlobalVariable import GenFdsGlobalVariable\r
1be2ed90 23import Common.LongFilePathOs as os\r
30fdf114
LG
24from CommonDataClass.FdfClass import FvImageSectionClassObject\r
25from Common import EdkLogger\r
26from Common.BuildToolError import *\r
8bb63e37 27from Common.DataType import *\r
30fdf114
LG
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
37de70b7 54 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):\r
30fdf114
LG
55\r
56 OutputFileList = []\r
4231a819 57 if self.FvFileType is not None:\r
30fdf114
LG
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
321151fe
YZ
64 MaxFvAlignment = 0\r
65 for FvFileName in FileList:\r
66 FvAlignmentValue = 0\r
67 if os.path.isfile(FvFileName):\r
ccaa7754 68 FvFileObj = open (FvFileName, 'rb')\r
321151fe
YZ
69 FvFileObj.seek(0)\r
70 # PI FvHeader is 0x48 byte\r
71 FvHeaderBuffer = FvFileObj.read(0x48)\r
72 # FV alignment position.\r
2e300969 73 FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)\r
321151fe
YZ
74 FvFileObj.close()\r
75 if FvAlignmentValue > MaxFvAlignment:\r
76 MaxFvAlignment = FvAlignmentValue\r
77\r
8bb63e37 78 OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get("FV_IMAGE"))\r
37de70b7 79 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
30fdf114 80 OutputFileList.append(OutputFile)\r
321151fe
YZ
81\r
82 # MaxFvAlignment is larger than or equal to 1K\r
83 if MaxFvAlignment >= 0x400:\r
e921f58d
YZ
84 if MaxFvAlignment >= 0x100000:\r
85 #The max alignment supported by FFS is 16M.\r
1dc287c3 86 if MaxFvAlignment >= 0x1000000:\r
e921f58d
YZ
87 self.Alignment = "16M"\r
88 else:\r
2e300969 89 self.Alignment = str(MaxFvAlignment // 0x100000) + "M"\r
321151fe 90 else:\r
2e300969 91 self.Alignment = str (MaxFvAlignment // 0x400) + "K"\r
321151fe
YZ
92 else:\r
93 # MaxFvAlignment is less than 1K\r
94 self.Alignment = str (MaxFvAlignment)\r
95\r
30fdf114
LG
96 return OutputFileList, self.Alignment\r
97 #\r
98 # Generate Fv\r
99 #\r
4231a819 100 if self.FvName is not None:\r
86e6cf98 101 Buffer = BytesIO()\r
30fdf114 102 Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)\r
4231a819 103 if Fv is not None:\r
30fdf114 104 self.Fv = Fv\r
8be15c61
YF
105 if not self.FvAddr and self.Fv.BaseAddress:\r
106 self.FvAddr = self.Fv.BaseAddress\r
37de70b7 107 FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict, Flag=IsMakefile)\r
4231a819
CJ
108 if Fv.FvAlignment is not None:\r
109 if self.Alignment is None:\r
52302d4d
LG
110 self.Alignment = Fv.FvAlignment\r
111 else:\r
112 if GenFdsGlobalVariable.GetAlignment (Fv.FvAlignment) > GenFdsGlobalVariable.GetAlignment (self.Alignment):\r
113 self.Alignment = Fv.FvAlignment\r
30fdf114 114 else:\r
4231a819 115 if self.FvFileName is not None:\r
30fdf114 116 FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)\r
877c0a93 117 if os.path.isfile(FvFileName):\r
ccaa7754 118 FvFileObj = open (FvFileName, 'rb')\r
877c0a93
YZ
119 FvFileObj.seek(0)\r
120 # PI FvHeader is 0x48 byte\r
121 FvHeaderBuffer = FvFileObj.read(0x48)\r
122 # FV alignment position.\r
86e6cf98 123 FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)\r
877c0a93
YZ
124 # FvAlignmentValue is larger than or equal to 1K\r
125 if FvAlignmentValue >= 0x400:\r
e921f58d
YZ
126 if FvAlignmentValue >= 0x100000:\r
127 #The max alignment supported by FFS is 16M.\r
128 if FvAlignmentValue >= 0x1000000:\r
129 self.Alignment = "16M"\r
130 else:\r
2e300969 131 self.Alignment = str(FvAlignmentValue // 0x100000) + "M"\r
877c0a93 132 else:\r
2e300969 133 self.Alignment = str (FvAlignmentValue // 0x400) + "K"\r
877c0a93
YZ
134 else:\r
135 # FvAlignmentValue is less than 1K\r
136 self.Alignment = str (FvAlignmentValue)\r
137 FvFileObj.close()\r
75135cc6
YZ
138 else:\r
139 if len (mws.getPkgPath()) == 0:\r
140 EdkLogger.error("GenFds", FILE_NOT_FOUND, "%s is not found in WORKSPACE: %s" % self.FvFileName, GenFdsGlobalVariable.WorkSpaceDir)\r
141 else:\r
142 EdkLogger.error("GenFds", FILE_NOT_FOUND, "%s is not found in packages path:\n\t%s" % (self.FvFileName, '\n\t'.join(mws.getPkgPath())))\r
143\r
30fdf114
LG
144 else:\r
145 EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName)\r
146\r
147 #\r
148 # Prepare the parameter of GenSection\r
149 #\r
8bb63e37 150 OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r
37de70b7 151 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
30fdf114
LG
152 OutputFileList.append(OutputFile)\r
153\r
154 return OutputFileList, self.Alignment\r