2 # process FFS generation from FILE statement
4 # Copyright (c) 2007 - 2010, 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.
24 from GenFdsGlobalVariable
import GenFdsGlobalVariable
25 from CommonDataClass
.FdfClass
import FileStatementClassObject
26 from Common
import EdkLogger
27 from Common
.BuildToolError
import *
28 from Common
.Misc
import GuidStructureByteArrayToGuidString
29 from GuidSection
import GuidSection
30 from FvImageSection
import FvImageSection
32 ## generate FFS from FILE
35 class FileStatement (FileStatementClassObject
) :
38 # @param self The object pointer
41 FileStatementClassObject
.__init
__(self
)
47 # @param self The object pointer
48 # @param Dict dictionary contains macro and value pair
49 # @param FvChildAddr Array of the inside FvImage base address
50 # @param FvParentAddr Parent Fv base address
51 # @retval string Generated FFS file name
53 def GenFfs(self
, Dict
= {}, FvChildAddr
=[], FvParentAddr
=None):
55 if self
.NameGuid
!= None and self
.NameGuid
.startswith('PCD('):
56 PcdValue
= GenFdsGlobalVariable
.GetPcdValue(self
.NameGuid
)
57 if len(PcdValue
) == 0:
58 EdkLogger
.error("GenFds", GENFDS_ERROR
, '%s NOT defined.' \
60 if PcdValue
.startswith('{'):
61 PcdValue
= GuidStructureByteArrayToGuidString(PcdValue
)
62 RegistryGuidStr
= PcdValue
63 if len(RegistryGuidStr
) == 0:
64 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'GUID value for %s in wrong format.' \
66 self
.NameGuid
= RegistryGuidStr
68 OutputDir
= os
.path
.join(GenFdsGlobalVariable
.FfsDir
, self
.NameGuid
)
69 if not os
.path
.exists(OutputDir
):
70 os
.makedirs(OutputDir
)
72 Dict
.update(self
.DefineVarDict
)
73 SectionAlignments
= None
74 if self
.FvName
!= None :
75 Buffer
= StringIO
.StringIO('')
76 if self
.FvName
.upper() not in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.keys():
77 EdkLogger
.error("GenFds", GENFDS_ERROR
, "FV (%s) is NOT described in FDF file!" % (self
.FvName
))
78 Fv
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(self
.FvName
.upper())
79 FileName
= Fv
.AddToBuffer(Buffer
)
80 SectionFiles
= [FileName
]
82 elif self
.FdName
!= None:
83 if self
.FdName
.upper() not in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.keys():
84 EdkLogger
.error("GenFds", GENFDS_ERROR
, "FD (%s) is NOT described in FDF file!" % (self
.FdName
))
85 Fd
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.get(self
.FdName
.upper())
87 SectionFiles
= [FileName
]
89 elif self
.FileName
!= None:
90 self
.FileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FileName
)
91 SectionFiles
= [GenFdsGlobalVariable
.MacroExtend(self
.FileName
, Dict
)]
96 SectionAlignments
= []
97 for section
in self
.SectionList
:
99 SecIndex
= '%d' %Index
100 # process the inside FvImage from FvSection or GuidSection
101 if FvChildAddr
!= []:
102 if isinstance(section
, FvImageSection
):
103 section
.FvAddr
= FvChildAddr
.pop(0)
104 elif isinstance(section
, GuidSection
):
105 section
.FvAddr
= FvChildAddr
106 if FvParentAddr
!= None and isinstance(section
, GuidSection
):
107 section
.FvParentAddr
= FvParentAddr
109 sectList
, align
= section
.GenSection(OutputDir
, self
.NameGuid
, SecIndex
, self
.KeyStringList
, None, Dict
)
111 for sect
in sectList
:
112 SectionFiles
.append(sect
)
113 SectionAlignments
.append(align
)
116 # Prepare the parameter
118 FfsFileOutput
= os
.path
.join(OutputDir
, self
.NameGuid
+ '.ffs')
119 GenFdsGlobalVariable
.GenerateFfs(FfsFileOutput
, SectionFiles
,
120 Ffs
.Ffs
.FdfFvFileTypeToFileType
.get(self
.FvFileType
),
123 CheckSum
=self
.CheckSum
,
124 Align
=self
.Alignment
,
125 SectionAlign
=SectionAlignments