]>
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.
18 from __future__
import absolute_import
20 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
21 from io
import BytesIO
22 from struct
import pack
24 from Common
.Misc
import SaveFileOnChange
27 ## base class for capsule data
33 # @param self The object pointer
37 ## generate capsule data
39 # @param self The object pointer
40 def GenCapsuleSubItem(self
):
43 ## FFS class for capsule data
46 class CapsuleFfs (CapsuleData
):
49 # @param self The object pointer
55 ## generate FFS capsule data
57 # @param self The object pointer
58 # @retval string Generated file name
60 def GenCapsuleSubItem(self
):
61 FfsFile
= self
.Ffs
.GenFfs()
64 ## FV class for capsule data
67 class CapsuleFv (CapsuleData
):
70 # @param self The object pointer
75 self
.CapsuleName
= None
77 ## generate FV capsule data
79 # @param self The object pointer
80 # @retval string Generated file name
82 def GenCapsuleSubItem(self
):
83 if self
.FvName
.find('.fv') == -1:
84 if self
.FvName
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
:
85 FvObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
[self
.FvName
.upper()]
86 FdBuffer
= BytesIO('')
87 FvObj
.CapsuleName
= self
.CapsuleName
88 FvFile
= FvObj
.AddToBuffer(FdBuffer
)
89 FvObj
.CapsuleName
= None
93 FvFile
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FvName
)
96 ## FD class for capsule data
99 class CapsuleFd (CapsuleData
):
102 # @param self The object pointer
107 self
.CapsuleName
= None
109 ## generate FD capsule data
111 # @param self The object pointer
112 # @retval string Generated file name
114 def GenCapsuleSubItem(self
):
115 if self
.FdName
.find('.fd') == -1:
116 if self
.FdName
.upper() in GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
:
117 FdObj
= GenFdsGlobalVariable
.FdfParser
.Profile
.FdDict
[self
.FdName
.upper()]
118 FdFile
= FdObj
.GenFd()
121 FdFile
= GenFdsGlobalVariable
.ReplaceWorkspaceMacro(self
.FdName
)
124 ## AnyFile class for capsule data
127 class CapsuleAnyFile (CapsuleData
):
130 # @param self The object pointer
136 ## generate AnyFile capsule data
138 # @param self The object pointer
139 # @retval string Generated file name
141 def GenCapsuleSubItem(self
):
144 ## Afile class for capsule data
147 class CapsuleAfile (CapsuleData
):
150 # @param self The object pointer
156 ## generate Afile capsule data
158 # @param self The object pointer
159 # @retval string Generated file name
161 def GenCapsuleSubItem(self
):
164 class CapsulePayload(CapsuleData
):
165 '''Generate payload file, the header is defined below:
169 EFI_GUID UpdateImageTypeId;
170 UINT8 UpdateImageIndex;
171 UINT8 reserved_bytes[3];
172 UINT32 UpdateImageSize;
173 UINT32 UpdateVendorCodeSize;
174 UINT64 UpdateHardwareInstance; //Introduced in v2
175 } EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER;
180 self
.ImageTypeId
= None
181 self
.ImageIndex
= None
182 self
.HardwareInstance
= None
184 self
.VendorCodeFile
= []
185 self
.Certificate_Guid
= None
186 self
.MonotonicCount
= None
190 def GenCapsuleSubItem(self
, AuthData
=[]):
192 self
.Version
= '0x00000002'
193 if not self
.ImageIndex
:
194 self
.ImageIndex
= '0x1'
195 if not self
.HardwareInstance
:
196 self
.HardwareInstance
= '0x0'
197 ImageFileSize
= os
.path
.getsize(self
.ImageFile
)
199 # the ImageFileSize need include the full authenticated info size. From first bytes of MonotonicCount to last bytes of certificate.
200 # the 32 bit is the MonotonicCount, dwLength, wRevision, wCertificateType and CertType
203 if self
.VendorCodeFile
:
204 VendorFileSize
= os
.path
.getsize(self
.VendorCodeFile
)
209 Guid
= self
.ImageTypeId
.split('-')
210 Buffer
= pack('=ILHHBBBBBBBBBBBBIIQ',
211 int(self
.Version
, 16),
215 int(Guid
[3][-4:-2], 16),
216 int(Guid
[3][-2:], 16),
217 int(Guid
[4][-12:-10], 16),
218 int(Guid
[4][-10:-8], 16),
219 int(Guid
[4][-8:-6], 16),
220 int(Guid
[4][-6:-4], 16),
221 int(Guid
[4][-4:-2], 16),
222 int(Guid
[4][-2:], 16),
223 int(self
.ImageIndex
, 16),
229 int(self
.HardwareInstance
, 16)
232 Buffer
+= pack('QIHH', AuthData
[0], AuthData
[1], AuthData
[2], AuthData
[3])
233 Buffer
+= uuid
.UUID(AuthData
[4]).get_bytes_le()
236 # Append file content to the structure
238 ImageFile
= open(self
.ImageFile
, 'rb')
239 Buffer
+= ImageFile
.read()
241 if self
.VendorCodeFile
:
242 VendorFile
= open(self
.VendorCodeFile
, 'rb')
243 Buffer
+= VendorFile
.read()