zyimage: make output byte order explicit - #75
Open
lexfrei wants to merge 1 commit into
Open
Conversation
device_id and crc32 were written in native host byte order, with no byte-swap calls at all, so the on-disk output was only correct on little-endian build hosts. Make the existing little-endian behavior explicit with htole32() and document the byte layout, so a porter reading the vendor's CONFIG_TARGET_DEVICE_ID can map it to the equivalent OpenWrt ZYIMAGE_ID. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
zyimage writes device_id and crc32 into the signature header in native host byte order — there is no htobe32/htole32 call anywhere in the tool, so the output is only correct on little-endian build hosts. This makes the existing little-endian behavior explicit with htole32() on both fields and documents the byte layout, so the relationship between OpenWrt's ZYIMAGE_ID values and the vendor's device-id constants is discoverable from the source.
I used htole32 rather than htobe32 to match the actual on-disk format: OpenWrt's ZYIMAGE_ID definitions were chosen assuming this little-endian encoding, and switching to big-endian would silently change the on-disk device id for every device that currently uses zyimage.
Testing: built with CMake on Linux and with a plain compiler on macOS. Verified the change is output-neutral on little-endian hosts by building the tool before and after the change and comparing signed output byte-for-byte across several device ids and file sizes.