]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/FfsFileStatement.py
Sync BaseTool trunk (version r2599) into EDKII BaseTools.
[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
40d841f6 4# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
30fdf114 5#\r
40d841f6 6# This program and the accompanying materials\r
30fdf114
LG
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
30fdf114
LG
20import os\r
21import StringIO\r
22import subprocess\r
52302d4d
LG
23\r
24from GenFdsGlobalVariable import GenFdsGlobalVariable\r
30fdf114
LG
25from CommonDataClass.FdfClass import FileStatementClassObject\r
26from Common import EdkLogger\r
27from Common.BuildToolError import *\r
28from Common.Misc import GuidStructureByteArrayToGuidString\r
52302d4d
LG
29from GuidSection import GuidSection\r
30from FvImageSection import FvImageSection\r
30fdf114
LG
31\r
32## generate FFS from FILE\r
33#\r
34#\r
35class FileStatement (FileStatementClassObject) :\r
36 ## The constructor\r
37 #\r
38 # @param self The object pointer\r
39 #\r
40 def __init__(self):\r
41 FileStatementClassObject.__init__(self)\r
79b74a03
LG
42 self.CurrentLineNum = None\r
43 self.CurrentLineContent = None\r
44 self.FileName = None\r
45 self.InfFileName = None\r
30fdf114
LG
46\r
47 ## GenFfs() method\r
48 #\r
49 # Generate FFS\r
50 #\r
52302d4d
LG
51 # @param self The object pointer\r
52 # @param Dict dictionary contains macro and value pair\r
53 # @param FvChildAddr Array of the inside FvImage base address\r
54 # @param FvParentAddr Parent Fv base address\r
55 # @retval string Generated FFS file name\r
30fdf114 56 #\r
52302d4d 57 def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None):\r
30fdf114
LG
58 \r
59 if self.NameGuid != None and self.NameGuid.startswith('PCD('):\r
60 PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)\r
61 if len(PcdValue) == 0:\r
62 EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \\r
63 % (self.NameGuid))\r
64 if PcdValue.startswith('{'):\r
65 PcdValue = GuidStructureByteArrayToGuidString(PcdValue)\r
66 RegistryGuidStr = PcdValue\r
67 if len(RegistryGuidStr) == 0:\r
68 EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \\r
69 % (self.NameGuid))\r
70 self.NameGuid = RegistryGuidStr\r
71 \r
72 OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid)\r
73 if not os.path.exists(OutputDir):\r
0d2711a6 74 os.makedirs(OutputDir)\r
30fdf114
LG
75\r
76 Dict.update(self.DefineVarDict)\r
77 SectionAlignments = None\r
78 if self.FvName != None :\r
79 Buffer = StringIO.StringIO('')\r
80 if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
81 EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName))\r
82 Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper())\r
83 FileName = Fv.AddToBuffer(Buffer)\r
84 SectionFiles = [FileName]\r
85\r
86 elif self.FdName != None:\r
87 if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
88 EdkLogger.error("GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName))\r
89 Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper())\r
fd171542 90 FileName = Fd.GenFd()\r
30fdf114
LG
91 SectionFiles = [FileName]\r
92\r
93 elif self.FileName != None:\r
94 self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)\r
95 SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)]\r
96\r
97 else:\r
98 SectionFiles = []\r
99 Index = 0\r
100 SectionAlignments = []\r
0d2711a6 101 for section in self.SectionList :\r
30fdf114
LG
102 Index = Index + 1\r
103 SecIndex = '%d' %Index\r
52302d4d
LG
104 # process the inside FvImage from FvSection or GuidSection\r
105 if FvChildAddr != []:\r
106 if isinstance(section, FvImageSection):\r
107 section.FvAddr = FvChildAddr.pop(0)\r
108 elif isinstance(section, GuidSection):\r
109 section.FvAddr = FvChildAddr\r
110 if FvParentAddr != None and isinstance(section, GuidSection):\r
111 section.FvParentAddr = FvParentAddr\r
112\r
4afd3d04
LG
113 if self.KeepReloc == False:\r
114 section.KeepReloc = False\r
30fdf114
LG
115 sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)\r
116 if sectList != []:\r
117 for sect in sectList:\r
118 SectionFiles.append(sect)\r
119 SectionAlignments.append(align)\r
120\r
121 #\r
122 # Prepare the parameter\r
123 #\r
124 FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')\r
125 GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,\r
126 Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),\r
127 self.NameGuid,\r
128 Fixed=self.Fixed,\r
129 CheckSum=self.CheckSum,\r
130 Align=self.Alignment,\r
131 SectionAlign=SectionAlignments\r
132 )\r
133\r
134 return FfsFileOutput\r
135\r
136\r
137\r