Skip to content

zyimage: make output byte order explicit - #75

Open
lexfrei wants to merge 1 commit into
openwrt:masterfrom
lexfrei:fix/zyimage-explicit-byte-order
Open

zyimage: make output byte order explicit#75
lexfrei wants to merge 1 commit into
openwrt:masterfrom
lexfrei:fix/zyimage-explicit-byte-order

Conversation

@lexfrei

@lexfrei lexfrei commented Aug 22, 2026

Copy link
Copy Markdown

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.

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>
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.

1 participant