From 2336f518be1acf52d4a92f4b69619d3bc10e2db9 Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Sat, 22 Aug 2026 23:41:04 +0300 Subject: [PATCH] zyimage: make output byte order explicit 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 Signed-off-by: Aleksei Sviridkin --- src/zyimage.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/zyimage.c b/src/zyimage.c index 51a5cf7..dff77d0 100644 --- a/src/zyimage.c +++ b/src/zyimage.c @@ -8,6 +8,11 @@ #include #include #include +#if defined(__linux__) +#include +#else +#include +#endif #define szbuf 32768 @@ -132,7 +137,15 @@ int main(int argc, char *argv[]) { } fseek(f, 0, SEEK_SET); - sign.crc32 = chksum_crc32(f); + /* + * On-disk fields are little-endian, matching every existing + * ZYIMAGE_ID value in the OpenWrt tree (unlike the vendor tool, + * which writes device_id big-endian). E.g. ZYIMAGE_ID 0x804410 and + * the vendor's CONFIG_TARGET_DEVICE_ID="0x10448000" are the same + * four bytes in opposite order. + */ + sign.device_id = htole32(sign.device_id); + sign.crc32 = htole32(chksum_crc32(f)); fwrite(&sign, sizeof(sign), 1, f); fclose(f);