GenFds Tool: Add FdfClassObject.
[people/mcb30/basetools.git] / Source / Python / GenFds / Capsule.py
1 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
2 from CommonDataClass.FdfClassObject import CapsuleClassObject\r
3 import os\r
4 import subprocess\r
5 \r
6 T_CHAR_LF = '\n'\r
7 class Capsule (CapsuleClassObject) :\r
8     def __init__(self):\r
9 ##        self.SpecName = None\r
10 ##        self.UiCapsuleName = None\r
11 ##        self.CreateFile = None\r
12 ##        self.GroupIdNumber = None\r
13 ###        self.DefineStatementList = None\r
14 ###        self.SetSatementList = None\r
15 ##        # DefineVarDict[var] = value\r
16 ##        self.DefineVarDict = {}\r
17 ##        # SetVarDict[var] = value\r
18 ##        self.SetVarDict = {}\r
19 ##        # TokensDict[var] = value\r
20 ##        self.TokensDict = {}\r
21 ##        self.CapsuleDataList = []\r
22         CapsuleClassObject.__init__(self)\r
23         self.BlockSize = None          # For GenFv\r
24         self.BlockNum = None           # For GenFv\r
25         \r
26     def GenCapsule(self):\r
27         capInfFile = self.GenCapInf()\r
28         capInfFile.writelines("[files]" + T_CHAR_LF)\r
29         \r
30         for file in self.CapsuleDataList :\r
31             fileName = file.GenCapsuleSubItem()\r
32             capInfFile.writelines("EFI_FILE_NAME = " + \\r
33                                    fileName      + \\r
34                                    T_CHAR_LF)\r
35         capInfFile.close()\r
36         #\r
37         # Call GenFv tool to generate capsule\r
38         #\r
39         CapOutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.UiCapsuleName)\r
40         CapOutputFile = CapOutputFile + '.Cap'\r
41         cmd = 'GenFv -i '          + \\r
42                self.CapInfFileName + \\r
43                ' -o '              + \\r
44                CapOutputFile       + \\r
45                ' -c '\r
46         print cmd\r
47         GenFdsGlobalVariable.CallExternalTool(cmd, "GefFv GenCapsule Failed!")\r
48 \r
49 ##\r
50 ##    def GenFvInf():\r
51 ##        self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir,\r
52 ##                                   self.UiFvName + '.inf')\r
53 ##        FvInfFile = open (self.InfFileName, 'w+')\r
54 ##\r
55 ##        self.FvInfFile.writelines("[options]" + T_CHAR_LF)\r
56 ##        if self.BlockSize != None and self.BlockNum != None:\r
57 ##            self.FvInfFile.writelines("EFI_BLOCK_SIZE = " + \\r
58 ##                                      '0x%x' %self.BlockSize    + \\r
59 ##                                      T_CHAR_LF)\r
60 ##            self.FvInfFile.writelines("EFI_NUM_BLOCKS   = "  + \\r
61 ##                                      ' 0x%x' %self.BlockNum    + \\r
62 ##                                      T_CHAR_LF)\r
63 ##\r
64 ##        self.FvInfFile.writelines("[attributes]" + T_CHAR_LF)\r
65 ##        return FvInfFile\r
66         \r
67     def GenCapInf(self):\r
68         self.CapInfFileName = os.path.join(GenFdsGlobalVariable.FvDir,\r
69                                    self.UiCapsuleName +  "_Cap" + '.inf')\r
70         capInfFile = open (self.CapInfFileName , 'w+')\r
71         \r
72         capInfFile.writelines("[options]" + T_CHAR_LF)\r
73         capInfFile.writelines("EFI_CAPSULE_VERSION = " + \\r
74                               self.SpecName            + \\r
75                               T_CHAR_LF)\r
76                               \r
77         for item in self.TokensDict.keys():\r
78             capInfFile.writelines("EFI_"                    + \\r
79                                   item                      + \\r
80                                   ' = '                     + \\r
81                                   self.TokensDict.get(item) + \\r
82                                   T_CHAR_LF)\r
83 \r
84         return capInfFile\r