GenFds Tool: Add FdfClassObject.
[people/mcb30/basetools.git] / Source / Python / GenFds / Vtf.py
1 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
2 import os\r
3 from CommonDataClass.FdfClassObject import VtfClassObject\r
4 T_CHAR_LF = '\n'\r
5 \r
6 class Vtf (VtfClassObject):\r
7     def __init__(self):\r
8 ##        self.KeyArch = None\r
9 ##        self.ArchList = None\r
10 ##        self.UiName = None\r
11 ####        self.OptionStatement = None\r
12 ##        self.ResetBin = None\r
13 ##        self.ComponentStatementList = []\r
14         VtfClassObject.__init__(self)\r
15 \r
16     def GenVtf(self, fdAddDict) :\r
17         self.GenBsfInf()\r
18         OutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.UiName + '.Vtf')\r
19         BaseAddArg = self.GetBaseAddArg(fdAddDict)\r
20         outputArg, VtfRawDict = self.GenOutputArg()\r
21         \r
22         cmd = "GenVtf "        + \\r
23                outputArg       + \\r
24                ' -f '          + \\r
25                self.BsfInfName + \\r
26                ' '             + \\r
27                BaseAddArg      \r
28                \r
29         print cmd\r
30         GenFdsGlobalVariable.CallExternalTool(cmd, "GenFv -Vtf Failed!")\r
31         return VtfRawDict\r
32         \r
33     def GenBsfInf (self):\r
34         fvList = self.GetFvList()\r
35         self.BsfInfName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiName + '.inf')\r
36         BsfInf = open (self.BsfInfName, 'w+')\r
37         BsfInf.writelines ("[COMPONENTS]" + T_CHAR_LF)\r
38 \r
39         for component in self.ComponentStatementList :\r
40             BsfInf.writelines ("COMP_NAME"        + \\r
41                                " = "              + \\r
42                                component.CompName + \\r
43                                T_CHAR_LF )\r
44             if component.CompLoc.upper() == 'NONE' :\r
45                 BsfInf.writelines ("COMP_LOC"        + \\r
46                                    " = "             + \\r
47                                    'N'               + \\r
48                                    T_CHAR_LF )\r
49             else:\r
50                 index = fvList.index(component.CompLoc.upper())\r
51                 if index == 0:\r
52                     BsfInf.writelines ("COMP_LOC"        + \\r
53                                        " = "             + \\r
54                                        'F'               + \\r
55                                        T_CHAR_LF )\r
56                 elif index == 1:\r
57                     BsfInf.writelines ("COMP_LOC"        + \\r
58                                        " = "             + \\r
59                                        'S'                 + \\r
60                                        T_CHAR_LF )\r
61                 \r
62             BsfInf.writelines ("COMP_TYPE"        + \\r
63                                " = "              + \\r
64                                component.CompType + \\r
65                                T_CHAR_LF )\r
66             BsfInf.writelines ("COMP_VER"        + \\r
67                                " = "             + \\r
68                                component.CompVer + \\r
69                                T_CHAR_LF )\r
70             BsfInf.writelines ("COMP_CS"        + \\r
71                                " = "            + \\r
72                                component.CompCs + \\r
73                                T_CHAR_LF )\r
74             BsfInf.writelines ("COMP_BIN"        + \\r
75                                " = "             + \\r
76                                GenFdsGlobalVariable.ReplaceWorkspaceMarco(component.CompBin) + \\r
77                                T_CHAR_LF )\r
78             BsfInf.writelines ("COMP_SYM"        + \\r
79                                " = "             + \\r
80                                GenFdsGlobalVariable.ReplaceWorkspaceMarco(component.CompSym) + \\r
81                                T_CHAR_LF )\r
82             BsfInf.writelines ("COMP_SIZE"        + \\r
83                                " = "              + \\r
84                                component.CompSize + \\r
85                                T_CHAR_LF )\r
86             BsfInf.writelines (T_CHAR_LF )\r
87             \r
88         BsfInf.close()\r
89 \r
90     def GetFvList(self):\r
91         fvList = []\r
92         for component in self.ComponentStatementList :\r
93             if component.CompLoc.upper() != 'NONE' and not (component.CompLoc.upper() in fvList):\r
94                 fvList.append(component.CompLoc.upper())\r
95                 \r
96         return fvList\r
97 \r
98     def GetBaseAddArg(self, fdAddDict):\r
99         fvList = self.GetFvList()\r
100         cmdStr = ''\r
101         for i in fvList:\r
102             (baseAdd, size) = fdAddDict.get(i)\r
103             cmdStr = cmdStr               + \\r
104                      ' -r 0x%x' %baseAdd  + \\r
105                      ' -s 0x%x' %size\r
106         return cmdStr\r
107                      \r
108     def GenOutputArg(self):\r
109         fvVtfDict = {}\r
110         outPutFileName = ''\r
111         fvList = self.GetFvList()\r
112         index = 0\r
113         arg = ''\r
114         for fv in fvList:\r
115             index = index +1\r
116             outputFileName = 'Vtf%d.raw' %index\r
117             outPutFileName = os.path.join(GenFdsGlobalVariable.FvDir, outputFileName)\r
118             arg = arg    + \\r
119                   ' -o ' + \\r
120                   outPutFileName\r
121             fvVtfDict[fv.upper()] = outPutFileName\r
122             \r
123         return arg, fvVtfDict\r
124                 \r