1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-29 09:38:08 +00:00

feat(python/firmware): introduce fw model field

This commit is contained in:
matejcik 2022-12-19 16:27:22 +01:00
parent 20dace89ff
commit 66eedd164c
3 changed files with 12 additions and 2 deletions

View File

@ -0,0 +1 @@
Add support for model field in firmware image.

View File

@ -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],

View File

@ -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: