]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/CapsuleData.py
4 # Copyright (c) 2007-2018, 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
26 ## base class for capsule data
32 # @param self The object pointer
36 ## generate capsule data
38 # @param self The object pointer
39 def GenCapsuleSubItem(self
):
42 ## FFS class for capsule data
45 class CapsuleFfs (CapsuleData
):
48 # @param self The object pointer
54 ## generate FFS capsule data
56 # @param self The object pointer
57 # @retval string Generated file name
59 def GenCapsuleSubItem(self
):
60 FfsFile
= self
.Ffs
.GenFfs()
63 ## FV class for capsule data
66 class CapsuleFv (CapsuleData
):
69 # @param self The object pointer
74 self
.CapsuleName
= None
76 ## generate FV capsule data
78 # @param self The object pointer
79 # @retval string Generated file name
81 def GenCapsuleSubItem(self
):
82 if self
.FvName
.find('.fv') == -1:
83 if self
.FvName
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
:
84 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
[self
.FvName
.upper()]
85 FdBuffer
= StringIO
.StringIO('')
86 FvObj
.CapsuleName
= self
.CapsuleName
87 FvFile
= FvObj
.AddToBuffer(FdBuffer
)
88 FvObj
.CapsuleName
= None
92 FvFile
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FvName
)
95 ## FD class for capsule data
98 class CapsuleFd (CapsuleData
):
101 # @param self The object pointer
106 self
.CapsuleName
= None
108 ## generate FD capsule data
110 # @param self The object pointer
111 # @retval string Generated file name
113 def GenCapsuleSubItem(self
):
114 if self
.FdName
.find('.fd') == -1:
115 if self
.FdName
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
:
116 FdObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
[self
.FdName
.upper()]
117 FdFile
= FdObj
.GenFd()
120 FdFile
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FdName
)
123 ## AnyFile class for capsule data
126 class CapsuleAnyFile (CapsuleData
):
129 # @param self The object pointer
135 ## generate AnyFile capsule data
137 # @param self The object pointer
138 # @retval string Generated file name
140 def GenCapsuleSubItem(self
):
143 ## Afile class for capsule data
146 class CapsuleAfile (CapsuleData
):
149 # @param self The object pointer
155 ## generate Afile capsule data
157 # @param self The object pointer
158 # @retval string Generated file name
160 def GenCapsuleSubItem(self
):
163 class CapsulePayload(CapsuleData
):
164 '''Generate payload file, the header is defined below:
168 EFI_GUID UpdateImageTypeId;
169 UINT8 UpdateImageIndex;
170 UINT8 reserved_bytes[3];
171 UINT32 UpdateImageSize;
172 UINT32 UpdateVendorCodeSize;
173 UINT64 UpdateHardwareInstance; //Introduced in v2
174 } EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER;
179 self
.ImageTypeId
= None
180 self
.ImageIndex
= None
181 self
.HardwareInstance
= None
183 self
.VendorCodeFile
= []
184 self
.Certificate_Guid
= None
185 self
.MonotonicCount
= None
189 def GenCapsuleSubItem(self
, AuthData
=[]):
191 self
.Version
= '0x00000002'
192 if not self
.ImageIndex
:
193 self
.ImageIndex
= '0x1'
194 if not self
.HardwareInstance
:
195 self
.HardwareInstance
= '0x0'
196 ImageFileSize
= os
.path
.getsize(self
.ImageFile
)
198 # the ImageFileSize need include the full authenticated info size. From first bytes of MonotonicCount to last bytes of certificate.
199 # the 32 bit is the MonotonicCount, dwLength, wRevision, wCertificateType and CertType
202 if self
.VendorCodeFile
:
203 VendorFileSize
= os
.path
.getsize(self
.VendorCodeFile
)
208 Guid
= self
.ImageTypeId
.split('-')
209 Buffer
= pack('=ILHHBBBBBBBBBBBBIIQ',
210 int(self
.Version
,16),
214 int(Guid
[3][-4:-2], 16),
215 int(Guid
[3][-2:], 16),
216 int(Guid
[4][-12:-10], 16),
217 int(Guid
[4][-10:-8], 16),
218 int(Guid
[4][-8:-6], 16),
219 int(Guid
[4][-6:-4], 16),
220 int(Guid
[4][-4:-2], 16),
221 int(Guid
[4][-2:], 16),
222 int(self
.ImageIndex
, 16),
228 int(self
.HardwareInstance
, 16)
231 Buffer
+= pack('QIHH', AuthData
[0], AuthData
[1], AuthData
[2], AuthData
[3])
232 Buffer
+= uuid
.UUID(AuthData
[4]).get_bytes_le()
235 # Append file content to the structure
237 ImageFile
= open(self
.ImageFile
, 'rb')
238 Buffer
+= ImageFile
.read()
240 if self
.VendorCodeFile
:
241 VendorFile
= open(self
.VendorCodeFile
, 'rb')
242 Buffer
+= VendorFile
.read()