]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Capsule.py
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Capsule.py
1 ## @file
2 # generate capsule
3 #
4 # Copyright (c) 2007, Intel Corporation
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 ##
16 # Import Modules
17 #
18 from GenFdsGlobalVariable import GenFdsGlobalVariable
19 from CommonDataClass.FdfClass import CapsuleClassObject
20 import os
21 import subprocess
22 import StringIO
23 from Common.Misc import SaveFileOnChange
24
25
26 T_CHAR_LF = '\n'
27
28 ## create inf file describes what goes into capsule and call GenFv to generate capsule
29 #
30 #
31 class Capsule (CapsuleClassObject) :
32 ## The constructor
33 #
34 # @param self The object pointer
35 #
36 def __init__(self):
37 CapsuleClassObject.__init__(self)
38 # For GenFv
39 self.BlockSize = None
40 # For GenFv
41 self.BlockNum = None
42
43 ## Generate capsule
44 #
45 # @param self The object pointer
46 #
47 def GenCapsule(self):
48 CapInfFile = self.GenCapInf()
49 CapInfFile.writelines("[files]" + T_CHAR_LF)
50
51 for CapsuleDataObj in self.CapsuleDataList :
52 FileName = CapsuleDataObj.GenCapsuleSubItem()
53 CapInfFile.writelines("EFI_FILE_NAME = " + \
54 FileName + \
55 T_CHAR_LF)
56 SaveFileOnChange(self.CapInfFileName, CapInfFile.getvalue(), False)
57 CapInfFile.close()
58 #
59 # Call GenFv tool to generate capsule
60 #
61 CapOutputFile = os.path.join(GenFdsGlobalVariable.FvDir, self.UiCapsuleName)
62 CapOutputFile = CapOutputFile + '.Cap'
63 GenFdsGlobalVariable.GenerateFirmwareVolume(
64 CapOutputFile,
65 [self.CapInfFileName],
66 Capsule=True
67 )
68 GenFdsGlobalVariable.SharpCounter = 0
69
70 ## Generate inf file for capsule
71 #
72 # @param self The object pointer
73 # @retval file inf file object
74 #
75 def GenCapInf(self):
76 self.CapInfFileName = os.path.join(GenFdsGlobalVariable.FvDir,
77 self.UiCapsuleName + "_Cap" + '.inf')
78 CapInfFile = StringIO.StringIO() #open (self.CapInfFileName , 'w+')
79
80 CapInfFile.writelines("[options]" + T_CHAR_LF)
81
82 for Item in self.TokensDict.keys():
83 CapInfFile.writelines("EFI_" + \
84 Item + \
85 ' = ' + \
86 self.TokensDict.get(Item) + \
87 T_CHAR_LF)
88
89 return CapInfFile