2 # Module that encodes and decodes a FMP_PAYLOAD_HEADER with a payload.
3 # The FMP_PAYLOAD_HEADER is processed by the FmpPayloadHeaderLib in the
6 # Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
7 # SPDX-License-Identifier: BSD-2-Clause-Patent
16 def _SIGNATURE_32 (A
, B
, C
, D
):
17 return struct
.unpack ('=I',bytearray (A
+ B
+ C
+ D
, 'ascii'))[0]
19 def _SIGNATURE_32_TO_STRING (Signature
):
20 return struct
.pack ("<I", Signature
).decode ()
22 class FmpPayloadHeaderClass (object):
28 # UINT32 LowestSupportedVersion;
29 # } FMP_PAYLOAD_HEADER;
31 # #define FMP_PAYLOAD_HEADER_SIGNATURE SIGNATURE_32 ('M', 'S', 'S', '1')
33 _StructFormat
= '<IIII'
34 _StructSize
= struct
.calcsize (_StructFormat
)
36 _FMP_PAYLOAD_HEADER_SIGNATURE
= _SIGNATURE_32 ('M', 'S', 'S', '1')
40 self
.Signature
= self
._FMP
_PAYLOAD
_HEADER
_SIGNATURE
41 self
.HeaderSize
= self
._StructSize
42 self
.FwVersion
= 0x00000000
43 self
.LowestSupportedVersion
= 0x00000000
47 FmpPayloadHeader
= struct
.pack (
52 self
.LowestSupportedVersion
55 return FmpPayloadHeader
+ self
.Payload
57 def Decode (self
, Buffer
):
58 if len (Buffer
) < self
._StructSize
:
60 (Signature
, HeaderSize
, FwVersion
, LowestSupportedVersion
) = \
63 Buffer
[0:self
._StructSize
]
65 if Signature
!= self
._FMP
_PAYLOAD
_HEADER
_SIGNATURE
:
67 if HeaderSize
< self
._StructSize
:
69 self
.Signature
= Signature
70 self
.HeaderSize
= HeaderSize
71 self
.FwVersion
= FwVersion
72 self
.LowestSupportedVersion
= LowestSupportedVersion
73 self
.Payload
= Buffer
[self
.HeaderSize
:]
81 print ('FMP_PAYLOAD_HEADER.Signature = {Signature:08X} ({SignatureString})'.format (Signature
= self
.Signature
, SignatureString
= _SIGNATURE_32_TO_STRING (self
.Signature
)))
82 print ('FMP_PAYLOAD_HEADER.HeaderSize = {HeaderSize:08X}'.format (HeaderSize
= self
.HeaderSize
))
83 print ('FMP_PAYLOAD_HEADER.FwVersion = {FwVersion:08X}'.format (FwVersion
= self
.FwVersion
))
84 print ('FMP_PAYLOAD_HEADER.LowestSupportedVersion = {LowestSupportedVersion:08X}'.format (LowestSupportedVersion
= self
.LowestSupportedVersion
))
85 print ('sizeof (Payload) = {Size:08X}'.format (Size
= len (self
.Payload
)))