Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C04FBC4321E for ; Sat, 26 Nov 2022 17:20:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8A6338529A; Sat, 26 Nov 2022 18:18:42 +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="N8VIGJQk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CDF4085098; Sat, 26 Nov 2022 17:59:53 +0100 (CET) Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 73D018502C for ; Sat, 26 Nov 2022 17:59:51 +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-x42e.google.com with SMTP id h11so3524053wrw.13 for ; Sat, 26 Nov 2022 08:59:51 -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=MXC8HNBpzciU/fmh18vbjm/N6JyOWXPNVzeJX4rkttE=; b=N8VIGJQkzMAJxXb1CUlPCm/2zUnNZnu80/d7X/qKSFWMW89Sitzh+vmZNOZr6WoBAD HC6DbKeNI9Gplql24veG6tke3QWPrnPxeNaYwAYlG5GPWuz8Lv/6R+VnxjYvLn80DndN eof0MhHkdZ41yyGl35JzUnGmVNfFrdGBcTQ+b3d9rA+T/+GTpWz3qFlwOE4ARguRzaEG JogZDhrO26feNY38BnY2rHtrI0l5iKEBSzHbAomgL102Rzyzwd2CQNrPgPjL6VMO5lNx mh4eS1kp+9KJsKn/78LpBn9LVoo/0uZ1D1XhYkp/+RMjrds3h1Rn5pLPSq0aAHbam1qd b6aA== 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=MXC8HNBpzciU/fmh18vbjm/N6JyOWXPNVzeJX4rkttE=; b=L1kp6VXz4baeXxM51CFgBbK4vKxCiKUafNzK+B6vVE+efEy8rilWrC3Jjpi/0YapsQ ckFnRLfSBQhDDhcS8YRMFbwL1tGPpitozEzkYx5TXTCo/f9cIjF55rCzUhu4wYfrw84I nDip7KASgDjMFzAKlTbzhFVmpPf74B9iVv0yM3yQAz0EdtXtj+zaQFsCk1dY46jIFIXA 12M+d8ABpt4f+h4PqkHjCS5KzQY/21VUOeatVh1tnoOLdH4aNHmpZJpea6UTl/05RdBI Tv5y3NQXHeDjDvy+icDq8P1nq7uN3lw8I8gogKtbNua/C+z0eUPsEzrPl17u/qZfaoQT ZXVg== X-Gm-Message-State: ANoB5pkSamLczTVvb2yiBWv49Bn3A7thgKy1/GQ45fbCQEqO0jS7xp6o bRRdwEYd39N6ja4T4bNtQspusQ== X-Google-Smtp-Source: AA0mqf4AoVdi4Zam1CIV9DUbRHSub9IDVERmbC9/WTt9CgPXJUNpaY9i8G7QR2NZB2jB7yWh03KpvA== X-Received: by 2002:adf:e103:0:b0:241:e2d5:8ef2 with SMTP id t3-20020adfe103000000b00241e2d58ef2mr13993672wrz.630.1669481991149; Sat, 26 Nov 2022 08:59:51 -0800 (PST) Received: from safae.baylibre.local ([2a04:cec0:11b5:4031:7588:eb2c:a5c2:aa6d]) by smtp.gmail.com with ESMTPSA id c15-20020adfe70f000000b00241e8d00b79sm7462408wrm.54.2022.11.26.08.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Nov 2022 08:59:50 -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 11/17] android: boot: update android_image_get_data to support v3, v4 Date: Sat, 26 Nov 2022 17:59:25 +0100 Message-Id: <20221126165931.197607-12-souajih@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221126165931.197607-1-souajih@baylibre.com> References: <20221126165931.197607-1-souajih@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Sat, 26 Nov 2022 18:18:14 +0100 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, the following functions are used to fill the generic android structure : andr_image_data: - android_boot_image_v3_v4_parse_hdr() - android_vendor_boot_image_v3_v4_parse_hdr() android_image_get_data() is then updated to support v3 and v4 Signed-off-by: Safae Ouajih --- boot/image-android.c | 79 +++++++++++++++++++++++++++++++++++++++-- include/android_image.h | 3 ++ include/image.h | 1 + 3 files changed, 80 insertions(+), 3 deletions(-) diff --git a/boot/image-android.c b/boot/image-android.c index eb821b08ccf4..5001b088f0fb 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -18,6 +18,64 @@ 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_v4 *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_vendor_boot_img_hdr_v3_v4 + *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; + 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_v1_v2 *hdr, struct andr_image_data *data) { @@ -78,10 +136,20 @@ bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr, return false; } - if (((struct andr_boot_img_hdr_v0_v1_v2 *)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_v1_v2 *)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; } @@ -199,6 +267,11 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *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_v1_v2 *hdr) { return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE); diff --git a/include/android_image.h b/include/android_image.h index 98a91cbf2f9c..b9591633c9f7 100644 --- a/include/android_image.h +++ b/include/android_image.h @@ -323,6 +323,8 @@ struct andr_image_data { ulong kernel_ptr; u32 kernel_size; u32 ramdisk_size; + ulong vendor_ramdisk_ptr; + u32 vendor_ramdisk_size; u32 boot_ramdisk_size; ulong second_ptr; u32 second_size; @@ -342,6 +344,7 @@ struct andr_image_data { ulong tags_addr; u32 header_version; u32 boot_img_total_size; + u32 vendor_boot_img_total_size; }; #endif diff --git a/include/image.h b/include/image.h index a0affc514a5d..c91502011500 100644 --- a/include/image.h +++ b/include/image.h @@ -1749,6 +1749,7 @@ void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr); bool android_image_print_dtb_contents(ulong hdr_addr); #endif bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr); +bool is_android_vendor_boot_image_header(const void *vendor_boot_img); /** * board_fit_config_name_match() - Check for a matching board name -- 2.25.1