MCUBoot¶
Tools for inspecting MCUBoot compatible firmware images.
Specification: https://docs.mcuboot.com/design.html
IMAGE_MAGIC: Final = 2532554813
module-attribute
¶
IMAGE_HEADER_SIZE: Final = 32
module-attribute
¶
IMAGE_VERSION_STRUCT: Final = struct.Struct(f'<{_IMAGE_VERSION_FORMAT_STRING}')
module-attribute
¶
IMAGE_HEADER_STRUCT: Final = struct.Struct(f'<LLHHLL{_IMAGE_VERSION_FORMAT_STRING}4x')
module-attribute
¶
IMAGE_TLV_INFO_MAGIC: Final = 26887
module-attribute
¶
IMAGE_TLV_PROT_INFO_MAGIC: Final = 26888
module-attribute
¶
IMAGE_TLV_INFO_STRUCT: Final = struct.Struct('<HH')
module-attribute
¶
IMAGE_TLV_STRUCT: Final = struct.Struct('<BxH')
module-attribute
¶
ImageTLVType = Annotated[Union[IMAGE_TLV, VendorTLV, int], Field(union_mode='left_to_right')]
module-attribute
¶
TLV type that accepts standard IMAGE_TLV enums, vendor-defined TLVs, or any integer.
This uses Pydantic's "left to right" union mode to: 1. First try to match against IMAGE_TLV enum values 2. Then try to validate as a VendorTLV (0xXXA0-0xXXFE ranges) 3. Finally accept any integer as a fallback
This ensures backward compatibility and supports future TLV types without validation errors.
MCUBootImageError
¶
Bases: Exception
Source code in src/smpclient/mcuboot.py
TLVNotFound
¶
Bases: MCUBootImageError
Source code in src/smpclient/mcuboot.py
IMAGE_F
¶
Bases: IntFlag
Image header flags.
Source code in src/smpclient/mcuboot.py
PIC = 1
class-attribute
instance-attribute
¶
Not supported.
ENCRYPTED_AES128 = 4
class-attribute
instance-attribute
¶
Encrypted using AES128.
ENCRYPTED_AES256 = 8
class-attribute
instance-attribute
¶
Encrypted using AES256.
NON_BOOTABLE = 16
class-attribute
instance-attribute
¶
Split image app.
RAM_LOAD = 32
class-attribute
instance-attribute
¶
IMAGE_TLV
¶
Bases: IntEnum
Image trailer TLV types.
Specification: https://docs.mcuboot.com/design.html#image-format
Source code in src/smpclient/mcuboot.py
KEYHASH = 1
class-attribute
instance-attribute
¶
Hash of the public key
PUBKEY = 2
class-attribute
instance-attribute
¶
Public key
SHA256 = 16
class-attribute
instance-attribute
¶
SHA256 of image hdr and body
SHA384 = 17
class-attribute
instance-attribute
¶
SHA384 of image hdr and body
SHA512 = 18
class-attribute
instance-attribute
¶
SHA512 of image hdr and body
RSA2048_PSS = 32
class-attribute
instance-attribute
¶
RSA2048 of hash output
ECDSA224 = 33
class-attribute
instance-attribute
¶
ECDSA of hash output - Not supported anymore
ECDSA_SIG = 34
class-attribute
instance-attribute
¶
ECDSA of hash output
RSA3072_PSS = 35
class-attribute
instance-attribute
¶
RSA3072 of hash output
ED25519 = 36
class-attribute
instance-attribute
¶
ED25519 of hash output
SIG_PURE = 37
class-attribute
instance-attribute
¶
Signature prepared over full image rather than digest
ENC_RSA2048 = 48
class-attribute
instance-attribute
¶
Key encrypted with RSA-OAEP-2048
ENC_KW = 49
class-attribute
instance-attribute
¶
Key encrypted with AES-KW-128 or 256
ENC_EC256 = 50
class-attribute
instance-attribute
¶
Key encrypted with ECIES-P256
ENC_X25519 = 51
class-attribute
instance-attribute
¶
Key encrypted with ECIES-X25519
ENC_X25519_SHA512 = 52
class-attribute
instance-attribute
¶
Key exchange using X25519 with SHA512 MAC
DEPENDENCY = 64
class-attribute
instance-attribute
¶
Image depends on other image
SEC_CNT = 80
class-attribute
instance-attribute
¶
Security counter
BOOT_RECORD = 96
class-attribute
instance-attribute
¶
Measured boot record
DECOMP_SIZE = 112
class-attribute
instance-attribute
¶
Decompressed image size excluding header/TLVs
DECOMP_SHA = 113
class-attribute
instance-attribute
¶
Decompressed image hash matching format of compressed slot
DECOMP_SIGNATURE = 114
class-attribute
instance-attribute
¶
Decompressed image signature matching compressed format
COMP_DEC_SIZE = 115
class-attribute
instance-attribute
¶
Compressed decrypted image size
UUID_VID = 128
class-attribute
instance-attribute
¶
Vendor unique identifier
UUID_CID = 129
class-attribute
instance-attribute
¶
Device class unique identifier
VendorTLV
¶
Bases: int
Vendor-defined TLV type in reserved ranges (0xXXA0-0xXXFE).
Vendor reserved TLVs occupy ranges from 0xXXA0 to 0xXXFE, where XX represents any upper byte value. Examples include ranges 0x00A0-0x00FF, 0x01A0-0x01FF, and 0x02A0-0x02FF, continuing through 0xFFA0-0xFFFE.
Source code in src/smpclient/mcuboot.py
__new__(value: int) -> VendorTLV
¶
Create a new VendorTLV, validating the range.
Source code in src/smpclient/mcuboot.py
__get_pydantic_core_schema__(_source_type: Any, _handler: GetCoreSchemaHandler) -> CoreSchema
classmethod
¶
Source code in src/smpclient/mcuboot.py
ImageVersion
¶
An MCUBoot image_version struct.
Source code in src/smpclient/mcuboot.py
ImageHeader
¶
An MCUBoot signed FW update header.
Source code in src/smpclient/mcuboot.py
magic: int
instance-attribute
¶
load_addr: int
instance-attribute
¶
hdr_size: int
instance-attribute
¶
protect_tlv_size: int
instance-attribute
¶
img_size: int
instance-attribute
¶
flags: IMAGE_F
instance-attribute
¶
ver: ImageVersion
instance-attribute
¶
loads(data: bytes) -> ImageHeader
staticmethod
¶
Load an ImageHeader from bytes.
Source code in src/smpclient/mcuboot.py
__post_init__() -> None
¶
load_from(file: BytesIO | BufferedReader) -> ImageHeader
staticmethod
¶
load_file(path: str) -> ImageHeader
staticmethod
¶
ImageTLVInfo
¶
An image Type-Length-Value (TLV) region header.
Source code in src/smpclient/mcuboot.py
ImageTLV
¶
A TLV header - type and length.
Source code in src/smpclient/mcuboot.py
ImageTLVValue
¶
Source code in src/smpclient/mcuboot.py
ImageInfo
¶
A summary of an MCUBoot FW update image.
Source code in src/smpclient/mcuboot.py
header: ImageHeader
instance-attribute
¶
tlv_info: ImageTLVInfo
instance-attribute
¶
tlvs: list[ImageTLVValue]
instance-attribute
¶
file: str | None = None
class-attribute
instance-attribute
¶
get_tlv(tlv: ImageTLVType) -> ImageTLVValue
¶
Get a TLV from the image or raise TLVNotFound.
Source code in src/smpclient/mcuboot.py
load_file(path: str) -> ImageInfo
staticmethod
¶
Load MCUBoot ImageInfo from the file at path.
Files with the .hex extension are treated as Intel HEX format.
All other file extensions are treated as binary.
Source code in src/smpclient/mcuboot.py
__str__() -> str
¶
mcuimg() -> int
¶
A minimal CLI for getting info about an MCUBoot compatible FW image.