]>
Commit | Line | Data |
---|---|---|
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 | |
18 | import Ffs\r | |
19 | import Rule\r | |
30fdf114 LG |
20 | import os\r |
21 | import StringIO\r | |
22 | import subprocess\r | |
52302d4d LG |
23 | \r |
24 | from GenFdsGlobalVariable import GenFdsGlobalVariable\r | |
30fdf114 LG |
25 | from CommonDataClass.FdfClass import FileStatementClassObject\r |
26 | from Common import EdkLogger\r | |
27 | from Common.BuildToolError import *\r | |
28 | from Common.Misc import GuidStructureByteArrayToGuidString\r | |
52302d4d LG |
29 | from GuidSection import GuidSection\r |
30 | from FvImageSection import FvImageSection\r | |
30fdf114 LG |
31 | \r |
32 | ## generate FFS from FILE\r | |
33 | #\r | |
34 | #\r | |
35 | class 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 | |
30fdf114 LG |
113 | sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)\r |
114 | if sectList != []:\r | |
115 | for sect in sectList:\r | |
116 | SectionFiles.append(sect)\r | |
117 | SectionAlignments.append(align)\r | |
118 | \r | |
119 | #\r | |
120 | # Prepare the parameter\r | |
121 | #\r | |
122 | FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')\r | |
123 | GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,\r | |
124 | Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),\r | |
125 | self.NameGuid,\r | |
126 | Fixed=self.Fixed,\r | |
127 | CheckSum=self.CheckSum,\r | |
128 | Align=self.Alignment,\r | |
129 | SectionAlign=SectionAlignments\r | |
130 | )\r | |
131 | \r | |
132 | return FfsFileOutput\r | |
133 | \r | |
134 | \r | |
135 | \r |