Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

docs: add mcuboot tools #51

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/mcuboot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# MCUBoot

::: smpclient.mcuboot
1 change: 1 addition & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nav:
- Serial (USB): transport/serial.md
- BLE: transport/ble.md
- UDP (Network): transport/udp.md
- MCUBoot: mcuboot.md
- Request/Response: requests.md
- File Management: file_management.md
- Image Management: image_management.md
Expand Down
10 changes: 8 additions & 2 deletions smpclient/mcuboot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tools for inspecting firmware images.
"""Tools for inspecting MCUBoot compatible firmware images.

Specification: https://docs.mcuboot.com/design.html
"""
Expand Down Expand Up @@ -101,6 +101,7 @@ class ImageVersion:

@staticmethod
def loads(data: bytes) -> 'ImageVersion':
"""Load an `ImageVersion` from `bytes`."""
return ImageVersion(*IMAGE_VERSION_STRUCT.unpack(data))

def __str__(self) -> str:
Expand Down Expand Up @@ -148,10 +149,12 @@ def __post_init__(self) -> None:

@staticmethod
def load_from(file: BytesIO | BufferedReader) -> 'ImageHeader':
"""Load an `ImageHeader` from an open file."""
return ImageHeader.loads(file.read(IMAGE_HEADER_STRUCT.size))

@staticmethod
def load_file(path: str) -> 'ImageHeader':
"""Load an `ImageHeader` the file at `path`."""
with open(path, 'rb') as f:
return ImageHeader.load_from(f)

Expand All @@ -178,6 +181,7 @@ def loads(data: bytes) -> 'ImageTLVInfo':

@staticmethod
def load_from(file: BytesIO | BufferedReader) -> 'ImageTLVInfo':
"""Load an `ImageTLVInfo` from a file."""
return ImageTLVInfo.loads(file.read(IMAGE_TLV_INFO_STRUCT.size))


Expand All @@ -191,6 +195,7 @@ class ImageTLV:

@staticmethod
def load_from(file: BytesIO | BufferedReader) -> 'ImageTLV':
"""Load an `ImageTLV` from a file."""
return ImageTLV(*IMAGE_TLV_STRUCT.unpack_from(file.read(IMAGE_TLV_STRUCT.size)))


Expand Down Expand Up @@ -225,6 +230,7 @@ def get_tlv(self, tlv: IMAGE_TLV) -> ImageTLVValue:

@staticmethod
def load_file(path: str) -> 'ImageInfo':
"""Load MCUBoot `ImageInfo` from the .bin or .hex file at `path`."""
file_path = pathlib.Path(path)
if file_path.suffix not in {".bin", ".hex"}:
raise MCUBootImageError(
Expand Down Expand Up @@ -279,7 +285,7 @@ def mcuimg() -> int:
prog="mcuimg",
description=(
"Inspect an MCUBoot compatible firmware update image."
"\nCopyright (C) 2023 Intercreate, Inc. | github.com/intercreate/smpclient"
"\nCopyright (C) 2023-2024 Intercreate, Inc. | github.com/intercreate/smpclient"
),
formatter_class=argparse.RawDescriptionHelpFormatter,
)
Expand Down
Loading