]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/FfsFileStatement.py
License header updated to match correct format.
[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
1be2ed90 4# Copyright (c) 2007 - 2014, 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
1be2ed90 20import Common.LongFilePathOs as os\r
30fdf114
LG
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
97fa0ee9
YL
95 #Replace $(SAPCE) with real space\r
96 self.FileName = self.FileName.replace('$(SPACE)', ' ')\r
30fdf114
LG
97 SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)]\r
98\r
99 else:\r
100 SectionFiles = []\r
101 Index = 0\r
102 SectionAlignments = []\r
0d2711a6 103 for section in self.SectionList :\r
30fdf114
LG
104 Index = Index + 1\r
105 SecIndex = '%d' %Index\r
52302d4d
LG
106 # process the inside FvImage from FvSection or GuidSection\r
107 if FvChildAddr != []:\r
108 if isinstance(section, FvImageSection):\r
109 section.FvAddr = FvChildAddr.pop(0)\r
110 elif isinstance(section, GuidSection):\r
111 section.FvAddr = FvChildAddr\r
112 if FvParentAddr != None and isinstance(section, GuidSection):\r
113 section.FvParentAddr = FvParentAddr\r
114\r
4afd3d04
LG
115 if self.KeepReloc == False:\r
116 section.KeepReloc = False\r
30fdf114
LG
117 sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)\r
118 if sectList != []:\r
119 for sect in sectList:\r
120 SectionFiles.append(sect)\r
121 SectionAlignments.append(align)\r
122\r
123 #\r
124 # Prepare the parameter\r
125 #\r
126 FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')\r
127 GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,\r
128 Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),\r
129 self.NameGuid,\r
130 Fixed=self.Fixed,\r
131 CheckSum=self.CheckSum,\r
132 Align=self.Alignment,\r
133 SectionAlign=SectionAlignments\r
134 )\r
135\r
136 return FfsFileOutput\r
137\r
138\r
139\r