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
)
42 self
.CurrentLineNum
= None
43 self
.CurrentLineContent
= None
45 self
.InfFileName
= None
51 # @param self The object pointer
52 # @param Dict dictionary contains macro and value pair
53 # @param FvChildAddr Array of the inside FvImage base address
54 # @param FvParentAddr Parent Fv base address
55 # @retval string Generated FFS file name
57 def GenFfs(self
, Dict
= {}, FvChildAddr
=[], FvParentAddr
=None):
59 if self
.NameGuid
!= None and self
.NameGuid
.startswith('PCD('):
60 PcdValue
= GenFdsGlobalVariable
.GetPcdValue(self
.NameGuid
)
61 if len(PcdValue
) == 0:
62 EdkLogger
.error("GenFds", GENFDS_ERROR
, '%s NOT defined.' \
64 if PcdValue
.startswith('{'):
65 PcdValue
= GuidStructureByteArrayToGuidString(PcdValue
)
66 RegistryGuidStr
= PcdValue
67 if len(RegistryGuidStr
) == 0:
68 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'GUID value for %s in wrong format.' \
70 self
.NameGuid
= RegistryGuidStr
72 OutputDir
= os
.path
.join(GenFdsGlobalVariable
.FfsDir
, self
.NameGuid
)
73 if not os
.path
.exists(OutputDir
):
74 os
.makedirs(OutputDir
)
76 Dict
.update(self
.DefineVarDict
)
77 SectionAlignments
= None
78 if self
.FvName
!= None :
79 Buffer
= StringIO
.StringIO('')
80 if self
.FvName
.upper() not in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.keys():
81 EdkLogger
.error("GenFds", GENFDS_ERROR
, "FV (%s) is NOT described in FDF file!" % (self
.FvName
))
82 Fv
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(self
.FvName
.upper())
83 FileName
= Fv
.AddToBuffer(Buffer
)
84 SectionFiles
= [FileName
]
86 elif self
.FdName
!= None:
87 if self
.FdName
.upper() not in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.keys():
88 EdkLogger
.error("GenFds", GENFDS_ERROR
, "FD (%s) is NOT described in FDF file!" % (self
.FdName
))
89 Fd
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.get(self
.FdName
.upper())
91 SectionFiles
= [FileName
]
93 elif self
.FileName
!= None:
94 self
.FileName
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FileName
)
95 SectionFiles
= [GenFdsGlobalVariable
.MacroExtend(self
.FileName
, Dict
)]
100 SectionAlignments
= []
101 for section
in self
.SectionList
:
103 SecIndex
= '%d' %Index
104 # process the inside FvImage from FvSection or GuidSection
105 if FvChildAddr
!= []:
106 if isinstance(section
, FvImageSection
):
107 section
.FvAddr
= FvChildAddr
.pop(0)
108 elif isinstance(section
, GuidSection
):
109 section
.FvAddr
= FvChildAddr
110 if FvParentAddr
!= None and isinstance(section
, GuidSection
):
111 section
.FvParentAddr
= FvParentAddr
113 if self
.KeepReloc
== False:
114 section
.KeepReloc
= False
115 sectList
, align
= section
.GenSection(OutputDir
, self
.NameGuid
, SecIndex
, self
.KeyStringList
, None, Dict
)
117 for sect
in sectList
:
118 SectionFiles
.append(sect
)
119 SectionAlignments
.append(align
)
122 # Prepare the parameter
124 FfsFileOutput
= os
.path
.join(OutputDir
, self
.NameGuid
+ '.ffs')
125 GenFdsGlobalVariable
.GenerateFfs(FfsFileOutput
, SectionFiles
,
126 Ffs
.Ffs
.FdfFvFileTypeToFileType
.get(self
.FvFileType
),
129 CheckSum
=self
.CheckSum
,
130 Align
=self
.Alignment
,
131 SectionAlign
=SectionAlignments