MCUBoot¶
Tools for inspecting MCUBoot compatible firmware images.
Specification: https://docs.mcuboot.com/design.html
ImageMagic = Literal[2532554813]
module-attribute
¶
IMAGE_MAGIC: Final[ImageMagic] = 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
¶
ImageTLVInfoMagic = Literal[26887]
module-attribute
¶
IMAGE_TLV_INFO_MAGIC: Final[ImageTLVInfoMagic] = 26887
module-attribute
¶
ImageTLVProtInfoMagic = Literal[26888]
module-attribute
¶
IMAGE_TLV_PROT_INFO_MAGIC: Final[ImageTLVProtInfoMagic] = 26888
module-attribute
¶
T = TypeVar('T', ImageTLVInfoMagic, ImageTLVProtInfoMagic)
module-attribute
¶
Any TLV info magic type.
MagicT = TypeVar('MagicT', ImageTLVInfoMagic, ImageTLVProtInfoMagic)
module-attribute
¶
Method-scoped equivalent of T - class-scoped TypeVars only bind via self/cls,
so the static loaders of ImageTLVInfo require their own TypeVar.
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: ImageMagic
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
load_from(file: BytesIO | BufferedReader) -> ImageHeader
staticmethod
¶
load_file(path: str) -> ImageHeader
staticmethod
¶
ImageTLVInfo
¶
Bases: Generic[T]
An image Type-Length-Value (TLV) region header.
Source code in src/smpclient/mcuboot.py
magic: T
instance-attribute
¶
tlv_tot: int
instance-attribute
¶
size of TLV area (including tlv_info header)
loads(data: bytes, magic: MagicT) -> ImageTLVInfo[MagicT]
staticmethod
¶
Load an ImageTLVInfo from bytes.
Source code in src/smpclient/mcuboot.py
load_from(file: BytesIO | BufferedReader, magic: MagicT) -> ImageTLVInfo[MagicT]
staticmethod
¶
Load an ImageTLVInfo from a file.
load_tlvs_from(file: BytesIO | BufferedReader) -> list[ImageTLVValue]
¶
Read and parse the TLV entries that follow this header in file.
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
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
header: ImageHeader
instance-attribute
¶
tlv_info: ImageTLVInfo[ImageTLVInfoMagic]
instance-attribute
¶
tlvs: list[ImageTLVValue]
instance-attribute
¶
protected_tlv_info: ImageTLVInfo[ImageTLVProtInfoMagic] | None = None
class-attribute
instance-attribute
¶
protected_tlvs: list[ImageTLVValue] | None = None
class-attribute
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
parse_tlvs(region: bytes) -> list[ImageTLVValue]
staticmethod
¶
Parse TLVs from a byte sequence.
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
¶
Source code in src/smpclient/mcuboot.py
mcuimg() -> int
¶
A minimal CLI for getting info about an MCUBoot compatible FW image.