]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/FvImageSection.py
BaseTools: use set instead of list for a variable to be used with in
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FvImageSection.py
1 ## @file
2 # process FV image section generation
3 #
4 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 ##
16 # Import Modules
17 #
18 import Section
19 import StringIO
20 from Ffs import Ffs
21 import subprocess
22 from GenFdsGlobalVariable import GenFdsGlobalVariable
23 import Common.LongFilePathOs as os
24 from CommonDataClass.FdfClass import FvImageSectionClassObject
25 from Common import EdkLogger
26 from Common.BuildToolError import *
27
28 ## generate FV image section
29 #
30 #
31 class FvImageSection(FvImageSectionClassObject):
32
33 ## The constructor
34 #
35 # @param self The object pointer
36 #
37 def __init__(self):
38 FvImageSectionClassObject.__init__(self)
39
40 ## GenSection() method
41 #
42 # Generate FV image section
43 #
44 # @param self The object pointer
45 # @param OutputPath Where to place output file
46 # @param ModuleName Which module this section belongs to
47 # @param SecNum Index of section
48 # @param KeyStringList Filter for inputs of section generation
49 # @param FfsInf FfsInfStatement object that contains this section data
50 # @param Dict dictionary contains macro and its value
51 # @retval tuple (Generated file name, section alignment)
52 #
53 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):
54
55 OutputFileList = []
56 if self.FvFileType is not None:
57 FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FvFileType, self.FvFileExtension)
58 if IsSect :
59 return FileList, self.Alignment
60
61 Num = SecNum
62
63 MaxFvAlignment = 0
64 for FvFileName in FileList:
65 FvAlignmentValue = 0
66 if os.path.isfile(FvFileName):
67 FvFileObj = open (FvFileName,'rb')
68 FvFileObj.seek(0)
69 # PI FvHeader is 0x48 byte
70 FvHeaderBuffer = FvFileObj.read(0x48)
71 # FV alignment position.
72 FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)
73 FvFileObj.close()
74 if FvAlignmentValue > MaxFvAlignment:
75 MaxFvAlignment = FvAlignmentValue
76
77 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get("FV_IMAGE"))
78 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)
79 OutputFileList.append(OutputFile)
80
81 # MaxFvAlignment is larger than or equal to 1K
82 if MaxFvAlignment >= 0x400:
83 if MaxFvAlignment >= 0x100000:
84 #The max alignment supported by FFS is 16M.
85 if MaxFvAlignment >=1000000:
86 self.Alignment = "16M"
87 else:
88 self.Alignment = str(MaxFvAlignment / 0x100000) + "M"
89 else:
90 self.Alignment = str (MaxFvAlignment / 0x400) + "K"
91 else:
92 # MaxFvAlignment is less than 1K
93 self.Alignment = str (MaxFvAlignment)
94
95 return OutputFileList, self.Alignment
96 #
97 # Generate Fv
98 #
99 if self.FvName is not None:
100 Buffer = StringIO.StringIO('')
101 Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)
102 if Fv is not None:
103 self.Fv = Fv
104 FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict, Flag=IsMakefile)
105 if Fv.FvAlignment is not None:
106 if self.Alignment is None:
107 self.Alignment = Fv.FvAlignment
108 else:
109 if GenFdsGlobalVariable.GetAlignment (Fv.FvAlignment) > GenFdsGlobalVariable.GetAlignment (self.Alignment):
110 self.Alignment = Fv.FvAlignment
111 else:
112 if self.FvFileName is not None:
113 FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)
114 if os.path.isfile(FvFileName):
115 FvFileObj = open (FvFileName,'rb')
116 FvFileObj.seek(0)
117 # PI FvHeader is 0x48 byte
118 FvHeaderBuffer = FvFileObj.read(0x48)
119 # FV alignment position.
120 FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)
121 # FvAlignmentValue is larger than or equal to 1K
122 if FvAlignmentValue >= 0x400:
123 if FvAlignmentValue >= 0x100000:
124 #The max alignment supported by FFS is 16M.
125 if FvAlignmentValue >= 0x1000000:
126 self.Alignment = "16M"
127 else:
128 self.Alignment = str(FvAlignmentValue / 0x100000) + "M"
129 else:
130 self.Alignment = str (FvAlignmentValue / 0x400) + "K"
131 else:
132 # FvAlignmentValue is less than 1K
133 self.Alignment = str (FvAlignmentValue)
134 FvFileObj.close()
135 else:
136 EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName)
137
138 #
139 # Prepare the parameter of GenSection
140 #
141 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))
142 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)
143 OutputFileList.append(OutputFile)
144
145 return OutputFileList, self.Alignment