From b614b06736c236ae7b9729a4759884824f3d23e2 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 13 Sep 2017 22:32:51 +0800 Subject: [PATCH] Search for dtb only if not existed --- jni/magiskboot/bootimg.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/jni/magiskboot/bootimg.c b/jni/magiskboot/bootimg.c index 198f0e97b..52c85dfb5 100644 --- a/jni/magiskboot/bootimg.c +++ b/jni/magiskboot/bootimg.c @@ -92,14 +92,16 @@ int parse_img(void *orig, size_t size, boot_img *boot) { boot->extra = base + pos; } - // Linear search in kernel for DTB - for (int i = 0; i < boot->hdr.kernel_size; ++i) { - if (memcmp(boot->kernel + i, DTB_MAGIC, 4) == 0) { - boot->flags |= APPEND_DTB; - boot->dtb = boot->kernel + i; - boot->hdr.dt_size = boot->hdr.kernel_size - i; - boot->hdr.kernel_size = i; - fprintf(stderr, "APPEND_DTB [%d]\n", boot->hdr.dt_size); + // Search for dtb in kernel if not found + if (boot->hdr.dt_size == 0) { + for (int i = 0; i < boot->hdr.kernel_size; ++i) { + if (memcmp(boot->kernel + i, DTB_MAGIC, 4) == 0) { + boot->flags |= APPEND_DTB; + boot->dtb = boot->kernel + i; + boot->hdr.dt_size = boot->hdr.kernel_size - i; + boot->hdr.kernel_size = i; + fprintf(stderr, "APPEND_DTB [%d]\n", boot->hdr.dt_size); + } } }