Added from python source root
[people/mcb30/basetools.git] / Source / Python / GenFds / FvImageSection.py
1 import Section\r
2 import StringIO\r
3 from Ffs import Ffs\r
4 import subprocess\r
5 from GenFdsGlobalVariable import GenFdsGlobalVariable\r
6 \r
7 class FvImageSection(Section.Section):\r
8     def __init__(self):\r
9         self.Aligenment = None\r
10         self.Fv = None\r
11         self.FvName = None\r
12     def GenSection(self, OutputPath, ModuleName, KeyStringList, FfsInf = None):\r
13         Buffer = StringIO.StringIO('')\r
14         #\r
15         # Generate Fv\r
16         #\r
17         if self.FvName != None:\r
18             Fv = GenFdsGlobalVariable.FdfParser.profile.FvDict.get(self.FvName)\r
19             if self.Fv == None:\r
20                 self.Fv = Fv\r
21             else:\r
22                 raise Exception("FvImageSection Failed! Can't describe the \\r
23                                  FvImageSection both in FvUiName and \\r
24                                  FvImageArg!")\r
25                                  \r
26         self.Fv.AddToBuffer(Buffer)\r
27         \r
28         FvFileName = OutputPath + \\r
29                      ModuleName + \\r
30                      '.fv'\r
31         FvFile = open ( FvFileName, 'w+')\r
32         FvFile.write(Buffer.getvalue())\r
33         FvFile.close()\r
34         #\r
35         # Prepare the parameter of GenSection\r
36         #\r
37         OutputFile = OutputPath + \\r
38                      ModuleName + \\r
39                      Ffs.SectionSuffix.get("FV_IMAGE")\r
40                      \r
41         GenSectionCmd = 'GenSec -o '                      + \\r
42                          OutputFile                           + \\r
43                          ' -s '                               + \\r
44                          'EFI_SECTION_FIRMWARE_VOLUME_IMAGE ' + \\r
45                          FvFileName\r
46                          \r
47         print GenSectionCmd\r
48         GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
49         return OutputFile, self.Aligenment\r