]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/FfsFileStatement.py
Sync basetools' source and binary files with r1707 of the basetools project.
[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 FileName = Fd.GenFd()
82 SectionFiles = [FileName]
83
84 elif self.FileName != None:
85 self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
86 SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)]
87
88 else:
89 SectionFiles = []
90 Index = 0
91 SectionAlignments = []
92 for section in self.SectionList :
93 Index = Index + 1
94 SecIndex = '%d' %Index
95 sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)
96 if sectList != []:
97 for sect in sectList:
98 SectionFiles.append(sect)
99 SectionAlignments.append(align)
100
101 #
102 # Prepare the parameter
103 #
104 FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')
105 GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,
106 Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),
107 self.NameGuid,
108 Fixed=self.Fixed,
109 CheckSum=self.CheckSum,
110 Align=self.Alignment,
111 SectionAlign=SectionAlignments
112 )
113
114 return FfsFileOutput
115
116
117