From patchwork Sun Feb 5 23:50:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1737937 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=vztLfZ/X; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P95m56FNLz23j7 for ; Mon, 6 Feb 2023 10:52:21 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D1C7585B63; Mon, 6 Feb 2023 00:51:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="vztLfZ/X"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B5C6985B6F; Mon, 6 Feb 2023 00:50:51 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 16E4A85B25 for ; Mon, 6 Feb 2023 00:50:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=souajih@baylibre.com Received: by mail-wr1-x42d.google.com with SMTP id k13so1526766wrh.8 for ; Sun, 05 Feb 2023 15:50:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6ZPL++BcnR61pXRmkxbqXLNdDh/YFEOKuqO5aYmcO+w=; b=vztLfZ/Xuws8NuPl92PxxPe5LsSVH7awz55/OaZgk+QT/fbGEXpr0V+RXQxkOYATET wUPnvtT7T49fSV3UQdyoHG838w/tiqMDDakmk9ZBhsW5S3Oh7rMzRyZktJga+6tX2zTJ Qi7YyrBm0rgd3Ve56TBImr1tFm6cdCPnJdF/Lh48o0Vb1sLQ+y4kem1JdWShwuv8EA9t vA+LYYyUrdNj2dmWFVQf3STIAJN+S7rHla2a04JfaQKNOiSYc0ajN2vsWN44jlna5o4E FKVr46s2ZSSHwiKEOEQtEKMQEcCmg9Rtvw9f8OCdFRKDTvG9d2RUYp8MjovN8yc5cDxA 6wzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6ZPL++BcnR61pXRmkxbqXLNdDh/YFEOKuqO5aYmcO+w=; b=QQ1yWAzBjkPlNk6+Zw/CTk1nyjpPkDh/YscGs/rpm80v607toWUh+aoPOaxSpmq6xj WGPDhK75DF35LrOvN7RdXQHJIczzmzUn9klB7ETnL2xqR5Ghxtn87LZoLDlmuYfT+zE8 S38og+o+5sECxuwZSWXMPKrqoOSek1iwjA8Y6WMo2IkhgII6uaCIFg5Wo0/kuHqWInjg uLbTUV/RwcsTZvHwrvgHMVi1FGS3p/IV129jbRSx0PQgek2e/KwLtP7pJBckM5lSzfGO cweKe/z6+BYVynyA3X7kfCxaC4S7db1CvgUCSSzY2gt/NTMfKD9bT5HsQmtHAuEdcZWK KDHw== X-Gm-Message-State: AO0yUKVe5btNSMOha+o0gGQ6F5UpuNmxZkYx/560LIdRGEFjeD9BbTNV H7SyoszkNSI8DMCZd8s+jUy+2w== X-Google-Smtp-Source: AK7set+cToIJvSRpAUBA6sA6KvemY5910zAMS2fKEUhx07uc6VM8ZlxNGuIT5d1OJRslKpo474ZQCg== X-Received: by 2002:a5d:678e:0:b0:2bc:aa67:28fb with SMTP id v14-20020a5d678e000000b002bcaa6728fbmr13271237wru.49.1675641040772; Sun, 05 Feb 2023 15:50:40 -0800 (PST) Received: from safae-ThinkPad-T480.. ([2a04:cec0:11ad:6643:93a:a991:f152:4df7]) by smtp.gmail.com with ESMTPSA id w2-20020a5d6802000000b002bfb1de74absm7430196wru.114.2023.02.05.15.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Feb 2023 15:50:40 -0800 (PST) From: Safae Ouajih To: sjg@chromium.org Cc: u-boot@lists.denx.de, sean.anderson@seco.com, r.stratiienko@gmail.com, mkorpershoek@baylibre.com, glaroque@baylibre.com, khilman@baylibre.com Subject: [PATCH v3 10/19] android: boot: update android_image_get_data to support v3, v4 Date: Mon, 6 Feb 2023 00:50:12 +0100 Message-Id: <20230205235021.355410-11-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230205235021.355410-1-souajih@baylibre.com> References: <20230205235021.355410-1-souajih@baylibre.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Since boot image header version 3 and 4 introduced vendor boot image, use the following functions to fill the generic android structure : andr_image_data: - android_boot_image_v3_v4_parse_hdr() - android_vendor_boot_image_v3_v4_parse_hdr() Update android_image_get_data() to support v3 and v4 Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- boot/image-android.c | 80 +++++++++++++++++++++++++++++++++++++++-- include/android_image.h | 3 ++ include/image.h | 11 ++++++ 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/boot/image-android.c b/boot/image-android.c index f16eebff49..712d437766 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -18,6 +18,65 @@ static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1]; +static void android_boot_image_v3_v4_parse_hdr(const struct andr_boot_img_hdr_v3 *hdr, + struct andr_image_data *data) +{ + ulong end; + + data->kcmdline = hdr->cmdline; + data->header_version = hdr->header_version; + + /* + * The header takes a full page, the remaining components are aligned + * on page boundary. + */ + end = (ulong)hdr; + end += ANDR_GKI_PAGE_SIZE; + data->kernel_ptr = end; + data->kernel_size = hdr->kernel_size; + end += ALIGN(hdr->kernel_size, ANDR_GKI_PAGE_SIZE); + data->ramdisk_size = hdr->ramdisk_size; + data->boot_ramdisk_size = hdr->ramdisk_size; + end += ALIGN(hdr->ramdisk_size, ANDR_GKI_PAGE_SIZE); + + if (hdr->header_version > 3) + end += ALIGN(hdr->signature_size, ANDR_GKI_PAGE_SIZE); + + data->boot_img_total_size = end - (ulong)hdr; +} + +static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vnd_boot_img_hdr + *hdr, struct andr_image_data *data) +{ + ulong end; + + /* + * The header takes a full page, the remaining components are aligned + * on page boundary. + */ + data->tags_addr = hdr->tags_addr; + data->image_name = hdr->name; + data->kernel_addr = hdr->kernel_addr; + data->ramdisk_addr = hdr->ramdisk_addr; + data->dtb_load_addr = hdr->dtb_addr; + end = (ulong)hdr; + end += hdr->page_size; + if (hdr->vendor_ramdisk_size) { + data->vendor_ramdisk_ptr = end; + data->vendor_ramdisk_size = hdr->vendor_ramdisk_size; + data->ramdisk_size += hdr->vendor_ramdisk_size; + end += ALIGN(hdr->vendor_ramdisk_size, hdr->page_size); + } + + data->dtb_ptr = end; + data->dtb_size = hdr->dtb_size; + + end += ALIGN(hdr->dtb_size, hdr->page_size); + end += ALIGN(hdr->vendor_ramdisk_table_size, hdr->page_size); + end += ALIGN(hdr->bootconfig_size, hdr->page_size); + data->vendor_boot_img_total_size = end - (ulong)hdr; +} + static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr_v0 *hdr, struct andr_image_data *data) { @@ -79,10 +138,20 @@ bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr, return false; } - if (((struct andr_boot_img_hdr_v0 *)boot_hdr)->header_version > 2) - printf("Only boot image header version 2 and below are supported\n"); - else + if (((struct andr_boot_img_hdr_v0 *)boot_hdr)->header_version > 2) { + if (!vendor_boot_hdr) { + printf("For boot header v3+ vendor boot image has to be provided\n"); + return false; + } + if (!is_android_vendor_boot_image_header(vendor_boot_hdr)) { + printf("Incorrect vendor boot image header\n"); + return false; + } + android_boot_image_v3_v4_parse_hdr(boot_hdr, data); + android_vendor_boot_image_v3_v4_parse_hdr(vendor_boot_hdr, data); + } else { android_boot_image_v0_v1_v2_parse_hdr(boot_hdr, data); + } return true; } @@ -200,6 +269,11 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, return 0; } +bool is_android_vendor_boot_image_header(const void *vendor_boot_img) +{ + return !memcmp(VENDOR_BOOT_MAGIC, vendor_boot_img, ANDR_VENDOR_BOOT_MAGIC_SIZE); +} + bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr) { return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE); diff --git a/include/android_image.h b/include/android_image.h index fb3a9d9858..99e7803508 100644 --- a/include/android_image.h +++ b/include/android_image.h @@ -323,6 +323,8 @@ struct andr_image_data { ulong kernel_ptr; /* kernel address */ u32 kernel_size; /* size in bytes */ u32 ramdisk_size; /* size in bytes */ + ulong vendor_ramdisk_ptr; /* vendor ramdisk address */ + u32 vendor_ramdisk_size; /* vendor ramdisk size*/ u32 boot_ramdisk_size; /* size in bytes */ ulong second_ptr; /* secondary bootloader address */ u32 second_size; /* secondary bootloader size */ @@ -342,6 +344,7 @@ struct andr_image_data { ulong tags_addr; /* physical addr for kernel tags */ u32 header_version; /* version of the boot image header */ u32 boot_img_total_size; /* boot image size */ + u32 vendor_boot_img_total_size; /* vendor boot image size */ }; #endif diff --git a/include/image.h b/include/image.h index f84c03f08f..c2e751c136 100644 --- a/include/image.h +++ b/include/image.h @@ -1876,6 +1876,17 @@ bool android_image_print_dtb_contents(ulong hdr_addr); */ bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr); +/** + * is_android_vendor_boot_image_header() - Check the magic of vendor boot image + * + * This checks the header of Android vendor boot image and verifies the magic + * is "VNDRBOOT" + * + * @vendor_boot_img: Pointer to boot image + * Return: non-zero if the magic is correct, zero otherwise + */ +bool is_android_vendor_boot_image_header(const void *vendor_boot_img); + /** * board_fit_config_name_match() - Check for a matching board name *