2 # process FV image section generation
4 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
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
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.
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 from Common
.DataType
import *
29 ## generate FV image section
32 class FvImageSection(FvImageSectionClassObject
):
36 # @param self The object pointer
39 FvImageSectionClassObject
.__init
__(self
)
41 ## GenSection() method
43 # Generate FV image section
45 # @param self The object pointer
46 # @param OutputPath Where to place output file
47 # @param ModuleName Which module this section belongs to
48 # @param SecNum Index of section
49 # @param KeyStringList Filter for inputs of section generation
50 # @param FfsInf FfsInfStatement object that contains this section data
51 # @param Dict dictionary contains macro and its value
52 # @retval tuple (Generated file name, section alignment)
54 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
= None, Dict
= {}, IsMakefile
= False):
57 if self
.FvFileType
is not None:
58 FileList
, IsSect
= Section
.Section
.GetFileList(FfsInf
, self
.FvFileType
, self
.FvFileExtension
)
60 return FileList
, self
.Alignment
65 for FvFileName
in FileList
:
67 if os
.path
.isfile(FvFileName
):
68 FvFileObj
= open (FvFileName
,'rb')
70 # PI FvHeader is 0x48 byte
71 FvHeaderBuffer
= FvFileObj
.read(0x48)
72 # FV alignment position.
73 FvAlignmentValue
= 1 << (ord (FvHeaderBuffer
[0x2E]) & 0x1F)
75 if FvAlignmentValue
> MaxFvAlignment
:
76 MaxFvAlignment
= FvAlignmentValue
78 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ Num
+ Ffs
.SectionSuffix
.get("FV_IMAGE"))
79 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [FvFileName
], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile
=IsMakefile
)
80 OutputFileList
.append(OutputFile
)
82 # MaxFvAlignment is larger than or equal to 1K
83 if MaxFvAlignment
>= 0x400:
84 if MaxFvAlignment
>= 0x100000:
85 #The max alignment supported by FFS is 16M.
86 if MaxFvAlignment
>=1000000:
87 self
.Alignment
= "16M"
89 self
.Alignment
= str(MaxFvAlignment
/ 0x100000) + "M"
91 self
.Alignment
= str (MaxFvAlignment
/ 0x400) + "K"
93 # MaxFvAlignment is less than 1K
94 self
.Alignment
= str (MaxFvAlignment
)
96 return OutputFileList
, self
.Alignment
100 if self
.FvName
is not None:
101 Buffer
= StringIO
.StringIO('')
102 Fv
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(self
.FvName
)
105 FvFileName
= Fv
.AddToBuffer(Buffer
, self
.FvAddr
, MacroDict
= Dict
, Flag
=IsMakefile
)
106 if Fv
.FvAlignment
is not None:
107 if self
.Alignment
is None:
108 self
.Alignment
= Fv
.FvAlignment
110 if GenFdsGlobalVariable
.GetAlignment (Fv
.FvAlignment
) > GenFdsGlobalVariable
.GetAlignment (self
.Alignment
):
111 self
.Alignment
= Fv
.FvAlignment
113 if self
.FvFileName
is not None:
114 FvFileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FvFileName
)
115 if os
.path
.isfile(FvFileName
):
116 FvFileObj
= open (FvFileName
,'rb')
118 # PI FvHeader is 0x48 byte
119 FvHeaderBuffer
= FvFileObj
.read(0x48)
120 # FV alignment position.
121 FvAlignmentValue
= 1 << (ord (FvHeaderBuffer
[0x2E]) & 0x1F)
122 # FvAlignmentValue is larger than or equal to 1K
123 if FvAlignmentValue
>= 0x400:
124 if FvAlignmentValue
>= 0x100000:
125 #The max alignment supported by FFS is 16M.
126 if FvAlignmentValue
>= 0x1000000:
127 self
.Alignment
= "16M"
129 self
.Alignment
= str(FvAlignmentValue
/ 0x100000) + "M"
131 self
.Alignment
= str (FvAlignmentValue
/ 0x400) + "K"
133 # FvAlignmentValue is less than 1K
134 self
.Alignment
= str (FvAlignmentValue
)
137 EdkLogger
.error("GenFds", GENFDS_ERROR
, "FvImageSection Failed! %s NOT found in FDF" % self
.FvName
)
140 # Prepare the parameter of GenSection
142 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ SecNum
+ Ffs
.SectionSuffix
.get("FV_IMAGE"))
143 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [FvFileName
], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile
=IsMakefile
)
144 OutputFileList
.append(OutputFile
)
146 return OutputFileList
, self
.Alignment