]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/FfsFileStatement.py
Sync BaseTools Branch (version r2362) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FfsFileStatement.py
1 ## @file
2 # process FFS generation from FILE statement
3 #
4 # Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
5 #
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
10 #
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.
13 #
14
15 ##
16 # Import Modules
17 #
18 import Ffs
19 import Rule
20 import os
21 import StringIO
22 import subprocess
23
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
31
32 ## generate FFS from FILE
33 #
34 #
35 class FileStatement (FileStatementClassObject) :
36 ## The constructor
37 #
38 # @param self The object pointer
39 #
40 def __init__(self):
41 FileStatementClassObject.__init__(self)
42 self.CurrentLineNum = None
43 self.CurrentLineContent = None
44 self.FileName = None
45 self.InfFileName = None
46
47 ## GenFfs() method
48 #
49 # Generate FFS
50 #
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
56 #
57 def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None):
58
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.' \
63 % (self.NameGuid))
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.' \
69 % (self.NameGuid))
70 self.NameGuid = RegistryGuidStr
71
72 OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid)
73 if not os.path.exists(OutputDir):
74 os.makedirs(OutputDir)
75
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]
85
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())
90 FileName = Fd.GenFd()
91 SectionFiles = [FileName]
92
93 elif self.FileName != None:
94 self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
95 SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)]
96
97 else:
98 SectionFiles = []
99 Index = 0
100 SectionAlignments = []
101 for section in self.SectionList:
102 Index = Index + 1
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
112
113 sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)
114 if sectList != []:
115 for sect in sectList:
116 SectionFiles.append(sect)
117 SectionAlignments.append(align)
118
119 #
120 # Prepare the parameter
121 #
122 FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')
123 GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,
124 Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),
125 self.NameGuid,
126 Fixed=self.Fixed,
127 CheckSum=self.CheckSum,
128 Align=self.Alignment,
129 SectionAlign=SectionAlignments
130 )
131
132 return FfsFileOutput
133
134
135