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