]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/FfsFileStatement.py
013dbb1f02fb99e335c23fc516847576362de4f1
[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
43 ## GenFfs() method
44 #
45 # Generate FFS
46 #
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
52 #
53 def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None):
54
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.' \
59 % (self.NameGuid))
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.' \
65 % (self.NameGuid))
66 self.NameGuid = RegistryGuidStr
67
68 OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid)
69 if not os.path.exists(OutputDir):
70 os.makedirs(OutputDir)
71
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]
81
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())
86 FileName = Fd.GenFd()
87 SectionFiles = [FileName]
88
89 elif self.FileName != None:
90 self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)
91 SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)]
92
93 else:
94 SectionFiles = []
95 Index = 0
96 SectionAlignments = []
97 for section in self.SectionList :
98 Index = Index + 1
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
108
109 sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)
110 if sectList != []:
111 for sect in sectList:
112 SectionFiles.append(sect)
113 SectionAlignments.append(align)
114
115 #
116 # Prepare the parameter
117 #
118 FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')
119 GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,
120 Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),
121 self.NameGuid,
122 Fixed=self.Fixed,
123 CheckSum=self.CheckSum,
124 Align=self.Alignment,
125 SectionAlign=SectionAlignments
126 )
127
128 return FfsFileOutput
129
130
131