From 81542fc6a846550152e07eaf7b111c4cb9dbfda1 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 29 Mar 2017 04:30:51 +0800 Subject: [PATCH] Fix MTK header support --- jni/magiskboot/parseimg.c | 3 ++- jni/magiskboot/repack.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/jni/magiskboot/parseimg.c b/jni/magiskboot/parseimg.c index f2beb26ba..59877434e 100644 --- a/jni/magiskboot/parseimg.c +++ b/jni/magiskboot/parseimg.c @@ -16,9 +16,10 @@ static void check_headers() { printf("MTK header found in kernel\n"); mtk_kernel = 1; } - if (check_type(ramdisk) == MTK) { + if (ramdisk_type == MTK) { printf("MTK header found in ramdisk\n"); mtk_ramdisk = 1; + ramdisk_type = check_type(ramdisk + 512); } // Check dtb if ELF boot diff --git a/jni/magiskboot/repack.c b/jni/magiskboot/repack.c index c76805fb5..f69892a06 100644 --- a/jni/magiskboot/repack.c +++ b/jni/magiskboot/repack.c @@ -53,7 +53,7 @@ void repack(const char* orig_image, const char* out_image) { // Restore kernel if (mtk_kernel) { mtk_kernel_off = lseek(fd, 0, SEEK_CUR); - write_zero(fd, 512); + restore_buf(fd, kernel, 512); memcpy(&mtk_kernel_hdr, kernel, sizeof(mtk_kernel_hdr)); } hdr.kernel_size = restore(KERNEL_FILE, fd); @@ -62,7 +62,7 @@ void repack(const char* orig_image, const char* out_image) { // Restore ramdisk if (mtk_ramdisk) { mtk_ramdisk_off = lseek(fd, 0, SEEK_CUR); - write_zero(fd, 512); + restore_buf(fd, ramdisk, 512); memcpy(&mtk_ramdisk_hdr, ramdisk, sizeof(mtk_ramdisk_hdr)); } if (access(RAMDISK_FILE, R_OK) == 0) {