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