GenFds Tool: Add FdfClassObject.
[people/mcb30/basetools.git] / Source / Python / GenFds / EfiSection.py
1 import Section\r
2 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
3 import subprocess\r
4 from Ffs import Ffs\r
5 import os\r
6 from CommonDataClass.FdfClassObject import EfiSectionClassObject\r
7 \r
8 class EfiSection (EfiSectionClassObject):\r
9     \r
10     def __init__(self):\r
11 ##        self.Alignment = None\r
12 ##        self.SectionType = None\r
13 ##        self.Optional = False\r
14 ##        # store file name composed of MACROs\r
15 ##        # Currently only support the String after UI section\r
16 ##        self.Filename = None\r
17 ##        self.BuildNum = None\r
18 ##        self.VersionNum = None\r
19           EfiSectionClassObject.__init__(self)\r
20 \r
21     def GenSection(self, OutputPath, ModuleName, KeyStringList, FfsInf = None) :\r
22         #\r
23         # Prepare the parameter of GenSection\r
24         #\r
25         if FfsInf != None :\r
26             InfFileName = FfsInf.InfFileName\r
27             SectionType = FfsInf.__ExtendMarco__(self.SectionType)\r
28             #print 'File Name : %s' %self.Filename\r
29             Filename = FfsInf.__ExtendMarco__(self.Filename)\r
30             #print 'After Extend File Name: %s' %self.Filename\r
31             #print 'Buile Num: %s' %self.BuildNum\r
32             BuildNum = FfsInf.__ExtendMarco__(self.BuildNum)\r
33             #print 'After extend Build Num: %s' %self.BuildNum\r
34             #print 'version Num: %s' %self.VersionNum\r
35             VersionNum = FfsInf.__ExtendMarco__(self.VersionNum)\r
36             #print 'After extend Version Num: %s' %self.VersionNum\r
37         else:\r
38             SectionType = self.SectionType\r
39             Filename = self.Filename\r
40             BuildNum = self.BuildNum\r
41             VerstionNum = self.VersionNum\r
42             InfFileName = ''\r
43             \r
44         if self.Optional == True :\r
45             if Filename == None or Filename =='':\r
46                 print "Optional Section don't exist!"\r
47                 return '', None\r
48             \r
49         OutputFile = os.path.join( OutputPath, ModuleName + Ffs.SectionSuffix.get(SectionType))\r
50         #\r
51         #  If Section type is 'VERSION'\r
52         #\r
53         if SectionType == 'VERSION':\r
54             if Filename != None:\r
55                 VerString = ' -n '           + \\r
56                              ' \"'           + \\r
57                              Filename        + \\r
58                              ' \"'\r
59             else:\r
60                 VerString = ''\r
61                              \r
62             if BuildNum != None and BuildNum != '':\r
63                 BuildNumString = ' -j ' + \\r
64                                  BuildNum\r
65             else :\r
66                 BuildNumString = ''\r
67             if VerString == '' and BuildNumString == '':\r
68                 if self.Optional == True :\r
69                     print "Optional Section don't exist!"\r
70                     return '', None\r
71                 else:\r
72                     raise Exception ("File: %s miss Version Section value" %InfFileName)\r
73             GenSectionCmd = 'GenSec -o '                + \\r
74                              OutputFile                 + \\r
75                              ' -s EFI_SECTION_VERSION'  + \\r
76                              VerString                  + \\r
77                              BuildNumString\r
78         #\r
79         # If Section Type is 'UI'\r
80         #\r
81         elif SectionType == 'UI':\r
82             #if self.Filename != None :\r
83             #    f = open (self.Filename, 'r')\r
84             #    UiString = f.read ()\r
85             #    f.close()\r
86             #    UiString = ' -n '    + \\r
87             #                '\"'     + \\r
88             #                UiString + \\r
89             #                '\"'\r
90             if Filename != None:\r
91                 UiString = ' -n '        + \\r
92                            '\"'          + \\r
93                            Filename      + \\r
94                            '\"'\r
95             else:\r
96                 UiString = ''\r
97 \r
98             if UiString == '':\r
99                 if self.Optional == True :\r
100                     print "Optional Section don't exist!"\r
101                     return '', None\r
102                 else:\r
103                     raise Exception ("File: %s miss UI Section value" %InfFileName)\r
104                 \r
105             GenSectionCmd = 'GenSec -o '                       + \\r
106                              OutputFile                        + \\r
107                              ' -s EFI_SECTION_USER_INTERFACE'  + \\r
108                              UiString\r
109         else:\r
110              if Filename == None or not os.path.exists(Filename) :\r
111                  if self.Optional == True:\r
112                      print "Optional Section don't exist!"\r
113                      return '', None\r
114                  else:\r
115                      raise Exception(" %s does't exist" %Filename)\r
116              #\r
117              # For TE Section call GenFw to generate TE image\r
118              #\r
119              if SectionType == 'TE':\r
120                  TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw')\r
121                  GenTeCmd = 'GenFW -t '    + \\r
122                             ' -o '         + \\r
123                              TeFile        + \\r
124                              ' '           + \\r
125                              GenFdsGlobalVariable.ExtendMarco(Filename)\r
126                  print GenTeCmd\r
127                  GenFdsGlobalVariable.CallExternalTool(GenTeCmd, "GenFw Failed !")\r
128                  Filename = TeFile\r
129 \r
130                  \r
131              GenSectionCmd = 'GenSec -o '                                     + \\r
132                               OutputFile                                      + \\r
133                               ' -s '                                          + \\r
134                               Section.Section.SectionType.get (SectionType)   + \\r
135                               ' '                                             + \\r
136                               GenFdsGlobalVariable.ExtendMarco(Filename)\r
137         #\r
138         # Call GenSection\r
139         #\r
140         print GenSectionCmd\r
141         GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed !")\r
142         return OutputFile , self.Alignment\r