2 # process FV image section generation
4 # Copyright (c) 2007 - 2016, 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 *
28 ## generate FV image section
31 class FvImageSection(FvImageSectionClassObject
):
35 # @param self The object pointer
38 FvImageSectionClassObject
.__init
__(self
)
40 ## GenSection() method
42 # Generate FV image section
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)
53 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, KeyStringList
, FfsInf
= None, Dict
= {}):
56 if self
.FvFileType
!= None:
57 FileList
, IsSect
= Section
.Section
.GetFileList(FfsInf
, self
.FvFileType
, self
.FvFileExtension
)
59 return FileList
, self
.Alignment
64 for FvFileName
in FileList
:
66 if os
.path
.isfile(FvFileName
):
67 FvFileObj
= open (FvFileName
,'r+b')
69 # PI FvHeader is 0x48 byte
70 FvHeaderBuffer
= FvFileObj
.read(0x48)
71 # FV alignment position.
72 FvAlignmentValue
= 1 << (ord (FvHeaderBuffer
[0x2E]) & 0x1F)
74 if FvAlignmentValue
> MaxFvAlignment
:
75 MaxFvAlignment
= FvAlignmentValue
77 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ 'SEC' + Num
+ Ffs
.SectionSuffix
.get("FV_IMAGE"))
78 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [FvFileName
], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')
79 OutputFileList
.append(OutputFile
)
81 # MaxFvAlignment is larger than or equal to 1K
82 if MaxFvAlignment
>= 0x400:
83 if MaxFvAlignment
>= 0x10000:
84 #The max alignment supported by FFS is 64K.
85 self
.Alignment
= "64K"
87 self
.Alignment
= str (MaxFvAlignment
/ 0x400) + "K"
89 # MaxFvAlignment is less than 1K
90 self
.Alignment
= str (MaxFvAlignment
)
92 return OutputFileList
, self
.Alignment
96 if self
.FvName
!= None:
97 Buffer
= StringIO
.StringIO('')
98 Fv
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(self
.FvName
)
101 FvFileName
= Fv
.AddToBuffer(Buffer
, self
.FvAddr
, MacroDict
= Dict
)
102 if Fv
.FvAlignment
!= None:
103 if self
.Alignment
== None:
104 self
.Alignment
= Fv
.FvAlignment
106 if GenFdsGlobalVariable
.GetAlignment (Fv
.FvAlignment
) > GenFdsGlobalVariable
.GetAlignment (self
.Alignment
):
107 self
.Alignment
= Fv
.FvAlignment
109 if self
.FvFileName
!= None:
110 FvFileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FvFileName
)
111 if os
.path
.isfile(FvFileName
):
112 FvFileObj
= open (FvFileName
,'r+b')
114 # PI FvHeader is 0x48 byte
115 FvHeaderBuffer
= FvFileObj
.read(0x48)
116 # FV alignment position.
117 FvAlignmentValue
= 1 << (ord (FvHeaderBuffer
[0x2E]) & 0x1F)
118 # FvAlignmentValue is larger than or equal to 1K
119 if FvAlignmentValue
>= 0x400:
120 if FvAlignmentValue
>= 0x10000:
121 #The max alignment supported by FFS is 64K.
122 self
.Alignment
= "64K"
124 self
.Alignment
= str (FvAlignmentValue
/ 0x400) + "K"
126 # FvAlignmentValue is less than 1K
127 self
.Alignment
= str (FvAlignmentValue
)
130 EdkLogger
.error("GenFds", GENFDS_ERROR
, "FvImageSection Failed! %s NOT found in FDF" % self
.FvName
)
133 # Prepare the parameter of GenSection
135 OutputFile
= os
.path
.join(OutputPath
, ModuleName
+ 'SEC' + SecNum
+ Ffs
.SectionSuffix
.get("FV_IMAGE"))
136 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [FvFileName
], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')
137 OutputFileList
.append(OutputFile
)
139 return OutputFileList
, self
.Alignment