]>
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 # SPDX-License-Identifier: BSD-2-Clause-Patent
12 from __future__
import absolute_import
13 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
14 from io
import BytesIO
15 from struct
import pack
17 from Common
.Misc
import SaveFileOnChange
20 ## base class for capsule data
26 # @param self The object pointer
30 ## generate capsule data
32 # @param self The object pointer
33 def GenCapsuleSubItem(self
):
36 ## FFS class for capsule data
39 class CapsuleFfs (CapsuleData
):
42 # @param self The object pointer
48 ## generate FFS capsule data
50 # @param self The object pointer
51 # @retval string Generated file name
53 def GenCapsuleSubItem(self
):
54 FfsFile
= self
.Ffs
.GenFfs()
57 ## FV class for capsule data
60 class CapsuleFv (CapsuleData
):
63 # @param self The object pointer
68 self
.CapsuleName
= None
70 ## generate FV capsule data
72 # @param self The object pointer
73 # @retval string Generated file name
75 def GenCapsuleSubItem(self
):
76 if self
.FvName
.find('.fv') == -1:
77 if self
.FvName
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
:
78 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
[self
.FvName
.upper()]
80 FvObj
.CapsuleName
= self
.CapsuleName
81 FvFile
= FvObj
.AddToBuffer(FdBuffer
)
82 FvObj
.CapsuleName
= None
86 FvFile
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FvName
)
89 ## FD class for capsule data
92 class CapsuleFd (CapsuleData
):
95 # @param self The object pointer
100 self
.CapsuleName
= None
102 ## generate FD capsule data
104 # @param self The object pointer
105 # @retval string Generated file name
107 def GenCapsuleSubItem(self
):
108 if self
.FdName
.find('.fd') == -1:
109 if self
.FdName
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
:
110 FdObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
[self
.FdName
.upper()]
111 FdFile
= FdObj
.GenFd()
114 FdFile
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FdName
)
117 ## AnyFile class for capsule data
120 class CapsuleAnyFile (CapsuleData
):
123 # @param self The object pointer
129 ## generate AnyFile capsule data
131 # @param self The object pointer
132 # @retval string Generated file name
134 def GenCapsuleSubItem(self
):
137 ## Afile class for capsule data
140 class CapsuleAfile (CapsuleData
):
143 # @param self The object pointer
149 ## generate Afile capsule data
151 # @param self The object pointer
152 # @retval string Generated file name
154 def GenCapsuleSubItem(self
):
157 class CapsulePayload(CapsuleData
):
158 '''Generate payload file, the header is defined below:
162 EFI_GUID UpdateImageTypeId;
163 UINT8 UpdateImageIndex;
164 UINT8 reserved_bytes[3];
165 UINT32 UpdateImageSize;
166 UINT32 UpdateVendorCodeSize;
167 UINT64 UpdateHardwareInstance; //Introduced in v2
168 } EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER;
173 self
.ImageTypeId
= None
174 self
.ImageIndex
= None
175 self
.HardwareInstance
= None
177 self
.VendorCodeFile
= []
178 self
.Certificate_Guid
= None
179 self
.MonotonicCount
= None
183 def GenCapsuleSubItem(self
, AuthData
=[]):
185 self
.Version
= '0x00000002'
186 if not self
.ImageIndex
:
187 self
.ImageIndex
= '0x1'
188 if not self
.HardwareInstance
:
189 self
.HardwareInstance
= '0x0'
190 ImageFileSize
= os
.path
.getsize(self
.ImageFile
)
192 # the ImageFileSize need include the full authenticated info size. From first bytes of MonotonicCount to last bytes of certificate.
193 # the 32 bit is the MonotonicCount, dwLength, wRevision, wCertificateType and CertType
196 if self
.VendorCodeFile
:
197 VendorFileSize
= os
.path
.getsize(self
.VendorCodeFile
)
202 Guid
= self
.ImageTypeId
.split('-')
203 Buffer
= pack('=ILHHBBBBBBBBBBBBIIQ',
204 int(self
.Version
, 16),
208 int(Guid
[3][-4:-2], 16),
209 int(Guid
[3][-2:], 16),
210 int(Guid
[4][-12:-10], 16),
211 int(Guid
[4][-10:-8], 16),
212 int(Guid
[4][-8:-6], 16),
213 int(Guid
[4][-6:-4], 16),
214 int(Guid
[4][-4:-2], 16),
215 int(Guid
[4][-2:], 16),
216 int(self
.ImageIndex
, 16),
222 int(self
.HardwareInstance
, 16)
225 Buffer
+= pack('QIHH', AuthData
[0], AuthData
[1], AuthData
[2], AuthData
[3])
226 Buffer
+= uuid
.UUID(AuthData
[4]).bytes_le
229 # Append file content to the structure
231 ImageFile
= open(self
.ImageFile
, 'rb')
232 Buffer
+= ImageFile
.read()
234 if self
.VendorCodeFile
:
235 VendorFile
= open(self
.VendorCodeFile
, 'rb')
236 Buffer
+= VendorFile
.read()