mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-28 17:18:29 +00:00
feat(python/firmware): introduce fw model field
This commit is contained in:
parent
20dace89ff
commit
66eedd164c
1
python/.changelog.d/2701.added.1
Normal file
1
python/.changelog.d/2701.added.1
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add support for model field in firmware image.
|
@ -25,6 +25,7 @@ from construct_classes import Struct, subcon
|
|||||||
from .. import cosi
|
from .. import cosi
|
||||||
from ..tools import EnumAdapter, TupleAdapter
|
from ..tools import EnumAdapter, TupleAdapter
|
||||||
from . import consts, util
|
from . import consts, util
|
||||||
|
from .models import Model
|
||||||
from .vendor import VendorHeader
|
from .vendor import VendorHeader
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
@ -47,6 +48,9 @@ class FirmwareHeader(Struct):
|
|||||||
code_length: int
|
code_length: int
|
||||||
version: t.Tuple[int, int, int, int]
|
version: t.Tuple[int, int, int, int]
|
||||||
fix_version: t.Tuple[int, int, int, int]
|
fix_version: t.Tuple[int, int, int, int]
|
||||||
|
hw_model: Model
|
||||||
|
hw_revision: int
|
||||||
|
monotonic: int
|
||||||
hashes: t.Sequence[bytes]
|
hashes: t.Sequence[bytes]
|
||||||
|
|
||||||
v1_signatures: t.Sequence[bytes]
|
v1_signatures: t.Sequence[bytes]
|
||||||
@ -69,7 +73,10 @@ class FirmwareHeader(Struct):
|
|||||||
),
|
),
|
||||||
"version" / TupleAdapter(c.Int8ul, c.Int8ul, c.Int8ul, c.Int8ul),
|
"version" / TupleAdapter(c.Int8ul, c.Int8ul, c.Int8ul, c.Int8ul),
|
||||||
"fix_version" / TupleAdapter(c.Int8ul, c.Int8ul, c.Int8ul, c.Int8ul),
|
"fix_version" / TupleAdapter(c.Int8ul, c.Int8ul, c.Int8ul, c.Int8ul),
|
||||||
"_reserved" / c.Padding(8),
|
"hw_model" / EnumAdapter(c.Bytes(4), Model),
|
||||||
|
"hw_revision" / c.Int8ul,
|
||||||
|
"monotonic" / c.Int8ul,
|
||||||
|
"_reserved" / c.Padding(2),
|
||||||
"hashes" / c.Bytes(32)[16],
|
"hashes" / c.Bytes(32)[16],
|
||||||
|
|
||||||
"v1_signatures" / c.Bytes(64)[consts.V1_SIGNATURE_SLOTS],
|
"v1_signatures" / c.Bytes(64)[consts.V1_SIGNATURE_SLOTS],
|
||||||
|
@ -382,7 +382,9 @@ class EnumAdapter(construct.Adapter):
|
|||||||
super().__init__(subcon)
|
super().__init__(subcon)
|
||||||
|
|
||||||
def _encode(self, obj: Any, ctx: Any, path: Any):
|
def _encode(self, obj: Any, ctx: Any, path: Any):
|
||||||
return obj.value
|
if isinstance(obj, self.enum):
|
||||||
|
return obj.value
|
||||||
|
return obj
|
||||||
|
|
||||||
def _decode(self, obj: Any, ctx: Any, path: Any):
|
def _decode(self, obj: Any, ctx: Any, path: Any):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user