]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/FfsFileStatement.py
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FfsFileStatement.py
1 ## @file
2 # process FFS generation from FILE statement
3 #
4 # Copyright (c) 2007, Intel Corporation
5 #
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
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 from GenFdsGlobalVariable import GenFdsGlobalVariable
21 import os
22 import StringIO
23 import subprocess
24 from CommonDataClass.FdfClass import FileStatementClassObject
25 from Common import EdkLogger
26 from Common.BuildToolError import *
27 from Common.Misc import GuidStructureByteArrayToGuidString
28
29 ## generate FFS from FILE
30 #
31 #
32 class FileStatement (FileStatementClassObject) :
33 ## The constructor
34 #
35 # @param self The object pointer
36 #
37 def __init__(self):
38 FileStatementClassObject.__init__(self)
39
40 ## GenFfs() method
41 #
42 # Generate FFS
43 #
44 # @param self The object pointer
45 # @param Dict dictionary contains macro and value pair
46 # @retval string Generated FFS file name
47 #
48 def GenFfs(self, Dict = {}):
49
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.' \
54 % (self.NameGuid))
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.' \
60 % (self.NameGuid))
61 self.NameGuid = RegistryGuidStr
62
63 OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid)
64 if not os.path.exists(OutputDir):
65 os.makedirs(OutputDir)
66
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]
76
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())
81 FvBin = {}
82 FileName = Fd.GenFd(FvBin)
83 SectionFiles = [FileName]
84
85 elif self.FileName != None:
86 self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
87 SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)]
88
89 else:
90 SectionFiles = []
91 Index = 0
92 SectionAlignments = []
93 for section in self.SectionList :
94 Index = Index + 1
95 SecIndex = '%d' %Index
96 sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)
97 if sectList != []:
98 for sect in sectList:
99 SectionFiles.append(sect)
100 SectionAlignments.append(align)
101
102 #
103 # Prepare the parameter
104 #
105 FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')
106 GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,
107 Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),
108 self.NameGuid,
109 Fixed=self.Fixed,
110 CheckSum=self.CheckSum,
111 Align=self.Alignment,
112 SectionAlign=SectionAlignments
113 )
114
115 return FfsFileOutput
116
117
118