]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/CapsuleData.py
4 # Copyright (c) 2007-2013, Intel Corporation. All rights reserved.<BR>
6 # 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
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.
19 from GenFdsGlobalVariable
import GenFdsGlobalVariable
21 from struct
import pack
23 from Common
.Misc
import SaveFileOnChange
25 ## base class for capsule data
31 # @param self The object pointer
35 ## generate capsule data
37 # @param self The object pointer
38 def GenCapsuleSubItem(self
):
41 ## FFS class for capsule data
44 class CapsuleFfs (CapsuleData
):
47 # @param self The object pointer
53 ## generate FFS capsule data
55 # @param self The object pointer
56 # @retval string Generated file name
58 def GenCapsuleSubItem(self
):
59 FfsFile
= self
.Ffs
.GenFfs()
62 ## FV class for capsule data
65 class CapsuleFv (CapsuleData
):
68 # @param self The object pointer
73 self
.CapsuleName
= None
75 ## generate FV capsule data
77 # @param self The object pointer
78 # @retval string Generated file name
80 def GenCapsuleSubItem(self
):
81 if self
.FvName
.find('.fv') == -1:
82 if self
.FvName
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.keys():
83 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
.get(self
.FvName
.upper())
84 FdBuffer
= StringIO
.StringIO('')
85 FvObj
.CapsuleName
= self
.CapsuleName
86 FvFile
= FvObj
.AddToBuffer(FdBuffer
)
87 FvObj
.CapsuleName
= None
91 FvFile
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FvName
)
94 ## FD class for capsule data
97 class CapsuleFd (CapsuleData
):
100 # @param self The object pointer
105 self
.CapsuleName
= None
107 ## generate FD capsule data
109 # @param self The object pointer
110 # @retval string Generated file name
112 def GenCapsuleSubItem(self
):
113 if self
.FdName
.find('.fd') == -1:
114 if self
.FdName
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.keys():
115 FdObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
.get(self
.FdName
.upper())
116 FdFile
= FdObj
.GenFd()
119 FdFile
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FdName
)
122 ## AnyFile class for capsule data
125 class CapsuleAnyFile (CapsuleData
):
128 # @param self The object pointer
134 ## generate AnyFile capsule data
136 # @param self The object pointer
137 # @retval string Generated file name
139 def GenCapsuleSubItem(self
):
142 ## Afile class for capsule data
145 class CapsuleAfile (CapsuleData
):
148 # @param self The object pointer
154 ## generate Afile capsule data
156 # @param self The object pointer
157 # @retval string Generated file name
159 def GenCapsuleSubItem(self
):
162 class CapsulePayload(CapsuleData
):
163 '''Generate payload file, the header is defined below:
167 EFI_GUID UpdateImageTypeId;
168 UINT8 UpdateImageIndex;
169 UINT8 reserved_bytes[3];
170 UINT32 UpdateImageSize;
171 UINT32 UpdateVendorCodeSize;
172 UINT64 UpdateHardwareInstance; //Introduced in v2
173 } EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER;
178 self
.ImageTypeId
= None
179 self
.ImageIndex
= None
180 self
.HardwareInstance
= None
181 self
.ImageFile
= None
182 self
.VendorCodeFile
= None
184 def GenCapsuleSubItem(self
):
186 self
.Version
= 0x00000002
187 ImageFileSize
= os
.path
.getsize(self
.ImageFile
)
189 if self
.VendorCodeFile
:
190 VendorFileSize
= os
.path
.getsize(self
.VendorCodeFile
)
195 Guid
= self
.ImageTypeId
.split('-')
196 Buffer
= pack('=ILHHBBBBBBBBBBBBIIQ',
197 int(self
.Version
,16),
201 int(Guid
[3][-4:-2], 16),
202 int(Guid
[3][-2:], 16),
203 int(Guid
[4][-12:-10], 16),
204 int(Guid
[4][-10:-8], 16),
205 int(Guid
[4][-8:-6], 16),
206 int(Guid
[4][-6:-4], 16),
207 int(Guid
[4][-4:-2], 16),
208 int(Guid
[4][-2:], 16),
209 int(self
.ImageIndex
, 16),
215 int(self
.HardwareInstance
, 16)
218 # Append file content to the structure
220 ImageFile
= open(self
.ImageFile
, 'rb')
221 Buffer
+= ImageFile
.read()
223 if self
.VendorCodeFile
:
224 VendorFile
= open(self
.VendorCodeFile
, 'rb')
225 Buffer
+= VendorFile
.read()