Skip to content

Handle parsing protected TLV region#114

Merged
JPHutchins merged 5 commits into
intercreate:mainfrom
LiveViewTech:prot-tlv-handling
Jun 11, 2026
Merged

Handle parsing protected TLV region#114
JPHutchins merged 5 commits into
intercreate:mainfrom
LiveViewTech:prot-tlv-handling

Conversation

@ChapterSevenSeeds

Copy link
Copy Markdown
Contributor

Zephyr images built with TF-M get an MCUboot trailer generated with both protected and regular TLV entries. This PR modifies the MCUboot image parsing to properly recognize and parse these entries.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the MCUboot image inspection/parsing logic to handle images that contain both protected and regular TLV regions (common with Zephyr + TF-M signed images), and adds a regression test using a TF-M fixture.

Changes:

  • Extend ImageInfo parsing to read an optional protected TLV region before the regular TLV region.
  • Add protected_tlv_info / protected_tlvs to ImageInfo and include protected TLVs in get_tlv() lookups.
  • Add a test fixture-based regression test to validate protected TLV parsing.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/smpclient/mcuboot.py Adds protected TLV parsing and updates TLV lookup/printing to account for protected TLVs.
tests/test_mcuboot_tools.py Adds a regression test for protected TLV parsing using a TF-M signed image fixture.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/smpclient/mcuboot.py Outdated
Comment thread tests/test_mcuboot_tools.py Outdated

@JPHutchins JPHutchins left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this important update!

Comment thread src/smpclient/mcuboot.py Outdated
tlv_header = ImageTLV.load_from(f)
tlvs.append(ImageTLVValue(header=tlv_header, value=f.read(tlv_header.len)))
# The mcuboot design doc says that optional protected TLV entries come before regular TLV entries
protected_tlvs = []

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably missing typing.

Comment thread src/smpclient/mcuboot.py
Comment on lines +305 to +313
@staticmethod
def parse_tlvs(f: BytesIO, tlvs_end_offset: int) -> list[ImageTLVValue]:
"""Parse TLVs from the current position in the file up to the given byte offset."""
tlvs: list[ImageTLVValue] = []
while f.tell() < tlvs_end_offset:
tlv_header = ImageTLV.load_from(f)
tlvs.append(ImageTLVValue(header=tlv_header, value=f.read(tlv_header.len)))

return tlvs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that I agree with abstracting this to reduce repetition, but I don't love that it has the side effect of mutating the file read position. Consider inlining again (even though it's repetition) or documenting the side effect.

Maybe some cleverness can be done with an iterator or generator, probably not worth the effort.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I reworked it to take in a bytes object and just operate off of that.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

Comment thread src/smpclient/mcuboot.py
Comment thread src/smpclient/mcuboot.py
Comment thread src/smpclient/mcuboot.py
Comment thread src/smpclient/mcuboot.py Outdated
JPHutchins
JPHutchins previously approved these changes Jun 11, 2026

@JPHutchins JPHutchins left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LMK when you're ready to merge and I'll do so.

I think that linting must be disabled on this file, so instead of iterating, or asking you to rebase, I'm going to swing back around with a rework, confidence given by the integration test that was added.

@ChapterSevenSeeds

Copy link
Copy Markdown
Contributor Author

@JPHutchins Feel free to take it whenever convenient, though I am willing to continue trying to satiate the Microsoft AI beast if you'd like 😛

@JPHutchins JPHutchins merged commit caff813 into intercreate:main Jun 11, 2026
28 checks passed
@ChapterSevenSeeds ChapterSevenSeeds deleted the prot-tlv-handling branch June 12, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants