From mboxrd@z Thu Jan 1 00:00:00 1970 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 D3E41C61DA4 for ; Thu, 9 Feb 2023 14:33:32 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C568885F76; Thu, 9 Feb 2023 15:33:00 +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=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="v9D03YTD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3AE4085F63; Thu, 9 Feb 2023 15:32:59 +0100 (CET) Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (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 2370D85742 for ; Thu, 9 Feb 2023 15:32:56 +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=mkorpershoek@baylibre.com Received: by mail-wm1-x32b.google.com with SMTP id n28-20020a05600c3b9c00b003ddca7a2bcbso1663171wms.3 for ; Thu, 09 Feb 2023 06:32:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=DWP2ddClPSGYeVjV02f53AR9pgb6+mCaKMPlmXgOnmg=; b=v9D03YTDgg8g8fYbbvW7U3dbLPj0cyLg9IvAjzNl8688ayZZ/QFKAdz6EbTnwBWAib wEZNoprd62CX6lIODBalP96Znhn3cHC4c5jlzSylqz3G9S4iHqXWnJCDUx5xkUfrHzKz xz+xEUFQq6HwRcXf1Kjp0rQucaCPdfHHdbbroTpkjRIWpu1EYqQmgu3mjDo2ZdX7TOGE lkgaKj7Wb1ExnzREZDmEUcPmyotp+QyUKCg9sEeZ532Dut2V5moCif84MhuEp0aMfesk 5zBPjWNiGaD2PwG2YUQfHmV3woefmcOyMGe+aGyVIp5Sp/GU2u6rJJslD7qYPqBGdA/3 whtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DWP2ddClPSGYeVjV02f53AR9pgb6+mCaKMPlmXgOnmg=; b=XMe7HoZEdTXuaRGtVE2lsypYcktEbOOvrmKvMb3SuEbR+8XJburSo1WIhBYp6+yu7I fnpsvb6A7WM0YE7Vb8rLXnhb/SklxU9OwdNQb/bbKVp89PM7rCIfBxa67asVxKJWl0TQ B1NQfRF7CLZsPtFK8BU6N4DJKlNmeMIo6seUuD98O6Vc3qhYX0fJ652KpoyuabAW3022 tzTrQleE5Bj/m6ErqToymLp2Vxk9q4d3YRPKK0QhuTzoXDhVust1xmHNtycx4GLpprcX RJp8x6yZWjoBkhAAKt89NfGb7CoF98JZk3hwqC9EQpGUsp0fmNV8AJJMoC6L1GTXYF5G KGgA== X-Gm-Message-State: AO0yUKUf8o0u8gPH776KXcf076+ZpCJ5BiP3Prhv4LHHKrrB0hW7cTxo WJrH7lIQFI0vR5KbXbdILMAQqw== X-Google-Smtp-Source: AK7set+ZUq0QQzlOe8pdaAoX8dtH9rR42qpoJ0KaW1n/WQr/t/0402jHoP4/fGwj98PyeKzQJLYl4A== X-Received: by 2002:a05:600c:1e8a:b0:3df:e57d:f4ba with SMTP id be10-20020a05600c1e8a00b003dfe57df4bamr13152801wmb.7.1675953175513; Thu, 09 Feb 2023 06:32:55 -0800 (PST) Received: from localhost ([82.66.159.240]) by smtp.gmail.com with ESMTPSA id k7-20020a05600c080700b003daf672a616sm1899864wmp.22.2023.02.09.06.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 06:32:55 -0800 (PST) From: Mattijs Korpershoek To: Safae Ouajih , sjg@chromium.org Cc: u-boot@lists.denx.de, sean.anderson@seco.com, r.stratiienko@gmail.com, glaroque@baylibre.com, khilman@baylibre.com Subject: Re: [PATCH v3 10/19] android: boot: update android_image_get_data to support v3,v4 In-Reply-To: <20230205235021.355410-11-souajih@baylibre.com> References: <20230205235021.355410-1-souajih@baylibre.com> <20230205235021.355410-11-souajih@baylibre.com> Date: Thu, 09 Feb 2023 15:32:54 +0100 Message-ID: <871qmykiy1.fsf@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain 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 On Mon, Feb 06, 2023 at 00:50, Safae Ouajih wrote: > 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 > * > -- > 2.34.1