2 # process FFS generation from FILE statement
4 # Copyright (c) 2007, Intel Corporation
6 # All rights reserved. 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.
20 from GenFdsGlobalVariable
import GenFdsGlobalVariable
24 from CommonDataClass
.FdfClass
import FileStatementClassObject
25 from Common
import EdkLogger
26 from Common
.BuildToolError
import *
27 from Common
.Misc
import GuidStructureByteArrayToGuidString
29 ## generate FFS from FILE
32 class FileStatement (FileStatementClassObject
) :
35 # @param self The object pointer
38 FileStatementClassObject
.__init
__(self
)
44 # @param self The object pointer
45 # @param Dict dictionary contains macro and value pair
46 # @retval string Generated FFS file name
48 def GenFfs(self
, Dict
= {}):
50 if self
.NameGuid
!= None and self
.NameGuid
.startswith('PCD('):
51 PcdValue
= GenFdsGlobalVariable
.GetPcdValue(self
.NameGuid
)
52 if len(PcdValue
) == 0:
53 EdkLogger
.error("GenFds", GENFDS_ERROR
, '%s NOT defined.' \
55 if PcdValue
.startswith('{'):
56 PcdValue
= GuidStructureByteArrayToGuidString(PcdValue
)
57 RegistryGuidStr
= PcdValue
58 if len(RegistryGuidStr
) == 0:
59 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'GUID value for %s in wrong format.' \
61 self
.NameGuid
= RegistryGuidStr
63 OutputDir
= os
.path
.join(GenFdsGlobalVariable
.FfsDir
, self
.NameGuid
)
64 if not os
.path
.exists(OutputDir
):
65 os
.makedirs(OutputDir
)
67 Dict
.update(self
.DefineVarDict
)
68 SectionAlignments
= None
69 if self
.FvName
!= None :
70 Buffer
= StringIO
.StringIO('')
71 if self
.FvName
.upper() not in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.keys():
72 EdkLogger
.error("GenFds", GENFDS_ERROR
, "FV (%s) is NOT described in FDF file!" % (self
.FvName
))
73 Fv
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(self
.FvName
.upper())
74 FileName
= Fv
.AddToBuffer(Buffer
)
75 SectionFiles
= [FileName
]
77 elif self
.FdName
!= None:
78 if self
.FdName
.upper() not in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.keys():
79 EdkLogger
.error("GenFds", GENFDS_ERROR
, "FD (%s) is NOT described in FDF file!" % (self
.FdName
))
80 Fd
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.get(self
.FdName
.upper())
82 FileName
= Fd
.GenFd(FvBin
)
83 SectionFiles
= [FileName
]
85 elif self
.FileName
!= None:
86 self
.FileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FileName
)
87 SectionFiles
= [GenFdsGlobalVariable
.MacroExtend(self
.FileName
, Dict
)]
92 SectionAlignments
= []
93 for section
in self
.SectionList
:
95 SecIndex
= '%d' %Index
96 sectList
, align
= section
.GenSection(OutputDir
, self
.NameGuid
, SecIndex
, self
.KeyStringList
, None, Dict
)
99 SectionFiles
.append(sect
)
100 SectionAlignments
.append(align
)
103 # Prepare the parameter
105 FfsFileOutput
= os
.path
.join(OutputDir
, self
.NameGuid
+ '.ffs')
106 GenFdsGlobalVariable
.GenerateFfs(FfsFileOutput
, SectionFiles
,
107 Ffs
.Ffs
.FdfFvFileTypeToFileType
.get(self
.FvFileType
),
110 CheckSum
=self
.CheckSum
,
111 Align
=self
.Alignment
,
112 SectionAlign
=SectionAlignments