]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # process FFS generation from FILE statement\r | |
3 | #\r | |
860992ed | 4 | # Copyright (c) 2007 - 2016, 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 | |
1be2ed90 | 20 | import Common.LongFilePathOs as os\r |
30fdf114 LG |
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 | |
860992ed YZ |
31 | from Common.Misc import SaveFileOnChange\r |
32 | from struct import *\r | |
30fdf114 LG |
33 | \r |
34 | ## generate FFS from FILE\r | |
35 | #\r | |
36 | #\r | |
37 | class FileStatement (FileStatementClassObject) :\r | |
38 | ## The constructor\r | |
39 | #\r | |
40 | # @param self The object pointer\r | |
41 | #\r | |
42 | def __init__(self):\r | |
43 | FileStatementClassObject.__init__(self)\r | |
79b74a03 LG |
44 | self.CurrentLineNum = None\r |
45 | self.CurrentLineContent = None\r | |
46 | self.FileName = None\r | |
47 | self.InfFileName = None\r | |
30fdf114 LG |
48 | \r |
49 | ## GenFfs() method\r | |
50 | #\r | |
51 | # Generate FFS\r | |
52 | #\r | |
52302d4d LG |
53 | # @param self The object pointer\r |
54 | # @param Dict dictionary contains macro and value pair\r | |
55 | # @param FvChildAddr Array of the inside FvImage base address\r | |
56 | # @param FvParentAddr Parent Fv base address\r | |
57 | # @retval string Generated FFS file name\r | |
30fdf114 | 58 | #\r |
52302d4d | 59 | def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None):\r |
30fdf114 LG |
60 | \r |
61 | if self.NameGuid != None and self.NameGuid.startswith('PCD('):\r | |
62 | PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)\r | |
63 | if len(PcdValue) == 0:\r | |
64 | EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \\r | |
65 | % (self.NameGuid))\r | |
66 | if PcdValue.startswith('{'):\r | |
67 | PcdValue = GuidStructureByteArrayToGuidString(PcdValue)\r | |
68 | RegistryGuidStr = PcdValue\r | |
69 | if len(RegistryGuidStr) == 0:\r | |
70 | EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in wrong format.' \\r | |
71 | % (self.NameGuid))\r | |
72 | self.NameGuid = RegistryGuidStr\r | |
73 | \r | |
74 | OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid)\r | |
75 | if not os.path.exists(OutputDir):\r | |
0d2711a6 | 76 | os.makedirs(OutputDir)\r |
30fdf114 LG |
77 | \r |
78 | Dict.update(self.DefineVarDict)\r | |
79 | SectionAlignments = None\r | |
80 | if self.FvName != None :\r | |
81 | Buffer = StringIO.StringIO('')\r | |
82 | if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r | |
83 | EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName))\r | |
84 | Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper())\r | |
85 | FileName = Fv.AddToBuffer(Buffer)\r | |
86 | SectionFiles = [FileName]\r | |
87 | \r | |
88 | elif self.FdName != None:\r | |
89 | if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r | |
90 | EdkLogger.error("GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName))\r | |
91 | Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper())\r | |
fd171542 | 92 | FileName = Fd.GenFd()\r |
30fdf114 LG |
93 | SectionFiles = [FileName]\r |
94 | \r | |
95 | elif self.FileName != None:\r | |
860992ed YZ |
96 | if hasattr(self, 'FvFileType') and self.FvFileType == 'RAW':\r |
97 | if isinstance(self.FileName, list) and isinstance(self.Alignment, list) and len(self.FileName) == len(self.Alignment):\r | |
98 | FileContent = ''\r | |
99 | for Index, File in enumerate(self.FileName):\r | |
100 | try:\r | |
101 | f = open(File, 'r+b')\r | |
102 | except:\r | |
103 | GenFdsGlobalVariable.ErrorLogger("Error opening RAW file %s." % (File))\r | |
104 | Content = f.read()\r | |
105 | f.close()\r | |
106 | AlignValue = self.Alignment[Index]\r | |
107 | if AlignValue == None:\r | |
108 | AlignValue = 1\r | |
109 | FileContent += Content\r | |
110 | if len(FileContent) % AlignValue != 0:\r | |
111 | Size = AlignValue - len(FileContent) % AlignValue\r | |
112 | for i in range(0, Size):\r | |
113 | FileContent += pack('B', 0xFF)\r | |
114 | \r | |
115 | if FileContent:\r | |
116 | OutputRAWFile = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid, self.NameGuid + '.raw')\r | |
117 | SaveFileOnChange(OutputRAWFile, FileContent, True)\r | |
118 | self.FileName = OutputRAWFile\r | |
119 | if max(self.Alignment):\r | |
120 | self.Alignment = str(max(self.Alignment))\r | |
121 | else:\r | |
122 | self.Alignment = None\r | |
30fdf114 | 123 | self.FileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName)\r |
97fa0ee9 YL |
124 | #Replace $(SAPCE) with real space\r |
125 | self.FileName = self.FileName.replace('$(SPACE)', ' ')\r | |
30fdf114 LG |
126 | SectionFiles = [GenFdsGlobalVariable.MacroExtend(self.FileName, Dict)]\r |
127 | \r | |
128 | else:\r | |
129 | SectionFiles = []\r | |
130 | Index = 0\r | |
131 | SectionAlignments = []\r | |
0d2711a6 | 132 | for section in self.SectionList :\r |
30fdf114 LG |
133 | Index = Index + 1\r |
134 | SecIndex = '%d' %Index\r | |
52302d4d LG |
135 | # process the inside FvImage from FvSection or GuidSection\r |
136 | if FvChildAddr != []:\r | |
137 | if isinstance(section, FvImageSection):\r | |
138 | section.FvAddr = FvChildAddr.pop(0)\r | |
139 | elif isinstance(section, GuidSection):\r | |
140 | section.FvAddr = FvChildAddr\r | |
141 | if FvParentAddr != None and isinstance(section, GuidSection):\r | |
142 | section.FvParentAddr = FvParentAddr\r | |
143 | \r | |
4afd3d04 LG |
144 | if self.KeepReloc == False:\r |
145 | section.KeepReloc = False\r | |
30fdf114 LG |
146 | sectList, align = section.GenSection(OutputDir, self.NameGuid, SecIndex, self.KeyStringList, None, Dict)\r |
147 | if sectList != []:\r | |
148 | for sect in sectList:\r | |
149 | SectionFiles.append(sect)\r | |
150 | SectionAlignments.append(align)\r | |
151 | \r | |
152 | #\r | |
153 | # Prepare the parameter\r | |
154 | #\r | |
155 | FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')\r | |
156 | GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,\r | |
157 | Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),\r | |
158 | self.NameGuid,\r | |
159 | Fixed=self.Fixed,\r | |
160 | CheckSum=self.CheckSum,\r | |
161 | Align=self.Alignment,\r | |
162 | SectionAlign=SectionAlignments\r | |
163 | )\r | |
164 | \r | |
165 | return FfsFileOutput\r | |
166 | \r | |
167 | \r | |
168 | \r |