]> git.proxmox.com Git - mirror_edk2.git/blame - 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
CommitLineData
30fdf114
LG
1## @file\r
2# process FFS generation from FILE statement\r
3#\r
4# Copyright (c) 2007, Intel Corporation\r
5#\r
6# All rights reserved. This program and the accompanying materials\r
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15##\r
16# Import Modules\r
17#\r
18import Ffs\r
19import Rule\r
20from GenFdsGlobalVariable import GenFdsGlobalVariable\r
21import os\r
22import StringIO\r
23import subprocess\r
24from CommonDataClass.FdfClass import FileStatementClassObject\r
25from Common import EdkLogger\r
26from Common.BuildToolError import *\r
27from Common.Misc import GuidStructureByteArrayToGuidString\r
28\r
29## generate FFS from FILE\r
30#\r
31#\r
32class FileStatement (FileStatementClassObject) :\r
33 ## The constructor\r
34 #\r
35 # @param self The object pointer\r
36 #\r
37 def __init__(self):\r
38 FileStatementClassObject.__init__(self)\r
39\r
40 ## GenFfs() method\r
41 #\r
42 # Generate FFS\r
43 #\r
44 # @param self The object pointer\r
45 # @param Dict dictionary contains macro and value pair\r
46 # @retval string Generated FFS file name\r
47 #\r
48 def GenFfs(self, Dict = {}):\r
49 \r
50 if self.NameGuid != None and self.NameGuid.startswith('PCD('):\r
51 PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)\r
52 if len(PcdValue) == 0:\r
53 EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \\r
54 % (self.NameGuid))\r
55 if PcdValue.startswith('{'):\r
56 PcdValue = GuidStructureByteArrayToGuidString(PcdValue)\r
57 RegistryGuidStr = PcdValue\r
58 if len(RegistryGuidStr) == 0:\r
59 EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \\r
60 % (self.NameGuid))\r
61 self.NameGuid = RegistryGuidStr\r
62 \r
63 OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid)\r
64 if not os.path.exists(OutputDir):\r
65 os.makedirs(OutputDir)\r
66\r
67 Dict.update(self.DefineVarDict)\r
68 SectionAlignments = None\r
69 if self.FvName != None :\r
70 Buffer = StringIO.StringIO('')\r
71 if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
72 EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName))\r
73 Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper())\r
74 FileName = Fv.AddToBuffer(Buffer)\r
75 SectionFiles = [FileName]\r
76\r
77 elif self.FdName != None:\r
78 if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
79 EdkLogger.error("GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName))\r
80 Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper())\r
fd171542 81 FileName = Fd.GenFd()\r
30fdf114
LG
82 SectionFiles = [FileName]\r
83\r
84 elif self.FileName != None:\r
85 self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)\r
86 SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)]\r
87\r
88 else:\r
89 SectionFiles = []\r
90 Index = 0\r
91 SectionAlignments = []\r
92 for section in self.SectionList :\r
93 Index = Index + 1\r
94 SecIndex = '%d' %Index\r
95 sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)\r
96 if sectList != []:\r
97 for sect in sectList:\r
98 SectionFiles.append(sect)\r
99 SectionAlignments.append(align)\r
100\r
101 #\r
102 # Prepare the parameter\r
103 #\r
104 FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')\r
105 GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,\r
106 Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),\r
107 self.NameGuid,\r
108 Fixed=self.Fixed,\r
109 CheckSum=self.CheckSum,\r
110 Align=self.Alignment,\r
111 SectionAlign=SectionAlignments\r
112 )\r
113\r
114 return FfsFileOutput\r
115\r
116\r
117\r