From 0e82df9e10a48742d65d868981fb1a1ba4a8ca99 Mon Sep 17 00:00:00 2001 From: "David K." Date: Thu, 30 Jan 2025 20:15:38 -0500 Subject: [PATCH] Support zImage compression types other than gzip. Instead of just searching for the gzip magic, it now incrementally searches the kernel for the first thing that `check_fmt_lg` doesn't report as `UNKNOWN`. --- native/src/boot/bootimg.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/native/src/boot/bootimg.cpp b/native/src/boot/bootimg.cpp index e7f108447..2a5cc9c16 100644 --- a/native/src/boot/bootimg.cpp +++ b/native/src/boot/bootimg.cpp @@ -431,9 +431,20 @@ bool boot_img::parse_image(const uint8_t *p, format_t type) { } if (k_fmt == ZIMAGE) { z_hdr = reinterpret_cast(kernel); - if (const void *gzip = memmem(kernel, hdr->kernel_size(), GZIP1_MAGIC "\x08\x00", 4)) { + + const uint8_t* found_pos = 0; + + for (const uint8_t* search_pos = kernel + 0x28; search_pos < kernel + hdr->kernel_size(); search_pos++) { + // ^^^^^^ +0x28 to search after zimage header and magic + if (check_fmt_lg(search_pos, hdr->kernel_size() - (search_pos - kernel)) != UNKNOWN) { + found_pos = search_pos; + search_pos = kernel + hdr->kernel_size(); + } + } + + if (found_pos != 0) { fprintf(stderr, "ZIMAGE_KERNEL\n"); - z_info.hdr_sz = (const uint8_t *) gzip - kernel; + z_info.hdr_sz = (const uint8_t *) found_pos - kernel; // Find end of piggy uint32_t zImage_size = z_hdr->end - z_hdr->start; @@ -457,7 +468,7 @@ bool boot_img::parse_image(const uint8_t *p, format_t type) { k_fmt = check_fmt_lg(kernel, hdr->kernel_size()); } } else { - fprintf(stderr, "! Could not find zImage gzip piggy, keeping raw kernel\n"); + fprintf(stderr, "! Could not find zImage piggy, keeping raw kernel\n"); } } fprintf(stderr, "%-*s [%s]\n", PADDING, "KERNEL_FMT", fmt2name[k_fmt]);