From patchwork Thu Jan 26 16:04:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732357 X-Patchwork-Delegate: sjg@chromium.org 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (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=TwiUd83W; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4P2ltj4x5Pz23h7 for ; Fri, 27 Jan 2023 03:06:05 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 98623856F5; Thu, 26 Jan 2023 17:05:36 +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="TwiUd83W"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C17EF856ED; Thu, 26 Jan 2023 17:05:13 +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-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (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 3E88D85650 for ; Thu, 26 Jan 2023 17:05:09 +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-x433.google.com with SMTP id q10so2267355wrm.4 for ; Thu, 26 Jan 2023 08:05:09 -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=zMrckJWET3alSVSflN8YLxc9BaB0hu5GLULu4Dgnyvc=; b=TwiUd83WvEcWiTOQOmYnfUqX9dcI0b8TgDfdt5/Th1MZ/KZpcXhmW2asiGKsK6/H8+ T1Ix09DyJ2mlO6nPsmfB5Lu9AFGeRxxGviAV1clzCsg4RQuFPxU0IbDpIinLibHeZJnn SK76JlBG2QbdoWOvH7VKz3eR6F0/eWQy7B5sPkNKNCQjaXqIg860yLh8+8rllfDBub3D USd4m1MG4cbYv5YEDIGmO/0u5a+SJ52vGBjXRAgY3+IO9ykS8ykA54+XFVsG2VR59ZgA 1fc8h/DpCNHHEEucmpMxpr1pJ7QlCBEYaAcJ6luG4+QZGSE8SB/1mzhUxUDWlvoh/L2a BF9w== 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=zMrckJWET3alSVSflN8YLxc9BaB0hu5GLULu4Dgnyvc=; b=lzuKzDXOSGnZzh5lgMerR+UzlR9Fz/GnsxCAH09/5T3ZKC1Oq1e5mIe2fLWNZM1UlI dpOSxeFFvqSMOZn4ueYKAh5HzvOTmRTe0bBHzja2uOA/30vowEB8CpvFhqqJe6VYVH8W B/RcdJnpl7fB+ATpQnFYtB2Qaw5zh+mTVF3OSyuZx2WTltYea4EiPQXPcUq7D0MnF7zw BiZncgpFzXSUtPW3gT/wQ9EJ2VLnINQntjo6+xFUx1zisPAO/pdg0Cp/1wPtIYVgYSWz VZQD/TPP+7dz0qMnc77RNy/pLwguX3+UMUPU+/fhsKeIH9Zyfi08eNvaBpl9bu+WyQd2 Uv+Q== X-Gm-Message-State: AO0yUKX41qk98kmPsQygFJv04PJtxvX+tWV4fqPgiAp91JUG58jd9DzN Ut0mP+EBkuLN17mS+dvx1+THnw== X-Google-Smtp-Source: AK7set84FFWzT2dGdx75kU8tDpAXFXKGLlclCgOa7dyrEnmtqD9DITQFPQx4Zkhz8zMzRViOZf8ELA== X-Received: by 2002:adf:decc:0:b0:2bf:b119:e6e2 with SMTP id i12-20020adfdecc000000b002bfb119e6e2mr8850319wrn.47.1674749108620; Thu, 26 Jan 2023 08:05:08 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:08 -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 v2 01/17] android: boot: rename andr_img_hdr -> andr_boot_img_hdr_v0 Date: Thu, 26 Jan 2023 17:04:50 +0100 Message-Id: <20230126160506.1026643-2-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 Android introduced boot header version 3 or 4. The header structure change with version 3 and 4 to support the new updates such as: - Introducing Vendor boot image: with a vendor ramdisk - Bootconfig feature (v4) To maintain support for version v0, v1 and v2 while introducing version 3 and 4, this struct name must change to refer to the header structure before v3. Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- boot/image-android.c | 26 +++++++++++++------------- boot/image-fdt.c | 2 +- cmd/abootimg.c | 4 ++-- drivers/fastboot/fb_mmc.c | 8 ++++---- include/android_image.h | 4 ++-- include/image.h | 18 +++++++++--------- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/boot/image-android.c b/boot/image-android.c index 2628db3741..8c0a304cc0 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -18,7 +18,7 @@ static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1]; -static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr) +static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0 *hdr) { /* * All the Android tools that generate a boot.img use this @@ -59,7 +59,7 @@ static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr) * Return: Zero, os start address and length on success, * otherwise on failure. */ -int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify, +int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify, ulong *os_data, ulong *os_len) { u32 kernel_addr = android_image_get_kernel_addr(hdr); @@ -122,12 +122,12 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify, return 0; } -int android_image_check_header(const struct andr_img_hdr *hdr) +int android_image_check_header(const struct andr_boot_img_hdr_v0 *hdr) { return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE); } -ulong android_image_get_end(const struct andr_img_hdr *hdr) +ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr) { ulong end; @@ -150,12 +150,12 @@ ulong android_image_get_end(const struct andr_img_hdr *hdr) return end; } -ulong android_image_get_kload(const struct andr_img_hdr *hdr) +ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr) { return android_image_get_kernel_addr(hdr); } -ulong android_image_get_kcomp(const struct andr_img_hdr *hdr) +ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr) { const void *p = (void *)((uintptr_t)hdr + hdr->page_size); @@ -167,7 +167,7 @@ ulong android_image_get_kcomp(const struct andr_img_hdr *hdr) return image_decomp_type(p, sizeof(u32)); } -int android_image_get_ramdisk(const struct andr_img_hdr *hdr, +int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr, ulong *rd_data, ulong *rd_len) { if (!hdr->ramdisk_size) { @@ -186,7 +186,7 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr, return 0; } -int android_image_get_second(const struct andr_img_hdr *hdr, +int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr, ulong *second_data, ulong *second_len) { if (!hdr->second_size) { @@ -226,7 +226,7 @@ int android_image_get_second(const struct andr_img_hdr *hdr, */ bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size) { - const struct andr_img_hdr *hdr; + const struct andr_boot_img_hdr_v0 *hdr; ulong dtbo_img_addr; bool ret = true; @@ -275,7 +275,7 @@ exit: */ static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong *addr) { - const struct andr_img_hdr *hdr; + const struct andr_boot_img_hdr_v0 *hdr; ulong dtb_img_addr; bool ret = true; @@ -328,7 +328,7 @@ exit: bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, u32 *size) { - const struct andr_img_hdr *hdr; + const struct andr_boot_img_hdr_v0 *hdr; bool res; ulong dtb_img_addr; /* address of DTB part in boot image */ u32 dtb_img_size; /* size of DTB payload in boot image */ @@ -393,7 +393,7 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, * returns: * no returned results */ -void android_print_contents(const struct andr_img_hdr *hdr) +void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr) { const char * const p = IMAGE_INDENT_STRING; /* os_version = ver << 11 | lvl */ @@ -485,7 +485,7 @@ static bool android_image_print_dtb_info(const struct fdt_header *fdt, */ bool android_image_print_dtb_contents(ulong hdr_addr) { - const struct andr_img_hdr *hdr; + const struct andr_boot_img_hdr_v0 *hdr; bool res; ulong dtb_img_addr; /* address of DTB part in boot image */ u32 dtb_img_size; /* size of DTB payload in boot image */ diff --git a/boot/image-fdt.c b/boot/image-fdt.c index b830a0ab41..1181cb60f0 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -529,7 +529,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, } #ifdef CONFIG_ANDROID_BOOT_IMAGE } else if (genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) { - struct andr_img_hdr *hdr = buf; + struct andr_boot_img_hdr_v0 *hdr = buf; ulong fdt_data, fdt_len; u32 fdt_size, dtb_idx; /* diff --git a/cmd/abootimg.c b/cmd/abootimg.c index f48a9dcb02..0262adb1e5 100644 --- a/cmd/abootimg.c +++ b/cmd/abootimg.c @@ -18,7 +18,7 @@ static ulong _abootimg_addr = -1; static int abootimg_get_ver(int argc, char *const argv[]) { - const struct andr_img_hdr *hdr; + const struct andr_boot_img_hdr_v0 *hdr; int res = CMD_RET_SUCCESS; if (argc > 1) @@ -65,7 +65,7 @@ static int abootimg_get_recovery_dtbo(int argc, char *const argv[]) static int abootimg_get_dtb_load_addr(int argc, char *const argv[]) { - const struct andr_img_hdr *hdr; + const struct andr_boot_img_hdr_v0 *hdr; int res = CMD_RET_SUCCESS; if (argc > 1) diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index 033c510bc0..6d0112fdf4 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -287,7 +287,7 @@ static void fb_mmc_boot_ops(struct blk_desc *dev_desc, void *buffer, */ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc, struct disk_partition *info, - struct andr_img_hdr *hdr, + struct andr_boot_img_hdr_v0 *hdr, char *response) { ulong sector_size; /* boot partition sector size */ @@ -296,7 +296,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc, /* Calculate boot image sectors count */ sector_size = info->blksz; - hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size); + hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_boot_img_hdr_v0), sector_size); if (hdr_sectors == 0) { pr_err("invalid number of boot sectors: 0\n"); fastboot_fail("invalid number of boot sectors: 0", response); @@ -338,7 +338,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc, char *response) { uintptr_t hdr_addr; /* boot image header address */ - struct andr_img_hdr *hdr; /* boot image header */ + struct andr_boot_img_hdr_v0 *hdr; /* boot image header */ lbaint_t hdr_sectors; /* boot image header sectors */ u8 *ramdisk_buffer; u32 ramdisk_sector_start; @@ -361,7 +361,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc, /* Put boot image header in fastboot buffer after downloaded zImage */ hdr_addr = (uintptr_t)download_buffer + ALIGN(download_bytes, PAGE_SIZE); - hdr = (struct andr_img_hdr *)hdr_addr; + hdr = (struct andr_boot_img_hdr_v0 *)hdr_addr; /* Read boot image header */ hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr, response); diff --git a/include/android_image.h b/include/android_image.h index 54d25af068..2bdcab9122 100644 --- a/include/android_image.h +++ b/include/android_image.h @@ -20,9 +20,9 @@ #define ANDR_BOOT_ARGS_SIZE 512 #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024 -/* The bootloader expects the structure of andr_img_hdr with header +/* The bootloader expects the structure of andr_boot_img_hdr_v0 with header * version 0 to be as follows: */ -struct andr_img_hdr { +struct andr_boot_img_hdr_v0 { /* Must be ANDR_BOOT_MAGIC. */ char magic[ANDR_BOOT_MAGIC_SIZE]; diff --git a/include/image.h b/include/image.h index 7717a4c13d..bcb24d92de 100644 --- a/include/image.h +++ b/include/image.h @@ -1734,21 +1734,21 @@ int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo); struct cipher_algo *image_get_cipher_algo(const char *full_name); -struct andr_img_hdr; -int android_image_check_header(const struct andr_img_hdr *hdr); -int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify, +struct andr_boot_img_hdr_v0; +int android_image_check_header(const struct andr_boot_img_hdr_v0 *hdr); +int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify, ulong *os_data, ulong *os_len); -int android_image_get_ramdisk(const struct andr_img_hdr *hdr, +int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr, ulong *rd_data, ulong *rd_len); -int android_image_get_second(const struct andr_img_hdr *hdr, +int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr, ulong *second_data, ulong *second_len); bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size); bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, u32 *size); -ulong android_image_get_end(const struct andr_img_hdr *hdr); -ulong android_image_get_kload(const struct andr_img_hdr *hdr); -ulong android_image_get_kcomp(const struct andr_img_hdr *hdr); -void android_print_contents(const struct andr_img_hdr *hdr); +ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr); +ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr); +ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr); +void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr); bool android_image_print_dtb_contents(ulong hdr_addr); /** From patchwork Thu Jan 26 16:04:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732360 X-Patchwork-Delegate: sjg@chromium.org 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (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=laQ9qkOD; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4P2lvp2wgsz23h7 for ; Fri, 27 Jan 2023 03:07:02 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1D373856E4; Thu, 26 Jan 2023 17:06:50 +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="laQ9qkOD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5D34785559; Thu, 26 Jan 2023 17:05:16 +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-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (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 D8F54856CC for ; Thu, 26 Jan 2023 17:05:09 +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-x433.google.com with SMTP id q10so2267409wrm.4 for ; Thu, 26 Jan 2023 08:05:09 -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=XEYa4uq/LNcQt/kyiYg84u99Ev0QZlFiR6BAWnhk6rc=; b=laQ9qkODG/+7TtoJlAJ404eEiR3w9ovHik4bDypNahBEDrhn/Rb9MRO0Xlstp/qUun KmRMwX7kRalqrDsljPVmCisvPmxH+RAg3QShW+saXGuykHFekV4GPncNe9nr1zMWgC4r 90LFR3bg1MugcrfeZ8oBjrucYzUyEVVrH6GBfyovm50tGDz+eKC+lMwABKbBn+ODCgCw V01NQ/Fwt0wMV+7AWb8ebpkKFUVvOADhEfqg5VIOIFDE/D1o8asdexpaisku+JIwWazk emBR9mPAZQBu2EPylcQNAk4VCi3tSrcDsJIzOPiVUuz37gj7oHq3uQDjwPgLMGoA8qxQ td1g== 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=XEYa4uq/LNcQt/kyiYg84u99Ev0QZlFiR6BAWnhk6rc=; b=kNGh3K8tSV1BzZ7hZ2XWoaR+G0kQgwk+ilMSvLDi8Nv9wOv+3yMjQfmaPTmW62WK/5 AVe8+dYBXITQhgMhwPwfVlxNjpIZZNraypf7y6GoFrKhw/o3925mCE8XbMKA4y9hX7hS f5lDZ3kCdZC3qKRYbEVJYYNI0ZB7r5Gok0EsltSeIvm3R4z1NKmY1FYb5klQ/g8oafPK zZSnklosdZ9junN7U7y3JUJQp8x+X6sap3OW3GvKo2zC43/3Yt2yN3NZCBqXeRbR3EJY EsE0tH22N/KBYftK+WilhDnhHjxd7EGyHy6SHURrPQVqbmL2T1Cc80yKWjago6Lf0sFa nFDA== X-Gm-Message-State: AO0yUKXB6Wnwdij5xOX32HxrJ6cKOMFyasXEZubOJd/r1Ivag8mwrcNh 2wTyBaKXf8rApoc0MZJGr9OocA== X-Google-Smtp-Source: AK7set8BFZnJw/fatN+qcFPhznTfvb+YAIrW22iZHEAs1J6mUxPbuhTKw3vSXMaC1dYYufyjNbG/lQ== X-Received: by 2002:adf:f286:0:b0:2bf:b5ea:8d66 with SMTP id k6-20020adff286000000b002bfb5ea8d66mr7372907wro.16.1674749109592; Thu, 26 Jan 2023 08:05:09 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:09 -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 v2 02/17] android: boot: support vendor boot image in abootimg Date: Thu, 26 Jan 2023 17:04:51 +0100 Message-Id: <20230126160506.1026643-3-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 Vendor boot image is introduced in boot image header version 3 and 4. Please check [1] for more details. To prepare for boot image v3/v4 support, allow the abootimg command to store the vendor_boot image address. Full support for this new format will be done in a future patch. Link:[1] https://source.android.com/docs/core/architecture/bootloader/partitions/vendor-boot-partitions Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- cmd/abootimg.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/abootimg.c b/cmd/abootimg.c index 0262adb1e5..026c03f91c 100644 --- a/cmd/abootimg.c +++ b/cmd/abootimg.c @@ -15,6 +15,7 @@ /* Please use abootimg_addr() macro to obtain the boot image address */ static ulong _abootimg_addr = -1; +static ulong _avendor_bootimg_addr = -1; static int abootimg_get_ver(int argc, char *const argv[]) { @@ -158,7 +159,7 @@ static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc, char *endp; ulong img_addr; - if (argc != 2) + if (argc < 2 || argc > 3) return CMD_RET_USAGE; img_addr = hextoul(argv[1], &endp); @@ -168,6 +169,17 @@ static int do_abootimg_addr(struct cmd_tbl *cmdtp, int flag, int argc, } _abootimg_addr = img_addr; + + if (argc == 3) { + img_addr = simple_strtoul(argv[2], &endp, 16); + if (*endp != '\0') { + printf("Error: Wrong vendor image address\n"); + return CMD_RET_FAILURE; + } + + _avendor_bootimg_addr = img_addr; + } + return CMD_RET_SUCCESS; } @@ -211,7 +223,7 @@ static int do_abootimg_dump(struct cmd_tbl *cmdtp, int flag, int argc, } static struct cmd_tbl cmd_abootimg_sub[] = { - U_BOOT_CMD_MKENT(addr, 2, 1, do_abootimg_addr, "", ""), + U_BOOT_CMD_MKENT(addr, 3, 1, do_abootimg_addr, "", ""), U_BOOT_CMD_MKENT(dump, 2, 1, do_abootimg_dump, "", ""), U_BOOT_CMD_MKENT(get, 5, 1, do_abootimg_get, "", ""), }; @@ -239,7 +251,7 @@ static int do_abootimg(struct cmd_tbl *cmdtp, int flag, int argc, U_BOOT_CMD( abootimg, CONFIG_SYS_MAXARGS, 0, do_abootimg, "manipulate Android Boot Image", - "addr \n" + "addr []>\n" " - set the address in RAM where boot image is located\n" " ($loadaddr is used by default)\n" "abootimg dump dtb\n" From patchwork Thu Jan 26 16:04:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732359 X-Patchwork-Delegate: sjg@chromium.org 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (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=zmFP0c0j; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4P2lvW47D2z23h7 for ; Fri, 27 Jan 2023 03:06:47 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8BB9B85705; Thu, 26 Jan 2023 17:06:35 +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="zmFP0c0j"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 44E77856CC; Thu, 26 Jan 2023 17:05:17 +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-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) (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 1E161856D3 for ; Thu, 26 Jan 2023 17:05:11 +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-x42a.google.com with SMTP id m7so2249747wru.8 for ; Thu, 26 Jan 2023 08:05:11 -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=CxMipMGsa8g7I5hck5BNlvgoNy6AF3X1YcJpSSye1vs=; b=zmFP0c0j2l6yW71/rqHx1uokXpnPkL5Qi1zKDRyIhs4Qi3rhj/Vlqzw6nkNp5lxOVO vTe30LlTh6COzsga1z4NBNv3viThn+zIpATXnwTFVyN/VjE51uBpEz+s7CSqh+crUro7 9EK3SDXKpnN+c6LizQDuX8kj7IS+PeUhWgBkoOaBGwKMzlxaHUmbmHPlloGPraz02D7B nSRU77X6Y68lOORT+KKeN7bYkxymefBflRllJ5xpP2b/kp/YQexzkW+PSLdltsG+XIDD G4UHBwaNaqbuq1uE/5ZClNqQeZkEq+cJ1LCkBvv29lGI3YcbISL/7affQ8I85xHIP8bK v3+A== 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=CxMipMGsa8g7I5hck5BNlvgoNy6AF3X1YcJpSSye1vs=; b=pX4e2zfhPOPMbeuK1p1EHy6kQdkJTZC43/tRhdm7Fz1h16rZV/mEsw1JXt13jKmKq+ FCtM7a4JDrkvqK7AUlGxgkdDEUicgM8v6CBugrzb9DMlRZbvm76mGs/3Dc4B6Mv80gXP eQokJzHOpYksu26qU4Qj0qFbrk3sPHlu7i9s9pkKy4W6KpaX2GmqgrvoEh6JAuFdN55w NCCINW9JYHyh27rKw03qqworr3JX7Mw4s/tuS4tYCHxFRz1LT9zgmbLu9oXn+PaGaeHW KB7mJbZwJagT+cZDIUzOVI4v/1Shfoe7zFlLq7FAIjKh4zw2PlxX3p7MFB6mH3gaiKyn GakA== X-Gm-Message-State: AFqh2kq0zEoTgqjXEA+kv99t7mHX5YN2lGzolRLwEfcmdRdFr/G3VBKk OIkkLy/jFD3BNJCybLwm5VfVDg== X-Google-Smtp-Source: AMrXdXurJ/7spT0G5KzMKES6RoVzNeaKMrKIp5mW6pA/ij/T69n/KsSdOEimGYbor0M9E/wdzwzMJA== X-Received: by 2002:a05:6000:a03:b0:244:48b3:d138 with SMTP id co3-20020a0560000a0300b0024448b3d138mr35662739wrb.54.1674749110341; Thu, 26 Jan 2023 08:05:10 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:10 -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 v2 03/17] android: boot: replace android_image_check_header Date: Thu, 26 Jan 2023 17:04:52 +0100 Message-Id: <20230126160506.1026643-4-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 With the new vendor boot image introduced in versions 3 and 4 of boot image header, the header check must be done for both boot image and vendor boot image. Thus, android_image_check_header() is being replaced by is_android_boot_image_header() to only refer to boot image header check. Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- boot/image-android.c | 8 ++++---- boot/image-board.c | 2 +- cmd/abootimg.c | 4 ++-- drivers/fastboot/fb_mmc.c | 3 +-- include/image.h | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/boot/image-android.c b/boot/image-android.c index 8c0a304cc0..ed51e8b47e 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -122,9 +122,9 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify, return 0; } -int android_image_check_header(const struct andr_boot_img_hdr_v0 *hdr) +bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr) { - return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE); + return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE); } ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr) @@ -231,7 +231,7 @@ bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size) bool ret = true; hdr = map_sysmem(hdr_addr, sizeof(*hdr)); - if (android_image_check_header(hdr)) { + if (!is_android_boot_image_header(hdr)) { printf("Error: Boot Image header is incorrect\n"); ret = false; goto exit; @@ -280,7 +280,7 @@ static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong *addr) bool ret = true; hdr = map_sysmem(hdr_addr, sizeof(*hdr)); - if (android_image_check_header(hdr)) { + if (!is_android_boot_image_header(hdr)) { printf("Error: Boot Image header is incorrect\n"); ret = false; goto exit; diff --git a/boot/image-board.c b/boot/image-board.c index e5d71a3d54..9295b6d0c8 100644 --- a/boot/image-board.c +++ b/boot/image-board.c @@ -284,7 +284,7 @@ int genimg_get_format(const void *img_addr) return IMAGE_FORMAT_FIT; } if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE) && - !android_image_check_header(img_addr)) + is_android_boot_image_header(img_addr)) return IMAGE_FORMAT_ANDROID; return IMAGE_FORMAT_INVALID; diff --git a/cmd/abootimg.c b/cmd/abootimg.c index 026c03f91c..b5cfb141ef 100644 --- a/cmd/abootimg.c +++ b/cmd/abootimg.c @@ -26,7 +26,7 @@ static int abootimg_get_ver(int argc, char *const argv[]) return CMD_RET_USAGE; hdr = map_sysmem(abootimg_addr(), sizeof(*hdr)); - if (android_image_check_header(hdr)) { + if (!is_android_boot_image_header(hdr)) { printf("Error: Boot Image header is incorrect\n"); res = CMD_RET_FAILURE; goto exit; @@ -73,7 +73,7 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[]) return CMD_RET_USAGE; hdr = map_sysmem(abootimg_addr(), sizeof(*hdr)); - if (android_image_check_header(hdr)) { + if (!is_android_boot_image_header(hdr)) { printf("Error: Boot Image header is incorrect\n"); res = CMD_RET_FAILURE; goto exit; diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index 6d0112fdf4..086e5f7843 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -313,8 +313,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc, } /* Check boot header magic string */ - res = android_image_check_header(hdr); - if (res != 0) { + if (!is_android_boot_image_header(hdr)) { pr_err("bad boot image magic\n"); fastboot_fail("boot partition not initialized", response); return 0; diff --git a/include/image.h b/include/image.h index bcb24d92de..c1594ee169 100644 --- a/include/image.h +++ b/include/image.h @@ -1735,7 +1735,6 @@ int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo); struct cipher_algo *image_get_cipher_algo(const char *full_name); struct andr_boot_img_hdr_v0; -int android_image_check_header(const struct andr_boot_img_hdr_v0 *hdr); int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify, ulong *os_data, ulong *os_len); int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr, @@ -1750,6 +1749,7 @@ ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr); ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr); void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr); bool android_image_print_dtb_contents(ulong hdr_addr); +bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr); /** * board_fit_config_name_match() - Check for a matching board name From patchwork Thu Jan 26 16:04:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732361 X-Patchwork-Delegate: sjg@chromium.org 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=pass (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=DZBub2eV; 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 4P2lw51WFKz23h7 for ; Fri, 27 Jan 2023 03:07:17 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BD5A8856F6; Thu, 26 Jan 2023 17:07:04 +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="DZBub2eV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B49E785559; Thu, 26 Jan 2023 17:05:28 +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-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (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 65734856D5 for ; Thu, 26 Jan 2023 17:05:11 +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-x433.google.com with SMTP id q10so2267497wrm.4 for ; Thu, 26 Jan 2023 08:05:11 -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=CZ2pNnCKlfM7oNYCDdXiv7M6HRdQ/59lVBYEqk/lcOk=; b=DZBub2eVGVI7SneNrwj+hp6GtQyDQm4ncp5AWvJYtjswijf9RyWJRNwf55jIX9txGa zCBL5O0GHw10Iu8VxsvzdohDCTjEFKwnP4U7PMqzZoFrAmyB/4Spk/Fjamd/3m4gjrZp jN8SvDWIaczH2wj2hN8iimQmQuhXg5WZC+fujEu13iUMFQxFEH2w0IdSU0BD59oMJuXd TrGXTVLbJyfa7q86mLIxYJyWQ+ITdaK/7lwEqFtyYqTm5vz12wCm4/goozTknnjWpM8S c3K7zGbUyXWFv1EpaJyivmNIq2b1pS+futayPf8Iz1ACCzpMfdGXQZ5DdsnWe/rR+Ml1 G32w== 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=CZ2pNnCKlfM7oNYCDdXiv7M6HRdQ/59lVBYEqk/lcOk=; b=GxqvoaRVHM1WGVGcKSq65mow5k9zB/WCdV4BhG9ouyMf2jCkc3j1sk6q4j3jbDjTZ1 egrLU2zrFRTLYT00xtpto6PMdqRPpl9rh1gYS0z66xrgkZg4OK1uAXhHraKXr6dxV/R0 3jcDCGh8auxyTE45nhF+gcbIAxbxZev/rs8Bh1lOxC51UQ2gj+MA5KUNncwMEUSkndXU xa2dZ7b0ZtJbrkHzaQVk+bL6SN7mPJXT3hULsaPYlLDBHC3CZlJTUIoxvsfHnqwcfeEQ VttGtUgcAvO2x7xN15MAjwNig+KeKuHcx3yraPFuQUz8NwXMCIdp/DxpM840embF1EOF ftqA== X-Gm-Message-State: AO0yUKU4T9COczAYk2sw6fZ2AL+ca+XUl5dFAC5BicOQ551nBixRc5rk LwGOjEUW5emxsJRbP/gUubbGFA== X-Google-Smtp-Source: AK7set/cG9jLI85mOWQ4sC4P/iyI4AtiojrRxKqQNL21PA/qEPf7ugGcAmhXu9UWtoDW032dP2KXaQ== X-Received: by 2002:adf:f791:0:b0:2bf:bcab:8e26 with SMTP id q17-20020adff791000000b002bfbcab8e26mr5049132wrp.63.1674749111003; Thu, 26 Jan 2023 08:05:11 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:10 -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 v2 04/17] android: boot: add boot image header v3 and v4 structures Date: Thu, 26 Jan 2023 17:04:53 +0100 Message-Id: <20230126160506.1026643-5-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 This adds support for v3/v4 boot image format by adding the following structures: - andr_boot_img_hdr_v3 : describes boot image header - andr_vendor_img_hdr : describes vendor boot image header These definitions have been copied over from the AOSP documentation at [1] and [2] Boot arg sizes are taken from [3]: commit: 35fb6262bc3f (ANDROID: Support for vendor boot) This also adds documentation for boot image header v3/v4 structure that was imported from [4], file: include/bootimg/bootimg.h commit: 8d0922bfb932 (Adding GKI signature in boot.img v4) Link:[1] https://source.android.com/docs/core/architecture/bootloader/boot-image-header Link:[2] https://source.android.com/docs/core/architecture/bootloader/partitions/vendor-boot-partitions#vendor-boot-header Link:[3] https://android.googlesource.com/platform/external/u-boot Link:[4] https://android.googlesource.com/platform/system/tools/mkbootimg Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- include/android_image.h | 183 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 182 insertions(+), 1 deletion(-) diff --git a/include/android_image.h b/include/android_image.h index 2bdcab9122..4fce363ff7 100644 --- a/include/android_image.h +++ b/include/android_image.h @@ -3,7 +3,7 @@ * This is from the Android Project, * Repository: https://android.googlesource.com/platform/system/tools/mkbootimg * File: include/bootimg/bootimg.h - * Commit: e55998a0f2b61b685d5eb4a486ca3a0c680b1a2f + * Commit: cce5b1923e3cd2fcb765b512610bdc5c42bc501d * * Copyright (C) 2007 The Android Open Source Project */ @@ -14,11 +14,58 @@ #include #include +#define ANDR_GKI_PAGE_SIZE 4096 #define ANDR_BOOT_MAGIC "ANDROID!" #define ANDR_BOOT_MAGIC_SIZE 8 #define ANDR_BOOT_NAME_SIZE 16 #define ANDR_BOOT_ARGS_SIZE 512 #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024 +#define VENDOR_BOOT_MAGIC "VNDRBOOT" +#define ANDR_VENDOR_BOOT_MAGIC_SIZE 8 +#define ANDR_VENDOR_BOOT_ARGS_SIZE 2048 +#define ANDR_VENDOR_BOOT_NAME_SIZE 16 + +struct andr_boot_img_hdr_v3 { + u8 magic[ANDR_BOOT_MAGIC_SIZE]; + + u32 kernel_size; /* size in bytes */ + u32 ramdisk_size; /* size in bytes */ + + u32 os_version; + + u32 header_size; /* size of boot image header in bytes */ + u32 reserved[4]; + u32 header_version; /* offset remains constant for version check */ + + u8 cmdline[ANDR_BOOT_ARGS_SIZE + ANDR_BOOT_EXTRA_ARGS_SIZE]; + /* for boot image header v4 only */ + u32 signature_size; /* size in bytes */ +}; + +struct andr_vendor_img_hdr { + u8 magic[ANDR_VENDOR_BOOT_MAGIC_SIZE]; + u32 header_version; + u32 page_size; /* flash page size we assume */ + + u32 kernel_addr; /* physical load addr */ + u32 ramdisk_addr; /* physical load addr */ + + u32 vendor_ramdisk_size; /* size in bytes */ + + u8 cmdline[ANDR_VENDOR_BOOT_ARGS_SIZE]; + + u32 tags_addr; /* physical addr for kernel tags */ + + u8 name[ANDR_VENDOR_BOOT_NAME_SIZE]; /* asciiz product name */ + u32 header_size; /* size of vendor boot image header in bytes */ + u32 dtb_size; /* size of dtb image */ + u64 dtb_addr; /* physical load address */ + /* for boot image header v4 only */ + u32 vendor_ramdisk_table_size; /* size in bytes for the vendor ramdisk table */ + u32 vendor_ramdisk_table_entry_num; /* number of entries in the vendor ramdisk table */ + u32 vendor_ramdisk_table_entry_size; /* size in bytes for a vendor ramdisk table entry */ + u32 bootconfig_size; /* size in bytes for the bootconfig section */ +}; /* The bootloader expects the structure of andr_boot_img_hdr_v0 with header * version 0 to be as follows: */ @@ -136,4 +183,138 @@ struct andr_boot_img_hdr_v0 { * else: jump to kernel_addr */ +/* When the boot image header has a version of 3, the structure of the boot + * image is as follows: + * + * +---------------------+ + * | boot header | 4096 bytes + * +---------------------+ + * | kernel | m pages + * +---------------------+ + * | ramdisk | n pages + * +---------------------+ + * + * m = (kernel_size + 4096 - 1) / 4096 + * n = (ramdisk_size + 4096 - 1) / 4096 + * + * Note that in version 3 of the boot image header, page size is fixed at 4096 bytes. + * + * The structure of the vendor boot image (introduced with version 3 and + * required to be present when a v3 boot image is used) is as follows: + * + * +---------------------+ + * | vendor boot header | o pages + * +---------------------+ + * | vendor ramdisk | p pages + * +---------------------+ + * | dtb | q pages + * +---------------------+ + * o = (2112 + page_size - 1) / page_size + * p = (vendor_ramdisk_size + page_size - 1) / page_size + * q = (dtb_size + page_size - 1) / page_size + * + * 0. all entities in the boot image are 4096-byte aligned in flash, all + * entities in the vendor boot image are page_size (determined by the vendor + * and specified in the vendor boot image header) aligned in flash + * 1. kernel, ramdisk, vendor ramdisk, and DTB are required (size != 0) + * 2. load the kernel and DTB at the specified physical address (kernel_addr, + * dtb_addr) + * 3. load the vendor ramdisk at ramdisk_addr + * 4. load the generic ramdisk immediately following the vendor ramdisk in + * memory + * 5. set up registers for kernel entry as required by your architecture + * 6. if the platform has a second stage bootloader jump to it (must be + * contained outside boot and vendor boot partitions), otherwise + * jump to kernel_addr + */ + +/* When the boot image header has a version of 4, the structure of the boot + * image is as follows: + * + * +---------------------+ + * | boot header | 4096 bytes + * +---------------------+ + * | kernel | m pages + * +---------------------+ + * | ramdisk | n pages + * +---------------------+ + * | boot signature | g pages + * +---------------------+ + * + * m = (kernel_size + 4096 - 1) / 4096 + * n = (ramdisk_size + 4096 - 1) / 4096 + * g = (signature_size + 4096 - 1) / 4096 + * + * Note that in version 4 of the boot image header, page size is fixed at 4096 + * bytes. + * + * The structure of the vendor boot image version 4, which is required to be + * present when a version 4 boot image is used, is as follows: + * + * +------------------------+ + * | vendor boot header | o pages + * +------------------------+ + * | vendor ramdisk section | p pages + * +------------------------+ + * | dtb | q pages + * +------------------------+ + * | vendor ramdisk table | r pages + * +------------------------+ + * | bootconfig | s pages + * +------------------------+ + * + * o = (2128 + page_size - 1) / page_size + * p = (vendor_ramdisk_size + page_size - 1) / page_size + * q = (dtb_size + page_size - 1) / page_size + * r = (vendor_ramdisk_table_size + page_size - 1) / page_size + * s = (vendor_bootconfig_size + page_size - 1) / page_size + * + * Note that in version 4 of the vendor boot image, multiple vendor ramdisks can + * be included in the vendor boot image. The bootloader can select a subset of + * ramdisks to load at runtime. To help the bootloader select the ramdisks, each + * ramdisk is tagged with a type tag and a set of hardware identifiers + * describing the board, soc or platform that this ramdisk is intended for. + * + * The vendor ramdisk section is consist of multiple ramdisk images concatenated + * one after another, and vendor_ramdisk_size is the size of the section, which + * is the total size of all the ramdisks included in the vendor boot image. + * + * The vendor ramdisk table holds the size, offset, type, name and hardware + * identifiers of each ramdisk. The type field denotes the type of its content. + * The vendor ramdisk names are unique. The hardware identifiers are specified + * in the board_id field in each table entry. The board_id field is consist of a + * vector of unsigned integer words, and the encoding scheme is defined by the + * hardware vendor. + * + * For the different type of ramdisks, there are: + * - VENDOR_RAMDISK_TYPE_NONE indicates the value is unspecified. + * - VENDOR_RAMDISK_TYPE_PLATFORM ramdisks contain platform specific bits, so + * the bootloader should always load these into memory. + * - VENDOR_RAMDISK_TYPE_RECOVERY ramdisks contain recovery resources, so + * the bootloader should load these when booting into recovery. + * - VENDOR_RAMDISK_TYPE_DLKM ramdisks contain dynamic loadable kernel + * modules. + * + * Version 4 of the vendor boot image also adds a bootconfig section to the end + * of the image. This section contains Boot Configuration parameters known at + * build time. The bootloader is responsible for placing this section directly + * after the generic ramdisk, followed by the bootconfig trailer, before + * entering the kernel. + * + * 0. all entities in the boot image are 4096-byte aligned in flash, all + * entities in the vendor boot image are page_size (determined by the vendor + * and specified in the vendor boot image header) aligned in flash + * 1. kernel, ramdisk, and DTB are required (size != 0) + * 2. load the kernel and DTB at the specified physical address (kernel_addr, + * dtb_addr) + * 3. load the vendor ramdisks at ramdisk_addr + * 4. load the generic ramdisk immediately following the vendor ramdisk in + * memory + * 5. load the bootconfig immediately following the generic ramdisk. Add + * additional bootconfig parameters followed by the bootconfig trailer. + * 6. set up registers for kernel entry as required by your architecture + * 7. if the platform has a second stage bootloader jump to it (must be + * contained outside boot and vendor boot partitions), otherwise + * jump to kernel_addr + */ #endif From patchwork Thu Jan 26 16:04:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732358 X-Patchwork-Delegate: sjg@chromium.org 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=pass (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=T7oO3lO7; 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 4P2lvD3lpmz23h7 for ; Fri, 27 Jan 2023 03:06:32 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6DF87856D5; Thu, 26 Jan 2023 17:06:25 +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="T7oO3lO7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F1A6A856FA; Thu, 26 Jan 2023 17:05:24 +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-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 48AC6856E5 for ; Thu, 26 Jan 2023 17:05:12 +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-x431.google.com with SMTP id d14so2248604wrr.9 for ; Thu, 26 Jan 2023 08:05:12 -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=URpn/CiL4EFrsaM1CNaA9/fk/wyhI5k/BHOS9kUiY28=; b=T7oO3lO7AZpD4EuRLvfKK4yGRxhzGRJvicECAmgY2OaD/URXM+iNlvdIeV1mKBngh5 tLGEKRYanunv/bCbZtfswX7P62gcaYXyjmIhyYltdXfIBYT0o/vN4rn+dtCbXcTUF/2A EK9yBbilT53wJIrgSkgUHAxWPKGEk+gBkFdb9fvWtqkIoL6o/siGda3GDUQMeZSZAYht jdbOsQnppJXvFz/Bero+QnhqHj8OMZYuVa6k5ghfyy9+iKzGDAJV+nn+/NYnz2KdNerc pCJ7ROnQtX0T+rh7UyuOoETJJxQWJYv6VejCkC9YwBrKMO7NBItvBo8CX16MA9lKenFc JJwQ== 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=URpn/CiL4EFrsaM1CNaA9/fk/wyhI5k/BHOS9kUiY28=; b=4RQsOh/Wu5ZqTyio/e5sJuV/ut/2IS0I7o5ArecSegHX7cMKCKj4ttLfHXRBdHy+jd Zf+EpsyAEWzq9c+nXb1WPeCZX5c8PhKS2bKSSNXjqCXHRkFs8FKvA3w5mkm3miBt7jkU 7UDVkwtQVHF0n5g4U8a1WDHm3VWG4r++mPsHemTJBjTv/W2nszBzVhhjad5wgde+VfwB hcikl76P5y3CastLlrAF9PRpA9/aZBkqwPXMOJkvC+Mf/SShgpQIiWg/oFWEvK6FVDsD WZ0mVcbPHTdMR001dG9AjN/Xa1MaVgOuGKWSLQfa6qCU1mZ0bRvbrZTpmtoreWehmz+x w77A== X-Gm-Message-State: AO0yUKX1EFY81/iSeybhKzLNVo87STRkdGvUPHXgWbXhT0SY9DZR5NE9 nj9ZFyxEmbLcrTeOqN1prfHBuA== X-Google-Smtp-Source: AK7set/w64VSEbQifYIWeQrqTU30TNkQJRPW9eR6qyy67jejf8vUdwmVsxZTOkGz7qi4bdsczIdmJw== X-Received: by 2002:a5d:6dd2:0:b0:2bf:b0e6:f463 with SMTP id d18-20020a5d6dd2000000b002bfb0e6f463mr8553732wrz.13.1674749111667; Thu, 26 Jan 2023 08:05:11 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:11 -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 v2 05/17] android: boot: kcomp: support andr_image_data Date: Thu, 26 Jan 2023 17:04:54 +0100 Message-Id: <20230126160506.1026643-6-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 andr_image_data structure is used as a global representation of boot image header structure. This new structure is introduced to support all boot header versions : v0,v1.v2.v3.v4 and will be used to support v3 and v4 while maitaining support for v0,v1,v2. The need of using andr_image_data comes from the change of header structure in both version 3 and 4. android_image_get_kcomp() is reworked to support this new struct. Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- boot/image-android.c | 75 ++++++++++++++++++++++++++++++++++++++++- include/android_image.h | 27 +++++++++++++++ include/image.h | 2 ++ 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/boot/image-android.c b/boot/image-android.c index ed51e8b47e..487223d850 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -18,6 +18,74 @@ static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1]; +static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr_v0 *hdr, + struct andr_image_data *data) +{ + ulong end; + + data->image_name = hdr->name; + data->kcmdline = hdr->cmdline; + data->kernel_addr = hdr->kernel_addr; + data->ramdisk_addr = hdr->ramdisk_addr; + data->header_version = hdr->header_version; + data->dtb_load_addr = hdr->dtb_addr; + + end = (ulong)hdr; + + /* + * The header takes a full page, the remaining components are aligned + * on page boundary + */ + + end += hdr->page_size; + + data->kernel_ptr = end; + data->kernel_size = hdr->kernel_size; + end += ALIGN(hdr->kernel_size, hdr->page_size); + + data->ramdisk_ptr = end; + data->ramdisk_size = hdr->ramdisk_size; + end += ALIGN(hdr->ramdisk_size, hdr->page_size); + + data->second_ptr = end; + data->second_size = hdr->second_size; + end += ALIGN(hdr->second_size, hdr->page_size); + + if (hdr->header_version >= 1) { + data->recovery_dtbo_ptr = end; + data->recovery_dtbo_size = hdr->recovery_dtbo_size; + end += ALIGN(hdr->recovery_dtbo_size, hdr->page_size); + } + + if (hdr->header_version >= 2) { + data->dtb_ptr = end; + data->dtb_size = hdr->dtb_size; + end += ALIGN(hdr->dtb_size, hdr->page_size); + } + + data->boot_img_total_size = end - (ulong)hdr; +} + +bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data) +{ + if (!boot_hdr || !data) { + printf("boot_hdr or data params can't be NULL\n"); + return false; + } + + if (!is_android_boot_image_header(boot_hdr)) { + printf("Incorrect boot image header\n"); + 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 + android_boot_image_v0_v1_v2_parse_hdr(boot_hdr, data); + + return true; +} + static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0 *hdr) { /* @@ -157,8 +225,13 @@ ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr) ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr) { - const void *p = (void *)((uintptr_t)hdr + hdr->page_size); + struct andr_image_data img_data; + const void *p; + + if (!android_image_get_data(hdr, &img_data)) + return -EINVAL; + p = (const void *)img_data.kernel_ptr; if (image_get_magic((struct legacy_img_hdr *)p) == IH_MAGIC) return image_get_comp((struct legacy_img_hdr *)p); else if (get_unaligned_le32(p) == LZ4F_MAGIC) diff --git a/include/android_image.h b/include/android_image.h index 4fce363ff7..5b36f96d7b 100644 --- a/include/android_image.h +++ b/include/android_image.h @@ -317,4 +317,31 @@ struct andr_boot_img_hdr_v0 { * contained outside boot and vendor boot partitions), otherwise * jump to kernel_addr */ + +/* Private struct */ +struct andr_image_data { + ulong kernel_ptr; + u32 kernel_size; + u32 ramdisk_size; + u32 boot_ramdisk_size; + ulong second_ptr; + u32 second_size; + ulong dtb_ptr; + u32 dtb_size; + ulong recovery_dtbo_ptr; + u32 recovery_dtbo_size; + + const char *kcmdline; + const char *kcmdline_extra; + const char *image_name; + + u32 kernel_addr; + ulong ramdisk_addr; + ulong ramdisk_ptr; + ulong dtb_load_addr; + ulong tags_addr; + u32 header_version; + u32 boot_img_total_size; +}; + #endif diff --git a/include/image.h b/include/image.h index c1594ee169..9a0bd9d8f2 100644 --- a/include/image.h +++ b/include/image.h @@ -1733,7 +1733,9 @@ struct cipher_algo { int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo); struct cipher_algo *image_get_cipher_algo(const char *full_name); +struct andr_image_data; +bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data); struct andr_boot_img_hdr_v0; int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify, ulong *os_data, ulong *os_len); From patchwork Thu Jan 26 16:04:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732367 X-Patchwork-Delegate: sjg@chromium.org 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=pass (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=aFDFClVy; 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 4P2lxY4kVFz23h7 for ; Fri, 27 Jan 2023 03:08:33 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EFB298573A; Thu, 26 Jan 2023 17:07: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=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="aFDFClVy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 258B2856E8; Thu, 26 Jan 2023 17:05:27 +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-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) (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 42F33856E7 for ; Thu, 26 Jan 2023 17:05:13 +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-wm1-x334.google.com with SMTP id f12-20020a7bc8cc000000b003daf6b2f9b9so3532056wml.3 for ; Thu, 26 Jan 2023 08:05:13 -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=TSjlZHAN6OTAkr8+7kjB1MMAoNMKW8kPQ+mR1p+RCEI=; b=aFDFClVypklTnESl0F8QYiHYRbAXR/KQoiL+MkJVYXewq1IMBp6/4yXyOWlBo4103u aGozH5YlihZD3LMwPPjanVkEoYQnOczAvEmRfNySoM2LTWLoe+EgxyVK9IxQouN07OeR 2JNhLWKFoxBe5lYdaZQGKSUcCAkPbiA6qljV6szjiOipMPHgeQn8WJvwW8YYfkgoXVqa Uf48TXnyJA31lp+EGB3TIlpyDB8EtcZyZNN+rIioh0UvFaEMBp70K1BV/1xUwOqE4HAp x80wZlPB7eiMyKNFOGtoXEc7K4bCLR6GaP3dgXcasCMf44IBYO7l0rhe86R07GM7PDf+ u54w== 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=TSjlZHAN6OTAkr8+7kjB1MMAoNMKW8kPQ+mR1p+RCEI=; b=cPJdtTFpq+Q50ZBA/emnwdhfCUnjnk51NJ6Txe4onZl/vNNGLivzQDcdgp+jp/rt1R 8alRI36BxyVZrIIUNCsost95CLYWl0MEh/G8pZNd/NZWbBxk+UxwcE9zyx6EhJtHumSG +zrKNF45P1spXnH7xk3QXJsY5GsCAhjQL5Y8E65Oq1BqPy0ySFCfb+RlsxqyMldXuRO9 QjqOjvi8g2t1MoIiqHNN8Ek4CH4KD4WL/z8CZmzDmWl7tDyUxDmXnS3j4mc9FsLMeTan A8i6jEciCiNxMjHimncE3yz08N/4GlqHB0jnQ52XdRBRRvHWKvBBD+R6isjlWjf3fabn c92w== X-Gm-Message-State: AFqh2koqCLRZ/xVJ6yPEzVIsG4AmCssRZR94VjWNEwx+KXqsFyiA2khH IhcxO2lvD1RMychAV3bjQ143QQ== X-Google-Smtp-Source: AMrXdXvpWvEgK06sCcMXGeXDI6hQIM+7dzKqW+Gd3YU3obW4gJBM+htmiF8JY+/y8ZZucaFJAuLvjA== X-Received: by 2002:a05:600c:3088:b0:3da:1bb0:4d8a with SMTP id g8-20020a05600c308800b003da1bb04d8amr36739867wmn.16.1674749112462; Thu, 26 Jan 2023 08:05:12 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:12 -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 v2 06/17] android: boot: move to andr_image_data structure Date: Thu, 26 Jan 2023 17:04:55 +0100 Message-Id: <20230126160506.1026643-7-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 Move from andr_boot_img_hdr_v0 to andr_image_data structure to prepare for boot image header version 3 and 4. Signed-off-by: Safae Ouajih --- boot/image-android.c | 127 ++++++++++++++++++++++++------------------- cmd/abootimg.c | 31 ++++++----- include/image.h | 2 + 3 files changed, 89 insertions(+), 71 deletions(-) diff --git a/boot/image-android.c b/boot/image-android.c index 487223d850..9dab09a69a 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -86,7 +86,7 @@ bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data) return true; } -static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0 *hdr) +static ulong android_image_get_kernel_addr(struct andr_image_data *img_data) { /* * All the Android tools that generate a boot.img use this @@ -99,17 +99,17 @@ static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0 *hd * * Otherwise, we will return the actual value set by the user. */ - if (hdr->kernel_addr == ANDROID_IMAGE_DEFAULT_KERNEL_ADDR) - return (ulong)hdr + hdr->page_size; + if (img_data->kernel_addr == ANDROID_IMAGE_DEFAULT_KERNEL_ADDR) + return img_data->kernel_ptr; /* * abootimg creates images where all load addresses are 0 * and we need to fix them. */ - if (hdr->kernel_addr == 0 && hdr->ramdisk_addr == 0) + if (img_data->kernel_addr == 0 && img_data->ramdisk_addr == 0) return env_get_ulong("kernel_addr_r", 16, 0); - return hdr->kernel_addr; + return img_data->kernel_addr; } /** @@ -130,27 +130,33 @@ static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0 *hd int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify, ulong *os_data, ulong *os_len) { - u32 kernel_addr = android_image_get_kernel_addr(hdr); - const struct legacy_img_hdr *ihdr = (const struct legacy_img_hdr *) - ((uintptr_t)hdr + hdr->page_size); + struct andr_image_data img_data = {0}; + u32 kernel_addr; + const struct legacy_img_hdr *ihdr; + + if (!android_image_get_data(hdr, &img_data)) + return -EINVAL; + + kernel_addr = android_image_get_kernel_addr(&img_data); + ihdr = (const struct legacy_img_hdr *)img_data.kernel_ptr; /* * Not all Android tools use the id field for signing the image with * sha1 (or anything) so we don't check it. It is not obvious that the * string is null terminated so we take care of this. */ - strncpy(andr_tmp_str, hdr->name, ANDR_BOOT_NAME_SIZE); + strncpy(andr_tmp_str, img_data.image_name, ANDR_BOOT_NAME_SIZE); andr_tmp_str[ANDR_BOOT_NAME_SIZE] = '\0'; if (strlen(andr_tmp_str)) printf("Android's image name: %s\n", andr_tmp_str); printf("Kernel load addr 0x%08x size %u KiB\n", - kernel_addr, DIV_ROUND_UP(hdr->kernel_size, 1024)); + kernel_addr, DIV_ROUND_UP(img_data.kernel_size, 1024)); int len = 0; - if (*hdr->cmdline) { - printf("Kernel command line: %s\n", hdr->cmdline); - len += strlen(hdr->cmdline); + if (*img_data.kcmdline) { + printf("Kernel command line: %s\n", img_data.kcmdline); + len += strlen(img_data.kcmdline); } char *bootargs = env_get("bootargs"); @@ -168,8 +174,9 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify, strcpy(newbootargs, bootargs); strcat(newbootargs, " "); } - if (*hdr->cmdline) - strcat(newbootargs, hdr->cmdline); + + if (*img_data.kcmdline) + strcat(newbootargs, img_data.kcmdline); env_set("bootargs", newbootargs); @@ -177,15 +184,14 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify, if (image_get_magic(ihdr) == IH_MAGIC) { *os_data = image_get_data(ihdr); } else { - *os_data = (ulong)hdr; - *os_data += hdr->page_size; + *os_data = img_data.kernel_ptr; } } if (os_len) { if (image_get_magic(ihdr) == IH_MAGIC) *os_len = image_get_data_size(ihdr); else - *os_len = hdr->kernel_size; + *os_len = img_data.kernel_size; } return 0; } @@ -197,30 +203,25 @@ bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr) ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr) { - ulong end; - - /* - * The header takes a full page, the remaining components are aligned - * on page boundary - */ - end = (ulong)hdr; - end += hdr->page_size; - end += ALIGN(hdr->kernel_size, hdr->page_size); - end += ALIGN(hdr->ramdisk_size, hdr->page_size); - end += ALIGN(hdr->second_size, hdr->page_size); + struct andr_image_data img_data; - if (hdr->header_version >= 1) - end += ALIGN(hdr->recovery_dtbo_size, hdr->page_size); + if (!android_image_get_data(hdr, &img_data)) + return -EINVAL; - if (hdr->header_version >= 2) - end += ALIGN(hdr->dtb_size, hdr->page_size); + if (img_data.header_version > 2) + return 0; - return end; + return img_data.boot_img_total_size; } ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr) { - return android_image_get_kernel_addr(hdr); + struct andr_image_data img_data; + + if (!android_image_get_data(hdr, &img_data)) + return -EINVAL; + + return android_image_get_kernel_addr(&img_data); } ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr) @@ -243,38 +244,43 @@ ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr) int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr, ulong *rd_data, ulong *rd_len) { - if (!hdr->ramdisk_size) { + struct andr_image_data img_data = {0}; + + if (!android_image_get_data(hdr, &img_data)) + return -EINVAL; + + if (!img_data.ramdisk_size) { *rd_data = *rd_len = 0; return -1; } - printf("RAM disk load addr 0x%08x size %u KiB\n", - hdr->ramdisk_addr, DIV_ROUND_UP(hdr->ramdisk_size, 1024)); + printf("RAM disk load addr 0x%08lx size %u KiB\n", + img_data.ramdisk_ptr, DIV_ROUND_UP(img_data.ramdisk_size, 1024)); - *rd_data = (unsigned long)hdr; - *rd_data += hdr->page_size; - *rd_data += ALIGN(hdr->kernel_size, hdr->page_size); + *rd_data = img_data.ramdisk_ptr; - *rd_len = hdr->ramdisk_size; + *rd_len = img_data.ramdisk_size; return 0; } int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr, ulong *second_data, ulong *second_len) { - if (!hdr->second_size) { + struct andr_image_data img_data; + + if (!android_image_get_data(hdr, &img_data)) + return -EINVAL; + + if (!img_data.second_size) { *second_data = *second_len = 0; return -1; } - *second_data = (unsigned long)hdr; - *second_data += hdr->page_size; - *second_data += ALIGN(hdr->kernel_size, hdr->page_size); - *second_data += ALIGN(hdr->ramdisk_size, hdr->page_size); + *second_data = img_data.second_ptr; printf("second address is 0x%lx\n",*second_data); - *second_len = hdr->second_size; + *second_len = img_data.second_size; return 0; } @@ -339,6 +345,8 @@ exit: return ret; } +#if !defined(CONFIG_SPL_BUILD) +#ifdef CONFIG_CMD_ABOOTIMG /** * android_image_get_dtb_img_addr() - Get the address of DTB area in boot image. * @hdr_addr: Boot image header address @@ -385,6 +393,8 @@ exit: unmap_sysmem(hdr); return ret; } +#endif +#endif /** * android_image_get_dtb_by_index() - Get address and size of blob in DTB area. @@ -401,17 +411,22 @@ exit: bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, u32 *size) { + struct andr_image_data img_data; const struct andr_boot_img_hdr_v0 *hdr; - bool res; + + hdr = map_sysmem(hdr_addr, sizeof(*hdr)); + if (!android_image_get_data(hdr, &img_data)) { + unmap_sysmem(hdr); + return false; + } + unmap_sysmem(hdr); + ulong dtb_img_addr; /* address of DTB part in boot image */ u32 dtb_img_size; /* size of DTB payload in boot image */ ulong dtb_addr; /* address of DTB blob with specified index */ u32 i; /* index iterator */ - res = android_image_get_dtb_img_addr(hdr_addr, &dtb_img_addr); - if (!res) - return false; - + android_image_get_dtb_img_addr(hdr_addr, &dtb_img_addr); /* Check if DTB area of boot image is in DTBO format */ if (android_dt_check_header(dtb_img_addr)) { return android_dt_get_fdt_by_index(dtb_img_addr, index, addr, @@ -419,9 +434,7 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, } /* Find out the address of DTB with specified index in concat blobs */ - hdr = map_sysmem(hdr_addr, sizeof(*hdr)); - dtb_img_size = hdr->dtb_size; - unmap_sysmem(hdr); + dtb_img_size = img_data.dtb_size; i = 0; dtb_addr = dtb_img_addr; while (dtb_addr < dtb_img_addr + dtb_img_size) { @@ -506,6 +519,7 @@ void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr) } } +#ifdef CONFIG_CMD_ABOOTIMG /** * android_image_print_dtb_info - Print info for one DTB blob in DTB area. * @fdt: DTB header @@ -610,3 +624,4 @@ bool android_image_print_dtb_contents(ulong hdr_addr) return true; } #endif +#endif diff --git a/cmd/abootimg.c b/cmd/abootimg.c index b5cfb141ef..f04a7c7c8e 100644 --- a/cmd/abootimg.c +++ b/cmd/abootimg.c @@ -66,33 +66,34 @@ static int abootimg_get_recovery_dtbo(int argc, char *const argv[]) static int abootimg_get_dtb_load_addr(int argc, char *const argv[]) { - const struct andr_boot_img_hdr_v0 *hdr; - int res = CMD_RET_SUCCESS; - if (argc > 1) return CMD_RET_USAGE; + struct andr_image_data img_data = {0}; + const struct andr_boot_img_hdr_v0 *hdr; hdr = map_sysmem(abootimg_addr(), sizeof(*hdr)); - if (!is_android_boot_image_header(hdr)) { - printf("Error: Boot Image header is incorrect\n"); - res = CMD_RET_FAILURE; - goto exit; + if (!android_image_get_data(hdr, &img_data)) { + unmap_sysmem(hdr); + return CMD_RET_FAILURE; } + unmap_sysmem(hdr); - if (hdr->header_version < 2) { + if (img_data.header_version < 2) { printf("Error: header_version must be >= 2 for this\n"); - res = CMD_RET_FAILURE; - goto exit; + return CMD_RET_FAILURE; + } + + if (!img_data.dtb_load_addr) { + printf("Error: failed to read dtb_load_addr\n"); + return CMD_RET_FAILURE; } if (argc == 0) - printf("%lx\n", (ulong)hdr->dtb_addr); + printf("%lx\n", (ulong)img_data.dtb_load_addr); else - env_set_hex(argv[0], (ulong)hdr->dtb_addr); + env_set_hex(argv[0], (ulong)img_data.dtb_load_addr); -exit: - unmap_sysmem(hdr); - return res; + return CMD_RET_SUCCESS; } static int abootimg_get_dtb_by_index(int argc, char *const argv[]) diff --git a/include/image.h b/include/image.h index 9a0bd9d8f2..6264d13e0c 100644 --- a/include/image.h +++ b/include/image.h @@ -1750,7 +1750,9 @@ ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr); ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr); ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr); void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr); +#ifdef CONFIG_CMD_ABOOTIMG bool android_image_print_dtb_contents(ulong hdr_addr); +#endif bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr); /** From patchwork Thu Jan 26 16:04:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732368 X-Patchwork-Delegate: sjg@chromium.org 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=2R0WohgG; 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 4P2lxp5rMkz23h7 for ; Fri, 27 Jan 2023 03:08:46 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7EA58856E8; Thu, 26 Jan 2023 17:08:04 +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="2R0WohgG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 62F4485711; Thu, 26 Jan 2023 17:05:26 +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-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (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 74D49856E8 for ; Thu, 26 Jan 2023 17:05:13 +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-x433.google.com with SMTP id q10so2267602wrm.4 for ; Thu, 26 Jan 2023 08:05:13 -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=B6UrAoLMAeDMNrCr2JS07SzEBmriKe7yge59nPKk1YA=; b=2R0WohgGJPQ+Aa60Tn8BrHmc+kyVOq8xnXWXeokkFyUz5vbh7NECE+fOXMhZCT0b4y d34QdobM7t862UL8p9IPhVF0HY8oVJ6r6cUaj21JhSesaXdaNViFwCwLct2zMsPTMVnr 7xSBWcn/4AgWDIZlOAPl9RWvqsKqT5vzrdO/sniaHpJyhbpP00ChlOMLf5uh6DLkrRLA ibjANSOA5VmZfpzp3Dvt/TYLJvtz2aV8CvV7dOPQuQBuF5y6ht3KVDuKdQ9sy4KyDA99 c5KjEldhu3/qKWAA7AnUL9rSEoCPLb9JhDck5DjGfb4NzVxfBBT4XIVLfkkha2USmIly iTdw== 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=B6UrAoLMAeDMNrCr2JS07SzEBmriKe7yge59nPKk1YA=; b=QR6bBYi2UtAO04o3y/2DJwDi7NkflDvkQyP0ZJe0S2elzU6k3uy7fKc4xrK7FJN7SA QlIXxKNHG8sCTLFhWLwuGthv3f4bNs5aN37XEWI7F2Qnw/XFo15mCWz+7pD2iLQXL27Z 0Dj1w+Cp0bV0fkDohgdRqJN4cjFqCI5a31kqCcTfEc+SRgFP/LIhh90qe9LCILH3KbNP f2bE9KyspKpynVSyXqreNAmvIK7vmOFysNSnIlZdqkKI0403j6SzA2PY3Z9cYGiNrnuT Dg68kumwKDH2p2xe0NcXHDtz0+7C/tRiIeOu8C0sJ9gF3wadXQUwzxjzijNQhbk2tocE Qtdw== X-Gm-Message-State: AO0yUKWW7idCWp/CSsHTeRK4Fp+lAH3qE/N+YLaV9vUFmCYcjTHoh+Ma Kwv1YtVKVQIOh3oYCJ+m3ma5u/K/elGrYqe1 X-Google-Smtp-Source: AK7set/94sozoElD1OV3BCfX/HCbOgWdkG8gP3Mx1XQd9bSljRgdF4VH3WN2/6KEuIfABuPPqhAX8Q== X-Received: by 2002:a5d:498a:0:b0:2bf:ae3c:e963 with SMTP id r10-20020a5d498a000000b002bfae3ce963mr10027099wrq.9.1674749113140; Thu, 26 Jan 2023 08:05:13 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:12 -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 v2 07/17] android: boot: content print is not supported for v3, v4 header version Date: Thu, 26 Jan 2023 17:04:56 +0100 Message-Id: <20230126160506.1026643-8-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 Content print is not supported for version 3 and 4 of boot image header. Thus, only print that content when v2 is used. Update android_print_contents() to print an error message when trying to print boot image header version 3 or 4 content. Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- boot/image-android.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/boot/image-android.c b/boot/image-android.c index 9dab09a69a..a6e7a7abb0 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -481,6 +481,10 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, */ void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr) { + if (hdr->header_version >= 3) { + printf("Content print is not supported for boot image header version > 2"); + return; + } const char * const p = IMAGE_INDENT_STRING; /* os_version = ver << 11 | lvl */ u32 os_ver = hdr->os_version >> 11; @@ -513,7 +517,7 @@ void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr) hdr->header_size); } - if (hdr->header_version >= 2) { + if (hdr->header_version == 2) { printf("%sdtb size: %x\n", p, hdr->dtb_size); printf("%sdtb addr: %llx\n", p, hdr->dtb_addr); } From patchwork Thu Jan 26 16:04:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732362 X-Patchwork-Delegate: sjg@chromium.org 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=ZpdkeHNJ; 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 4P2lwK2j8Dz23h7 for ; Fri, 27 Jan 2023 03:07:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4579085720; Thu, 26 Jan 2023 17:07:16 +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="ZpdkeHNJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 99B5A856D5; Thu, 26 Jan 2023 17:05:29 +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-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 A1165856BB for ; Thu, 26 Jan 2023 17:05:14 +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-x42c.google.com with SMTP id q5so2300977wrv.0 for ; Thu, 26 Jan 2023 08:05:14 -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=AVzWkeDOXwmLhQvI6XH0MLJxMfohbmMZxQBzjjjvVnQ=; b=ZpdkeHNJcnQlGj5cJpHckRSiWJ5Glp9JwUNQqHev8db48ZGotlAlfZDcFR62M9NT9X cZtaxdp48Nacmr1aDD5cUxIrJENDN9Xx64h5il937ZHxS88LpLQ+Tar/mNJuNd4zCTvz s6ZetDVQCS4q3r+WJKI0caHWZBQJVvGdMCh3nAiIDvxDwYQ+pai2uJMge17/u4dij6Ys 3Acyitj368VpkpsOOODHYJ1CPOOj/ED1OJIgBrkAscHtxx0HhLIsgFQNWXOfLZy8cxc8 Kq/qBvnzcs4z1q/R67czsLx6B2vzzq0lSLefXL5FWWgMMbB95YvK//aMZ8HjPXlwlHEQ TGHw== 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=AVzWkeDOXwmLhQvI6XH0MLJxMfohbmMZxQBzjjjvVnQ=; b=y4d6Km6Hn+ZoOmWMPlYXS9Bo5LfFOS/yxY6MFUfe0aYl22eT9W4NvI+HEPHKKoZizi 1izkpnwXeFqiOEPiABLBr/IGGpmykFK8X1hAHy6t0c3i5UIkb+JFkmp9MuMr6Vu3+Pzr nvW+gOhCsiNTJmXJIlupl7/faRSh2qPPSYW2fuE8XnA/W1Cquo+z/AnMjVW3skomoq7U hh9SSnMtam5J0qrcYA2PNjJddkyPwcJcb9PJtb7mtFbRElyKQ4GDymM/h8XaIXKXFnfg LM78T8oACVf0bmFO1yP4ROQkMx4tu2ZTp6hMnkH79U/FwPJ2vRMgdCceYuavgKFLzSFR 1wmA== X-Gm-Message-State: AFqh2kpqttwwD0Ab9saZv4ME3XwBsUCi/OKCIBByGFwD4mKx1jotejCU xJZdP8CV/mtsY6u1X1iltNvFrQ== X-Google-Smtp-Source: AMrXdXtjSLppkBkjbsV62q5zgwTen9XeTiZiPQqEopKu4JxLOVWRBi5usdjXrxzTRKkXNgkZFRm6Mw== X-Received: by 2002:a05:6000:12cb:b0:2bd:bf44:2427 with SMTP id l11-20020a05600012cb00b002bdbf442427mr34408452wrx.42.1674749113949; Thu, 26 Jan 2023 08:05:13 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:13 -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 v2 08/17] android: boot: boot image header v3, v4 do not support recovery DTBO Date: Thu, 26 Jan 2023 17:04:57 +0100 Message-Id: <20230126160506.1026643-9-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 android_image_get_dtbo() is used to get recovery DTBO via abootimg cmd. This is not supported in boot image header v3 and v4. Thus, we print an error message when v1,v2 header version are not used. Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- boot/image-android.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boot/image-android.c b/boot/image-android.c index a6e7a7abb0..d797270a32 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -316,8 +316,8 @@ bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size) goto exit; } - if (hdr->header_version < 1) { - printf("Error: header_version must be >= 1 to get dtbo\n"); + if (hdr->header_version != 1 && hdr->header_version != 2) { + printf("Error: header version must be >= 1 and <= 2 to get dtbo\n"); ret = false; goto exit; } From patchwork Thu Jan 26 16:04:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732372 X-Patchwork-Delegate: sjg@chromium.org 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=PIyBPoDI; 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 4P2lz70pTWz23h7 for ; Fri, 27 Jan 2023 03:09:55 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 11F5585746; Thu, 26 Jan 2023 17:08:23 +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="PIyBPoDI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 22898856ED; Thu, 26 Jan 2023 17:05:40 +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-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 08A83856F1 for ; Thu, 26 Jan 2023 17:05:15 +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-x431.google.com with SMTP id d14so2248775wrr.9 for ; Thu, 26 Jan 2023 08:05:14 -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=+tKKmnqdM9m3eGvSWXGFTxo5dd0HGByc8I+ykrZ6OVk=; b=PIyBPoDIwESUTMHTfQkb3RT+jxSPDKGy4s/X3+tUQEkKQDoFJbaOISdOUqzeZJR0Vk ev0tFd0qN0Iu2oF7MAUh2prJY99mMGU+cCnP8gtgYP1dxZknpAAiidmfa9FJ0HVOW/YS huasCu0xjLKn4/3BkRPaQdqLkXNdCt8frUyzcUmN132lek0GkAtPSeBQk3kFZEOISuhT f0hbs+49ExzWjy5QZb1FmuIGM/vDCnci+X1odJ+vyUIHxyjBdWAMvwwycHHIK0mgu/Sq p6AXVguxawPRT9YFBE8Cw7RdfYFRZtS1csFWUK7jHZuZ04qm0ttQ9gTelclEUSsAjbf+ rX0A== 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=+tKKmnqdM9m3eGvSWXGFTxo5dd0HGByc8I+ykrZ6OVk=; b=5id2wjSFcCcXgtffRME8JHNiTMSiEBVA+vS06X7JYP3ZeMdsGCdHiGr5la99Izx4za vPop2TGOznaCPOgQ+1wGXZzrqbiOoN7Pd+vild5mbvECmqNU/aPAHNqNfjGvK5z1zQ4p n//xPO9oVmW3j68mxUM1xoCPTw81S+OO8Jt+1VoogU59AcE8nNdue+BSqDikF6wBn4au +iYRkii8uFisv6AnIUMjXQVr/YvsIDEKsR55/gfueLbS1+QxOXjcxIE8SpLN43Ocheve D9G6nQFbN6330IzfdWwMwYI14HbxBPcQGFa2FEXZogkgwnerAoEmORjUlMuvweHt0Av3 SRSQ== X-Gm-Message-State: AO0yUKXuX0x4SEQ12I2VNzlCfZkAN7X1/RKzZiFzo8qCgQK6YCN2i4bv ZwlZh53ybFGzFTSQIeybzNWbHQ== X-Google-Smtp-Source: AK7set+Hsrhfy0qYdIoyT3mCUKHzwBCiXbXlelbU4QeLHGisgG9LatjUYXYQqhDAw8XZ8Q18EfSmqQ== X-Received: by 2002:adf:a41a:0:b0:2bf:bab9:5f2e with SMTP id d26-20020adfa41a000000b002bfbab95f2emr4555844wra.22.1674749114642; Thu, 26 Jan 2023 08:05:14 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:14 -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 v2 09/17] android: boot: add vendor boot image to prepare for v3, v4 support Date: Thu, 26 Jan 2023 17:04:58 +0100 Message-Id: <20230126160506.1026643-10-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 This is done to prepare for boot image version 3 and 4 support. Signed-off-by: Safae Ouajih --- boot/bootm.c | 8 +++---- boot/image-android.c | 54 ++++++++++++++++++++++++++++---------------- boot/image-board.c | 3 +-- boot/image-fdt.c | 3 ++- cmd/abootimg.c | 4 ++-- include/image.h | 22 +++++++++++------- 6 files changed, 58 insertions(+), 36 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index 15fce8ad95..a58e6f391e 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -182,11 +182,11 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, #ifdef CONFIG_ANDROID_BOOT_IMAGE case IMAGE_FORMAT_ANDROID: images.os.type = IH_TYPE_KERNEL; - images.os.comp = android_image_get_kcomp(os_hdr); + images.os.comp = android_image_get_kcomp(os_hdr, NULL); images.os.os = IH_OS_LINUX; - images.os.end = android_image_get_end(os_hdr); - images.os.load = android_image_get_kload(os_hdr); + images.os.end = android_image_get_end(os_hdr, NULL); + images.os.load = android_image_get_kload(os_hdr, NULL); images.ep = images.os.load; ep_found = true; break; @@ -965,7 +965,7 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, #ifdef CONFIG_ANDROID_BOOT_IMAGE case IMAGE_FORMAT_ANDROID: printf("## Booting Android Image at 0x%08lx ...\n", img_addr); - if (android_image_get_kernel(buf, images->verify, + if (android_image_get_kernel(buf, NULL, images->verify, os_data, os_len)) return NULL; break; diff --git a/boot/image-android.c b/boot/image-android.c index d797270a32..66922355e5 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -66,7 +66,8 @@ static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr data->boot_img_total_size = end - (ulong)hdr; } -bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data) +bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr, + struct andr_image_data *data) { if (!boot_hdr || !data) { printf("boot_hdr or data params can't be NULL\n"); @@ -114,8 +115,10 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data) /** * android_image_get_kernel() - processes kernel part of Android boot images - * @hdr: Pointer to image header, which is at the start + * @hdr: Pointer to boot image header, which is at the start * of the image. + * @vendor_boot_img: Pointer to vendor boot image header, which is at the + * start of the image. * @verify: Checksum verification flag. Currently unimplemented. * @os_data: Pointer to a ulong variable, will hold os data start * address. @@ -127,14 +130,15 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data) * Return: Zero, os start address and length on success, * otherwise on failure. */ -int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify, +int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, + const void *vendor_boot_img, int verify, ulong *os_data, ulong *os_len) { struct andr_image_data img_data = {0}; u32 kernel_addr; const struct legacy_img_hdr *ihdr; - if (!android_image_get_data(hdr, &img_data)) + if (!android_image_get_data(hdr, vendor_boot_img, &img_data)) return -EINVAL; kernel_addr = android_image_get_kernel_addr(&img_data); @@ -201,11 +205,12 @@ bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr) return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE); } -ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr) +ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr, + const void *vendor_boot_img) { struct andr_image_data img_data; - if (!android_image_get_data(hdr, &img_data)) + if (!android_image_get_data(hdr, vendor_boot_img, &img_data)) return -EINVAL; if (img_data.header_version > 2) @@ -214,22 +219,24 @@ ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr) return img_data.boot_img_total_size; } -ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr) +ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr, + const void *vendor_boot_img) { struct andr_image_data img_data; - if (!android_image_get_data(hdr, &img_data)) + if (!android_image_get_data(hdr, vendor_boot_img, &img_data)) return -EINVAL; return android_image_get_kernel_addr(&img_data); } -ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr) +ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr, + const void *vendor_boot_img) { struct andr_image_data img_data; const void *p; - if (!android_image_get_data(hdr, &img_data)) + if (!android_image_get_data(hdr, vendor_boot_img, &img_data)) return -EINVAL; p = (const void *)img_data.kernel_ptr; @@ -242,11 +249,11 @@ ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr) } int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr, - ulong *rd_data, ulong *rd_len) + const void *vendor_boot_img, ulong *rd_data, ulong *rd_len) { struct andr_image_data img_data = {0}; - if (!android_image_get_data(hdr, &img_data)) + if (!android_image_get_data(hdr, vendor_boot_img, &img_data)) return -EINVAL; if (!img_data.ramdisk_size) { @@ -268,7 +275,7 @@ int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr, { struct andr_image_data img_data; - if (!android_image_get_data(hdr, &img_data)) + if (!android_image_get_data(hdr, NULL, &img_data)) return -EINVAL; if (!img_data.second_size) { @@ -350,11 +357,12 @@ exit: /** * android_image_get_dtb_img_addr() - Get the address of DTB area in boot image. * @hdr_addr: Boot image header address + * @vhdr_addr: Vendor Boot image header address * @addr: Will contain the address of DTB area in boot image * * Return: true on success or false on fail. */ -static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong *addr) +static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong vhdr_addr, ulong *addr) { const struct andr_boot_img_hdr_v0 *hdr; ulong dtb_img_addr; @@ -399,6 +407,7 @@ exit: /** * android_image_get_dtb_by_index() - Get address and size of blob in DTB area. * @hdr_addr: Boot image header address + * @vendor_boot_img: Pointer to vendor boot image header, which is at the start of the image. * @index: Index of desired DTB in DTB area (starting from 0) * @addr: If not NULL, will contain address to specified DTB * @size: If not NULL, will contain size of specified DTB @@ -408,17 +417,24 @@ exit: * * Return: true on success or false on error. */ -bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, - u32 *size) +bool android_image_get_dtb_by_index(ulong hdr_addr, ulong vendor_boot_img, + u32 index, ulong *addr, u32 *size) { struct andr_image_data img_data; const struct andr_boot_img_hdr_v0 *hdr; + const struct andr_vendor_img_hdr *vhdr; hdr = map_sysmem(hdr_addr, sizeof(*hdr)); - if (!android_image_get_data(hdr, &img_data)) { + if (vendor_boot_img != -1) + vhdr = map_sysmem(vendor_boot_img, sizeof(*vhdr)); + if (!android_image_get_data(hdr, vhdr, &img_data)) { + if (vendor_boot_img != -1) + unmap_sysmem(vhdr); unmap_sysmem(hdr); return false; } + if (vendor_boot_img != -1) + unmap_sysmem(vhdr); unmap_sysmem(hdr); ulong dtb_img_addr; /* address of DTB part in boot image */ @@ -426,7 +442,7 @@ bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, ulong dtb_addr; /* address of DTB blob with specified index */ u32 i; /* index iterator */ - android_image_get_dtb_img_addr(hdr_addr, &dtb_img_addr); + android_image_get_dtb_img_addr(hdr_addr, vendor_boot_img, &dtb_img_addr); /* Check if DTB area of boot image is in DTBO format */ if (android_dt_check_header(dtb_img_addr)) { return android_dt_get_fdt_by_index(dtb_img_addr, index, addr, @@ -583,7 +599,7 @@ bool android_image_print_dtb_contents(ulong hdr_addr) ulong dtb_addr; /* address of DTB blob with specified index */ u32 i; /* index iterator */ - res = android_image_get_dtb_img_addr(hdr_addr, &dtb_img_addr); + res = android_image_get_dtb_img_addr(hdr_addr, 0, &dtb_img_addr); if (!res) return false; diff --git a/boot/image-board.c b/boot/image-board.c index 9295b6d0c8..b6c9bbe8f5 100644 --- a/boot/image-board.c +++ b/boot/image-board.c @@ -428,8 +428,7 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) { void *ptr = map_sysmem(images->os.start, 0); int ret; - - ret = android_image_get_ramdisk(ptr, rd_datap, rd_lenp); + ret = android_image_get_ramdisk(ptr, NULL, rd_datap, rd_lenp); unmap_sysmem(ptr); if (ret) return ret; diff --git a/boot/image-fdt.c b/boot/image-fdt.c index 1181cb60f0..f270d00a5f 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -536,7 +536,8 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, * Firstly check if this android boot image has dtb field. */ dtb_idx = (u32)env_get_ulong("adtb_idx", 10, 0); - if (android_image_get_dtb_by_index((ulong)hdr, dtb_idx, &fdt_addr, &fdt_size)) { + if (android_image_get_dtb_by_index((ulong)hdr, 0, + dtb_idx, &fdt_addr, &fdt_size)) { fdt_blob = (char *)map_sysmem(fdt_addr, 0); if (fdt_check_header(fdt_blob)) goto no_fdt; diff --git a/cmd/abootimg.c b/cmd/abootimg.c index f04a7c7c8e..4d6cf0fa3e 100644 --- a/cmd/abootimg.c +++ b/cmd/abootimg.c @@ -72,7 +72,7 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[]) const struct andr_boot_img_hdr_v0 *hdr; hdr = map_sysmem(abootimg_addr(), sizeof(*hdr)); - if (!android_image_get_data(hdr, &img_data)) { + if (!android_image_get_data(hdr, NULL, &img_data)) { unmap_sysmem(hdr); return CMD_RET_FAILURE; } @@ -119,7 +119,7 @@ static int abootimg_get_dtb_by_index(int argc, char *const argv[]) return CMD_RET_FAILURE; } - if (!android_image_get_dtb_by_index(abootimg_addr(), num, + if (!android_image_get_dtb_by_index(abootimg_addr(), 0, num, &addr, &size)) { return CMD_RET_FAILURE; } diff --git a/include/image.h b/include/image.h index 6264d13e0c..df8a9075fa 100644 --- a/include/image.h +++ b/include/image.h @@ -1735,20 +1735,26 @@ int fit_image_cipher_get_algo(const void *fit, int noffset, char **algo); struct cipher_algo *image_get_cipher_algo(const char *full_name); struct andr_image_data; -bool android_image_get_data(const void *boot_hdr, struct andr_image_data *data); +bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr, + struct andr_image_data *data); + struct andr_boot_img_hdr_v0; -int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify, +int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, + const void *vendor_boot_img, int verify, ulong *os_data, ulong *os_len); int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr, - ulong *rd_data, ulong *rd_len); + const void *vendor_boot_img, ulong *rd_data, ulong *rd_len); int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr, ulong *second_data, ulong *second_len); bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size); -bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr, - u32 *size); -ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr); -ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr); -ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr); +bool android_image_get_dtb_by_index(ulong hdr_addr, ulong vendor_boot_img, + u32 index, ulong *addr, u32 *size); +ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr, + const void *vendor_boot_img); +ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr, + const void *vendor_boot_img); +ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr, + const void *vendor_boot_img); void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr); #ifdef CONFIG_CMD_ABOOTIMG bool android_image_print_dtb_contents(ulong hdr_addr); From patchwork Thu Jan 26 16:04:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732363 X-Patchwork-Delegate: sjg@chromium.org 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=85.214.62.61; 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=MqbxryVa; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4P2lwX2nn5z23h7 for ; Fri, 27 Jan 2023 03:07:40 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 11BAB856F5; Thu, 26 Jan 2023 17:07: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="MqbxryVa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A8D6C85559; Thu, 26 Jan 2023 17:05:32 +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-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (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 C74DA856F4 for ; Thu, 26 Jan 2023 17:05:15 +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-wm1-x335.google.com with SMTP id k16so1459104wms.2 for ; Thu, 26 Jan 2023 08:05:15 -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=l8/ORwV2exT3fIW5k4sokalGXjw9EwBBz5NgSfDNbJE=; b=MqbxryVaK25yyR9WKlChmqCGFCR4wjL6Ydzcp8qvtxfh0iZOE8fTfjBLNH+jEX+LlQ YFFIKdudG2ucTvCZdgeuHwXQfZKxaWasxQ6PvqcArBWz5vWTK/mOH8DOCokfZNaf1p4q a6K24ytkGve0jaXvi/UgtAbq99Ke4zCyifLEMgkUVsxxIwTUaiAcFtQGQ1OMpbgKy/RV m9LZyxrUHqvRY03UeawEP9cHkWinmsO/iHlZHIZwoMHTNjJcOpAsuhoB8YfmwMjmPTUs olssf30nAnvccIfRA+QTAt4J0LmiwzVODe+J3NgdQC+MAOrimh2RM1zr5KpUBEIFCaKL 1NUA== 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=l8/ORwV2exT3fIW5k4sokalGXjw9EwBBz5NgSfDNbJE=; b=DgNb7WmvpN3gdi8U7oksPQOPs58mcP/+XFcsNhrAHntk2CPNqgT0uK3bN1R/pKnOJE NhZZFNlQge+IZxoc4/5dTzJJlOBQTzZXrfEkXQcTgONTkQmDfX/0NzDYFZckYEtIJix0 oyw7Wz6xpK1aBjNVi5PGKBt9ug5iGPhiqDhSsnVO0io7Rto8UpCV3rmZMjkHREBLPq3R q046xF8fKugAN+anxhZrrTk9Uqubq7qvwwciqTu95wN8hvg60UNMdXu8rUpHnN3HFyNm Q+PMnKIOM/6jFqIZF8Af+YIIuuakZT4GZS152VFWE9X/3zB9SM6j/UO0aLN3uIi/+H8b UbSw== X-Gm-Message-State: AFqh2koIK//xlgmw/QvAoJJJ9kh328Wuy6GnPXD74GFNY2G0DXqGDmYA KQZv1pD9eyGbe2Zl/NWY/TbQ4g== X-Google-Smtp-Source: AMrXdXtO008wJUu2be1gjCmRJdQQPGlWO/u1vTSlnHuvilTlranFlbepF2kQCZ60ZPXnvcIVEBRB+A== X-Received: by 2002:a05:600c:444b:b0:3da:fd06:a6f1 with SMTP id v11-20020a05600c444b00b003dafd06a6f1mr34766936wmn.31.1674749115296; Thu, 26 Jan 2023 08:05:15 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:15 -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 v2 10/17] android: boot: update android_image_get_data to support v3, v4 Date: Thu, 26 Jan 2023 17:04:59 +0100 Message-Id: <20230126160506.1026643-11-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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, 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 Reviewed-by: Simon Glass --- boot/image-android.c | 80 +++++++++++++++++++++++++++++++++++++++-- include/android_image.h | 3 ++ include/image.h | 1 + 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/boot/image-android.c b/boot/image-android.c index 66922355e5..0e78ca0dac 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_vendor_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 5b36f96d7b..351e17750e 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 df8a9075fa..a1a14403d5 100644 --- a/include/image.h +++ b/include/image.h @@ -1760,6 +1760,7 @@ void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr); bool android_image_print_dtb_contents(ulong hdr_addr); #endif bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr); +bool is_android_vendor_boot_image_header(const void *vendor_boot_img); /** * board_fit_config_name_match() - Check for a matching board name From patchwork Thu Jan 26 16:05:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732366 X-Patchwork-Delegate: sjg@chromium.org 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=pass (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=Zbhjs+tG; 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 4P2lxJ5NYBz23h7 for ; Fri, 27 Jan 2023 03:08:20 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C6C4185718; Thu, 26 Jan 2023 17:07:52 +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="Zbhjs+tG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 96B82856F4; Thu, 26 Jan 2023 17:05:35 +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-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) (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 49468856DD for ; Thu, 26 Jan 2023 17:05:17 +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-wm1-x334.google.com with SMTP id j17so1480748wms.0 for ; Thu, 26 Jan 2023 08:05:17 -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=UHhc4xnQuGkGKzjcf8teXIrbPZdQ7B4exb7Fch50jV4=; b=Zbhjs+tGT5DQPR+GNi1vS2N0/E5WxM07gLEvvtK9gF1mmlCiTS35ovaSW3TWSCjl52 wMN77G5n2ejVT2/7Ut3+3ItUC+SPt0W3bTPU1jSsnillrDZ8PJD1fFbMCn0zPe8MJKwl MdZq+RPp/tlQb+k92L7gRJuupo3rKLdgaqLeIp7+iZstnF5DpDc2/okr452K2BfEknU6 MUmsC6j7gmdDQtsKeI6yeD1qXY8uiCUVpy0w7Tqn3nMwwFE7ho7B8lYb+hqp4OlQXnM3 C+TRhLPLXNzyfTgs95+BDQoxZR1kycT/TROO9NV4HoSQbiJcMdXeVyUNQkpYHqP7fPl1 1wNg== 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=UHhc4xnQuGkGKzjcf8teXIrbPZdQ7B4exb7Fch50jV4=; b=xPeOjHSjpmxZ0CxQwU0+bNSJkUdlr956Hx8tIim/6CqMN0iloacLpQAOxxWSOJm9K4 bMRPHNqOFbok5r7qBkw2BV+7ehU3BHqcsQCy1e/HDKc7vKxFGRFw3qrEGTjzZXaRtTGW 1lOegCUTPBB+7LZUCdcKpKse3mREhec82YjeR4AA0r/5h0ucAzxrx4cGeXOF3c4b7Kv3 HAFa0HfQii0VQ73EA87J4VbyqYKIlVgeBoX95hSaOaBS3m5/d72fxZXrgSD6tnVU92ZC QSXi0GYp0YMjTG1o0T1sQ1SwNWi0BA/hbSlTnq9Nnj0H41dyN7jqk+7rhNt7CXKyL6uS O4HQ== X-Gm-Message-State: AFqh2krRtVqCA8XAwFglmVn0J+jYofMhlKX3DsNYalGPCidD3lzloCPG YiYvXUM78UQubld2ks+GfzgMG4IlyFgYZYsn X-Google-Smtp-Source: AMrXdXsyI12ceYtC5jcQOCGtRPbgpS6kLZXHSqA6ytHF/eFnyFDBIBH+sVgAWh8a5hW/mi4oROJ/5g== X-Received: by 2002:a05:600c:3d98:b0:3d6:ecc4:6279 with SMTP id bi24-20020a05600c3d9800b003d6ecc46279mr32996468wmb.27.1674749116058; Thu, 26 Jan 2023 08:05:16 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:15 -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 v2 11/17] android: boot: ramdisk: support vendor ramdisk Date: Thu, 26 Jan 2023 17:05:00 +0100 Message-Id: <20230126160506.1026643-12-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 Version 3 and 4 of boot image header introduced vendor boot ramdisk: Please check include/android_image.h for details. The ramdisk is now split into a generic ramdisk in boot image and a vendor ramdisk in vendor boot image. Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass --- boot/image-android.c | 13 +++++++++++-- include/image.h | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/boot/image-android.c b/boot/image-android.c index 0e78ca0dac..5b270e4417 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -25,6 +25,7 @@ static void android_boot_image_v3_v4_parse_hdr(const struct andr_boot_img_hdr_v3 data->kcmdline = hdr->cmdline; data->header_version = hdr->header_version; + data->ramdisk_ptr = env_get_ulong("ramdisk_addr_r", 16, 0); /* * The header takes a full page, the remaining components are aligned @@ -322,10 +323,11 @@ ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr, return image_decomp_type(p, sizeof(u32)); } -int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr, - const void *vendor_boot_img, ulong *rd_data, ulong *rd_len) +int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, + ulong *rd_data, ulong *rd_len) { struct andr_image_data img_data = {0}; + ulong ramdisk_ptr; if (!android_image_get_data(hdr, vendor_boot_img, &img_data)) return -EINVAL; @@ -334,6 +336,13 @@ int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr, *rd_data = *rd_len = 0; return -1; } + if (img_data.header_version > 2) { + ramdisk_ptr = img_data.ramdisk_ptr; + memcpy((void *)(ramdisk_ptr), (void *)img_data.vendor_ramdisk_ptr, + img_data.vendor_ramdisk_size); + memcpy((void *)(ramdisk_ptr + img_data.vendor_ramdisk_size), + (void *)img_data.ramdisk_ptr, img_data.boot_ramdisk_size); + } printf("RAM disk load addr 0x%08lx size %u KiB\n", img_data.ramdisk_ptr, DIV_ROUND_UP(img_data.ramdisk_size, 1024)); diff --git a/include/image.h b/include/image.h index a1a14403d5..ac94ecaa14 100644 --- a/include/image.h +++ b/include/image.h @@ -1742,8 +1742,8 @@ struct andr_boot_img_hdr_v0; int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, const void *vendor_boot_img, int verify, ulong *os_data, ulong *os_len); -int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr, - const void *vendor_boot_img, ulong *rd_data, ulong *rd_len); +int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, + ulong *rd_data, ulong *rd_len); int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr, ulong *second_data, ulong *second_len); bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size); From patchwork Thu Jan 26 16:05:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732369 X-Patchwork-Delegate: sjg@chromium.org 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (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=0oXTKtkF; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4P2ly30Q8yz23h7 for ; Fri, 27 Jan 2023 03:08:59 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8F6CC85734; Thu, 26 Jan 2023 17:08:11 +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="0oXTKtkF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CCA02856D5; Thu, 26 Jan 2023 17:05:34 +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-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (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 B080F856ED for ; Thu, 26 Jan 2023 17:05:17 +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-x433.google.com with SMTP id bk16so2239343wrb.11 for ; Thu, 26 Jan 2023 08:05:17 -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=/Ff8AGpbOzmDeIskVJywdY0hL+QXivVd5/BpqONpZMc=; b=0oXTKtkFgi03Sus1FJ5AP5K/0fEb0fbvTUiZsHEzHFIOuvgvNyDZ6aY/Tzds4m5XXp kKfvAC3SPwhDAK+JpY43pl324xfwA9YdQ6iqzKea2Fxpx8Nm9TKlhqRgKheJxXVfOPRw Rl9KeWIXwUIQurut26kkv0hDYJQcEXjCiZYn0gL4Db4ayaiTzT0aJVStW7jqzX8fEok6 Aw85fn3Aws2I1mYxg+87DWx0c890W/T6Dm4BbawA7p4OLM7YZL58McSiznZpUrHtjwtb h+q6TBq9GeY5pvCPoFFwFo2ZDPyqVj3Hu0swK6sZWym3NqhsiEYgqlwgM6ifX6J/8cde qY7Q== 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=/Ff8AGpbOzmDeIskVJywdY0hL+QXivVd5/BpqONpZMc=; b=rS3qoFR/AIKmDcSzJQT0zjj257lBxtnFdxUSXESIqZ+v7g/0eeMmnXSk7EepXKKmw+ 3t7AuUeYCOu8jAM1BeBt92D7uk06S+JTDQFJOZ2BoUzxC4d7wRnMsiDM0lh+Z9Zfj0EW qnQtJKn40rzhIJ4/NfmA2XRnwtaVyjrzJuuNxXBWzQoHB83J7VgK6nsTtduU7rex5G1+ LQC9UQL2C1zAzJc29vc6P1QPjrWiax7OC+CBrwn+lECZeQHVvT9OpG2f4PsUpEd+UHuY PGi9rz6X55+7GOASFC2BVu6/+RXgcJlY+B9SRJaooD24aZYK712g4qtqE+j51qLNZsnI VHsQ== X-Gm-Message-State: AFqh2kr5P5r0nX4croiQO0Iu1yZqfJ0IJbB0ULZ8q8ebI7hmQtFY5d1X QC9D0gVpidrhBPWguK7O/OMoow== X-Google-Smtp-Source: AMrXdXvRldhAlaMTpp2VUs0YxZNPNb91QRpEDAewd9/NNErx+2Ofm2csI4kUJ+CqFPiP0fiTIO59EA== X-Received: by 2002:adf:e7d2:0:b0:2be:f49:6b83 with SMTP id e18-20020adfe7d2000000b002be0f496b83mr32398985wrn.57.1674749116718; Thu, 26 Jan 2023 08:05:16 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:16 -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 v2 12/17] android: boot: support extra command line Date: Thu, 26 Jan 2023 17:05:01 +0100 Message-Id: <20230126160506.1026643-13-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 In version 3 and 4 of boot image header, the vendor specific command line are located in vendor boot image. Thus, using extra command line to add those cmd to bootargs. Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- boot/image-android.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/boot/image-android.c b/boot/image-android.c index 5b270e4417..cb4fc22b00 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -55,6 +55,7 @@ static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vendor_i * The header takes a full page, the remaining components are aligned * on page boundary. */ + data->kcmdline_extra = hdr->cmdline; data->tags_addr = hdr->tags_addr; data->image_name = hdr->name; data->kernel_addr = hdr->kernel_addr; @@ -233,6 +234,11 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, len += strlen(img_data.kcmdline); } + if (img_data.kcmdline_extra) { + printf("Kernel extra command line: %s\n", img_data.kcmdline_extra); + len += strlen(img_data.kcmdline_extra); + } + char *bootargs = env_get("bootargs"); if (bootargs) len += strlen(bootargs); @@ -252,6 +258,11 @@ int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, if (*img_data.kcmdline) strcat(newbootargs, img_data.kcmdline); + if (img_data.kcmdline_extra) { + strcat(newbootargs, " "); + strcat(newbootargs, img_data.kcmdline_extra); + } + env_set("bootargs", newbootargs); if (os_data) { From patchwork Thu Jan 26 16:05:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732364 X-Patchwork-Delegate: sjg@chromium.org 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=OWnMzoXE; 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 4P2lwm5s1Fz23h7 for ; Fri, 27 Jan 2023 03:07:52 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 47DA785729; Thu, 26 Jan 2023 17:07:45 +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="OWnMzoXE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5D9AE85650; Thu, 26 Jan 2023 17:05:39 +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-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (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 CF0DE856F7 for ; Thu, 26 Jan 2023 17:05:19 +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-x436.google.com with SMTP id bk16so2239374wrb.11 for ; Thu, 26 Jan 2023 08:05:19 -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=ZbCJr+NMLPktfCVMLJFBd75RI6HIT2EzTozd2BGO+00=; b=OWnMzoXEe6LcLNZDBsPD7l3wFa/vlMnpO/RyxcsXxmkmy/mav3Y6nt1x2Wb7fyXD0K 18obf8FkhawD4TUPS0ZRxHkPNoYy3QH4QknxqA1Nq9epqlyv2CpP5zIHiY+iY+5K0XWr pVs+NM9s0no/qL72sJjO2INiRwbVmqlb136UFWWDfLHSl4ou6cVCm2EzbLezdPrsMOGo TO9UfZtDMKha+iJGfhItFdr72s/v9dj9gL8yWLd7SbyR6civhwtT1C/VtQSJSAkswsZ1 XBQ19SagMH6AANPz0w2FTI2G0jmhPwfFt1q2fuxzL+83BYYS0UWyyEXhHhP1e2BFGxFO j/7g== 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=ZbCJr+NMLPktfCVMLJFBd75RI6HIT2EzTozd2BGO+00=; b=yAqYD/+uvWyyNcieUwnJOTKQQlyqJg5LjBJyF6xv2WxoGCVp3thwln3XmJzC1rOwCX N5/caYIW1uCEFx+fXjtiph6E4vxHpkTHe1coQ3EBsfA2Bq7cWja87EUKmYIfd+G4TLUY QkS1s8sbqhq3qxG3eQwa0QIhq3/wPgoUL8mK4q/oO0QMhWEZTX0i7B23jAM6p8R3+w9o 7ZUeKfruE4R9Fw0AIgs2EMqhMTSolROfe/y/0V+iD/D9gis/hxTmpaedKqUPoSow3zkH YTCYeuCTs4ZjSjj2fenSlMyHDeojPawV0LhRFAgeVj21QoTJET6t9fS4wV/vf0khiswc vhzQ== X-Gm-Message-State: AO0yUKWrdMm10PGxj5dezHtRQyk0BKG6WNkqybSwkb6UrOPtazK+oxp3 DjzKoIk6hWt8lbdAgpFMKm/Kvg== X-Google-Smtp-Source: AK7set+5TjMcNhOCSmrzx3LJ+lS9YJxzjq2MBrr+OtNy8Eya1hVkSP4NLKMth4cVgc+6xCtudkXGTA== X-Received: by 2002:adf:ce04:0:b0:2bf:ae15:5950 with SMTP id p4-20020adfce04000000b002bfae155950mr9205155wrn.20.1674749117404; Thu, 26 Jan 2023 08:05:17 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:17 -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 v2 13/17] android: boot: update android_image_get_dtb_img_addr to support v3, v4 Date: Thu, 26 Jan 2023 17:05:02 +0100 Message-Id: <20230126160506.1026643-14-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 This adds support for boot image version 3 and 4 in android_image_get_dtb_img_addr(). Since the dtb is now included in vendor_boot image instead of boot image, the dtb address should be extracted from vendor_boot image when a v3 or v4 is used. Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- boot/image-android.c | 47 +++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/boot/image-android.c b/boot/image-android.c index cb4fc22b00..edeeaaaee0 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -459,6 +459,7 @@ exit: static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong vhdr_addr, ulong *addr) { const struct andr_boot_img_hdr_v0 *hdr; + const struct andr_vendor_img_hdr *v_hdr; ulong dtb_img_addr; bool ret = true; @@ -475,22 +476,40 @@ static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong vhdr_addr, ulon goto exit; } - if (hdr->dtb_size == 0) { - printf("Error: dtb_size is 0\n"); - ret = false; - goto exit; + if (hdr->header_version == 2) { + if (hdr->dtb_size == 0) { + printf("Error: dtb_size is 0\n"); + ret = false; + goto exit; + } + /* Calculate the address of DTB area in boot image */ + dtb_img_addr = hdr_addr; + dtb_img_addr += hdr->page_size; + dtb_img_addr += ALIGN(hdr->kernel_size, hdr->page_size); + dtb_img_addr += ALIGN(hdr->ramdisk_size, hdr->page_size); + dtb_img_addr += ALIGN(hdr->second_size, hdr->page_size); + dtb_img_addr += ALIGN(hdr->recovery_dtbo_size, hdr->page_size); + + *addr = dtb_img_addr; } - /* Calculate the address of DTB area in boot image */ - dtb_img_addr = hdr_addr; - dtb_img_addr += hdr->page_size; - dtb_img_addr += ALIGN(hdr->kernel_size, hdr->page_size); - dtb_img_addr += ALIGN(hdr->ramdisk_size, hdr->page_size); - dtb_img_addr += ALIGN(hdr->second_size, hdr->page_size); - dtb_img_addr += ALIGN(hdr->recovery_dtbo_size, hdr->page_size); - - *addr = dtb_img_addr; - + if (hdr->header_version > 2) { + v_hdr = map_sysmem(vhdr_addr, sizeof(*v_hdr)); + if (v_hdr->dtb_size == 0) { + printf("Error: dtb_size is 0\n"); + ret = false; + unmap_sysmem(v_hdr); + goto exit; + } + /* Calculate the address of DTB area in boot image */ + dtb_img_addr = vhdr_addr; + dtb_img_addr += v_hdr->page_size; + if (v_hdr->vendor_ramdisk_size) + dtb_img_addr += ALIGN(v_hdr->vendor_ramdisk_size, v_hdr->page_size); + *addr = dtb_img_addr; + unmap_sysmem(v_hdr); + goto exit; + } exit: unmap_sysmem(hdr); return ret; From patchwork Thu Jan 26 16:05:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732370 X-Patchwork-Delegate: sjg@chromium.org 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=85.214.62.61; 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=5zYEWB2G; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4P2lyg2vtGz23h7 for ; Fri, 27 Jan 2023 03:09:31 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 868C98574E; Thu, 26 Jan 2023 17:08:14 +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="5zYEWB2G"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A3EFD856F0; Thu, 26 Jan 2023 17:05:36 +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 956BB85705 for ; Thu, 26 Jan 2023 17:05:23 +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 h12so2241299wrv.10 for ; Thu, 26 Jan 2023 08:05:23 -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=Mur7WXvbsh4+mSqen0wap/KajQfSg+KfFJgSOYta2Tk=; b=5zYEWB2G9ZXebkUDh4JAHwjfwMhfOyiQnd4EN8Jg4oQqtUwhLIBPNta8y5wqiDwtvL vRM0Sds5xWICd49qvoaX9xnSbFuZPTRq/r4p9X5RRCmGStN/sQZ5kDfmzNWbYr4deGLc HkPMZD5ozp4OnhIWCGVMVT63qJa+hd9yEDeWjzJAKRlDBkHclrJT7b6NDTEVnOOzj3zS sVBuE5FiAoBTE9DcLSJrErrhpn1tIH0gNDF84tdbJ9FsR8CJuXr34Fq0+cQ0BCrLkfX6 6/txqxbJ1if0l+02G9GiJR0DZOc4hPUSF5papSjZ/t8b0oOJP8heeT/NQTCPCWpwv4iR YdJA== 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=Mur7WXvbsh4+mSqen0wap/KajQfSg+KfFJgSOYta2Tk=; b=Hty+hRWI3Si/WFywAjKWiRI/Wpjept06X9YpbPjCgJGmjE5zvyFMDgBKeKOJj9EKJR PhtAnSXKYLsGKDo0nk+phSackENvZwtkvyDdC19lgKh3ac/SAN5obxXpyGNEwQT8gXaI hh856fQSA1PyN7/TwT43oJfJEuMJqff6WlQ7XfulWlJLIOheuKYCOddb4ph4/8AVBmtC bs4YlM0VgBl3WdDid36a5LuN9wMUzQOlaqAdkgoqw5BFXD6Ow3RWhOdpcIoo1iAnvGtT N3i+eQA3i1Y7kW3GJrB4mJMHSJox7Q9S3vN/Q3Y79eu5quaNaZN3UyyPN0kHSGFvZYod vAdw== X-Gm-Message-State: AO0yUKUgWTLu4GTGV15Lqx1+StVbTge6BvIruL0kudcBITIjAfNGEAj8 tLdueSXKtdZZ104XXZvoxmAfuA== X-Google-Smtp-Source: AK7set+NudCLqcUZnPJfM9CfrQK9rTgpN79ymX5w8BG3YW4c7Qtf0kWCsyNW7wGNvTkbBSttGjAOLw== X-Received: by 2002:adf:e2d1:0:b0:2bf:c741:5956 with SMTP id d17-20020adfe2d1000000b002bfc7415956mr2189288wrj.19.1674749118091; Thu, 26 Jan 2023 08:05:18 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:17 -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 v2 14/17] drivers: fastboot: zImage flashing is not supported for v3, v4 Date: Thu, 26 Jan 2023 17:05:03 +0100 Message-Id: <20230126160506.1026643-15-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 Print an error message when the boot image header version is greater than 2 as this is not supported for v3 and v4. Signed-off-by: Safae Ouajih --- drivers/fastboot/fb_mmc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c index 086e5f7843..9fb2ab3820 100644 --- a/drivers/fastboot/fb_mmc.c +++ b/drivers/fastboot/fb_mmc.c @@ -370,6 +370,14 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc, return -1; } + /* Check if boot image header version is 2 or less */ + if (hdr->header_version > 2) { + pr_err("zImage flashing supported only for boot images v2 and less\n"); + fastboot_fail("zImage flashing supported only for boot images v2 and less", + response); + return -1; + } + /* Check if boot image has second stage in it (we don't support it) */ if (hdr->second_size > 0) { pr_err("moving second stage is not supported yet\n"); From patchwork Thu Jan 26 16:05:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732373 X-Patchwork-Delegate: sjg@chromium.org 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (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=7gYLI7Id; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4P2lzP5fHtz23gY for ; Fri, 27 Jan 2023 03:10:09 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DA5AA85757; Thu, 26 Jan 2023 17:08:25 +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="7gYLI7Id"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ED76B85650; Thu, 26 Jan 2023 17:05:41 +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-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (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 873DF8570E for ; Thu, 26 Jan 2023 17:05:24 +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-x432.google.com with SMTP id h12so2241342wrv.10 for ; Thu, 26 Jan 2023 08:05:24 -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=u//jHfseNUmKnaU3QzyYt1OYwInCtvExOUy5E4UG3kQ=; b=7gYLI7Id5BNcRcK1VUNB/ikFCLO9qgwfGZUPX3SXyFKJOeaynnxDAot8XO/UHCRwco W7V79I+jVQmb73gAd88kwx/pK3D1fILO4eWKhd+bg4M0U1e+9wpauD61L+bQnxBDrAMg gZ4xNQzyPA5PosIQgiNXbXvSuxQW6WeodgGuNHctnyHJDfeNypLbcQ09tUTM7ZcvAlvW aFyZOttrjbmt0MjZOQRRdvCUrzIoAQEVLhAzwVnGWG1+tCzef1KsYDjafTCMP2QSOfWN 3I7v69tKBcoQCmTKvnxD0+78GF1g6nySh4m1tmM32T2wYYpgPzUd5b/fo3Lm+jyjAiSa YrwA== 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=u//jHfseNUmKnaU3QzyYt1OYwInCtvExOUy5E4UG3kQ=; b=SDv+cinuvx8mJMZ5lQXaouGQaYcQA18HmKgnCyHnHB84qaL6boPEFc44KjOaXr6oQt t3+HeO8GRS4OtvgcZP/4xUJh5pIVDYbe7xd9XdvkWLGCpXTp3XZad/SJcveSE3AccqN2 nt270GvfwQYm2UfmNzClm3ftwplg7ZYlt4qMtBUQeI2bN4qt+dqkp8HLrsbJwTkVPDv8 Adwm/UTWOmbKM7prLrFoLZgj0QpQn0WKkL7lQ3UBD+GSR49iNzuBnArX5dX0OiI64Q9P hGvCDGzVhBCbTAjZCbQaI8+TxIwCgNisrG+Ol9g9O2r/xXnHJFI3+9l0gg+FxnrBWRNl w+yQ== X-Gm-Message-State: AO0yUKUnVR7FamG39/P+nTbJUP+H+oes0wqlw9QyTJnjkBMT1I7zSXIb pHVDP25Npt7wp6oBziWEGxXUZwQ9sQYk7XEI X-Google-Smtp-Source: AK7set+th5zepAhVUE6hn7DR0mlSuLrh8+091UgW+eU2OoSatAo+q8usQ4enZ6BJzw/V5B26Wja3dQ== X-Received: by 2002:a5d:5446:0:b0:2bf:c4b5:a019 with SMTP id w6-20020a5d5446000000b002bfc4b5a019mr2443288wrv.54.1674749118825; Thu, 26 Jan 2023 08:05:18 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:18 -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 v2 15/17] android: boot: support boot image header version 3 and 4 Date: Thu, 26 Jan 2023 17:05:04 +0100 Message-Id: <20230126160506.1026643-16-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 This enables the support for boot image header version 3 and 4 using abootimg command. In order to use version 3 or 4: 1- Vendor boot image address should be given to abootimg cmd. abootimg addr $1 $vendor_boot_load_addr 2- "ramdisk_addr_r" env variable (ramdisk address) should be set to host the ramdisk : generic ramdisk + vendor ramdisk "struct andr_boot_img_hdr_v0*" is replaced by "void *" in some functions since v3 and v4 are now supported as well. Signed-off-by: Safae Ouajih --- boot/bootm.c | 29 ++++++++++++++++++++++++----- boot/image-android.c | 16 ++++++++++------ boot/image-board.c | 14 +++++++++++--- boot/image-fdt.c | 2 +- cmd/abootimg.c | 24 ++++++++++++++++++++++-- include/image.h | 14 ++++++++------ 6 files changed, 76 insertions(+), 23 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index a58e6f391e..3e130c175c 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -113,6 +113,10 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { const void *os_hdr; +#ifdef CONFIG_ANDROID_BOOT_IMAGE + const void *vendor_boot_img; + const void *boot_img; +#endif bool ep_found = false; int ret; @@ -181,12 +185,17 @@ static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc, #endif #ifdef CONFIG_ANDROID_BOOT_IMAGE case IMAGE_FORMAT_ANDROID: + boot_img = os_hdr; + vendor_boot_img = NULL; + if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { + boot_img = (void *)get_abootimg_addr(); + vendor_boot_img = (void *)get_avendor_bootimg_addr(); + } images.os.type = IH_TYPE_KERNEL; - images.os.comp = android_image_get_kcomp(os_hdr, NULL); + images.os.comp = android_image_get_kcomp(boot_img, vendor_boot_img); images.os.os = IH_OS_LINUX; - - images.os.end = android_image_get_end(os_hdr, NULL); - images.os.load = android_image_get_kload(os_hdr, NULL); + images.os.end = android_image_get_end(boot_img, vendor_boot_img); + images.os.load = android_image_get_kload(boot_img, vendor_boot_img); images.ep = images.os.load; ep_found = true; break; @@ -889,6 +898,10 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, int os_noffset; #endif +#ifdef CONFIG_ANDROID_BOOT_IMAGE + const void *boot_img; + const void *vendor_boot_img; +#endif img_addr = genimg_get_kernel_addr_fit(argc < 1 ? NULL : argv[0], &fit_uname_config, &fit_uname_kernel); @@ -964,8 +977,14 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc, #endif #ifdef CONFIG_ANDROID_BOOT_IMAGE case IMAGE_FORMAT_ANDROID: + boot_img = buf; + vendor_boot_img = NULL; + if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { + boot_img = (void *)get_abootimg_addr(); + vendor_boot_img = (void *)get_avendor_bootimg_addr(); + } printf("## Booting Android Image at 0x%08lx ...\n", img_addr); - if (android_image_get_kernel(buf, NULL, images->verify, + if (android_image_get_kernel(boot_img, vendor_boot_img, images->verify, os_data, os_len)) return NULL; break; diff --git a/boot/image-android.c b/boot/image-android.c index edeeaaaee0..dd06c09279 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -201,7 +201,7 @@ static ulong android_image_get_kernel_addr(struct andr_image_data *img_data) * Return: Zero, os start address and length on success, * otherwise on failure. */ -int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, +int android_image_get_kernel(const void *hdr, const void *vendor_boot_img, int verify, ulong *os_data, ulong *os_len) { @@ -286,7 +286,7 @@ 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) +bool is_android_boot_image_header(const void *hdr) { return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE); } @@ -305,7 +305,7 @@ ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr, return img_data.boot_img_total_size; } -ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr, +ulong android_image_get_kload(const void *hdr, const void *vendor_boot_img) { struct andr_image_data img_data; @@ -316,7 +316,7 @@ ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr, return android_image_get_kernel_addr(&img_data); } -ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr, +ulong android_image_get_kcomp(const void *hdr, const void *vendor_boot_img) { struct andr_image_data img_data; @@ -364,14 +364,18 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, return 0; } -int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr, - ulong *second_data, ulong *second_len) +int android_image_get_second(const void *hdr, ulong *second_data, ulong *second_len) { struct andr_image_data img_data; if (!android_image_get_data(hdr, NULL, &img_data)) return -EINVAL; + if (img_data.header_version > 2) { + printf("Second stage bootloader is only supported for boot image version <= 2\n"); + return -1; + } + if (!img_data.second_size) { *second_data = *second_len = 0; return -1; diff --git a/boot/image-board.c b/boot/image-board.c index b6c9bbe8f5..a20b57900e 100644 --- a/boot/image-board.c +++ b/boot/image-board.c @@ -426,10 +426,18 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a break; case IMAGE_FORMAT_ANDROID: if (IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE)) { - void *ptr = map_sysmem(images->os.start, 0); int ret; - ret = android_image_get_ramdisk(ptr, NULL, rd_datap, rd_lenp); - unmap_sysmem(ptr); + if (IS_ENABLED(CONFIG_CMD_ABOOTIMG)) { + ret = android_image_get_ramdisk((void *)get_abootimg_addr(), + (void *)get_avendor_bootimg_addr(), + rd_datap, rd_lenp); + } else { + void *ptr = map_sysmem(images->os.start, 0); + + ret = android_image_get_ramdisk(ptr, NULL, rd_datap, rd_lenp); + unmap_sysmem(ptr); + } + if (ret) return ret; done = true; diff --git a/boot/image-fdt.c b/boot/image-fdt.c index f270d00a5f..5f9cf7b4e6 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -529,7 +529,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch, } #ifdef CONFIG_ANDROID_BOOT_IMAGE } else if (genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) { - struct andr_boot_img_hdr_v0 *hdr = buf; + void *hdr = buf; ulong fdt_data, fdt_len; u32 fdt_size, dtb_idx; /* diff --git a/cmd/abootimg.c b/cmd/abootimg.c index 4d6cf0fa3e..ef7130da0b 100644 --- a/cmd/abootimg.c +++ b/cmd/abootimg.c @@ -17,6 +17,16 @@ static ulong _abootimg_addr = -1; static ulong _avendor_bootimg_addr = -1; +ulong get_abootimg_addr(void) +{ + return (_abootimg_addr == -1 ? image_load_addr : _abootimg_addr); +} + +ulong get_avendor_bootimg_addr(void) +{ + return _avendor_bootimg_addr; +} + static int abootimg_get_ver(int argc, char *const argv[]) { const struct andr_boot_img_hdr_v0 *hdr; @@ -70,12 +80,21 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[]) return CMD_RET_USAGE; struct andr_image_data img_data = {0}; const struct andr_boot_img_hdr_v0 *hdr; + const struct andr_vendor_img_hdr *vhdr; hdr = map_sysmem(abootimg_addr(), sizeof(*hdr)); - if (!android_image_get_data(hdr, NULL, &img_data)) { + if (get_avendor_bootimg_addr() != -1) + vhdr = map_sysmem(get_avendor_bootimg_addr(), sizeof(*vhdr)); + + if (!android_image_get_data(hdr, vhdr, &img_data)) { + if (get_avendor_bootimg_addr() != -1) + unmap_sysmem(vhdr); unmap_sysmem(hdr); return CMD_RET_FAILURE; } + + if (get_avendor_bootimg_addr() != -1) + unmap_sysmem(vhdr); unmap_sysmem(hdr); if (img_data.header_version < 2) { @@ -119,7 +138,8 @@ static int abootimg_get_dtb_by_index(int argc, char *const argv[]) return CMD_RET_FAILURE; } - if (!android_image_get_dtb_by_index(abootimg_addr(), 0, num, + if (!android_image_get_dtb_by_index(abootimg_addr(), + get_avendor_bootimg_addr(), num, &addr, &size)) { return CMD_RET_FAILURE; } diff --git a/include/image.h b/include/image.h index ac94ecaa14..5bd4bf5d57 100644 --- a/include/image.h +++ b/include/image.h @@ -1739,29 +1739,31 @@ bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr, struct andr_image_data *data); struct andr_boot_img_hdr_v0; -int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, +int android_image_get_kernel(const void *hdr, const void *vendor_boot_img, int verify, ulong *os_data, ulong *os_len); int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, ulong *rd_data, ulong *rd_len); -int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr, - ulong *second_data, ulong *second_len); +int android_image_get_second(const void *hdr, ulong *second_data, ulong *second_len); bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size); bool android_image_get_dtb_by_index(ulong hdr_addr, ulong vendor_boot_img, u32 index, ulong *addr, u32 *size); ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr, const void *vendor_boot_img); -ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr, +ulong android_image_get_kload(const void *hdr, const void *vendor_boot_img); -ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr, +ulong android_image_get_kcomp(const void *hdr, const void *vendor_boot_img); void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr); #ifdef CONFIG_CMD_ABOOTIMG bool android_image_print_dtb_contents(ulong hdr_addr); #endif -bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0 *hdr); +bool is_android_boot_image_header(const void *hdr); bool is_android_vendor_boot_image_header(const void *vendor_boot_img); +ulong get_abootimg_addr(void); +ulong get_avendor_bootimg_addr(void); + /** * board_fit_config_name_match() - Check for a matching board name * From patchwork Thu Jan 26 16:05:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732365 X-Patchwork-Delegate: sjg@chromium.org 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=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (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=CXbsHAgy; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4P2lx41ySqz23h7 for ; Fri, 27 Jan 2023 03:08:08 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B3C89856FA; Thu, 26 Jan 2023 17:07:49 +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="CXbsHAgy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A322A856D5; Thu, 26 Jan 2023 17:05:40 +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-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 C8807856D3 for ; Thu, 26 Jan 2023 17:05:19 +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-x42c.google.com with SMTP id q5so2301274wrv.0 for ; Thu, 26 Jan 2023 08:05:19 -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=+YQldu2slJ4MvSxr35Hf2sVCTu/CxyT5CpVDjVkIaL4=; b=CXbsHAgy7Omnr8tFRMY3p1ejXcJ3gNSs66PaeAyt0Xx15dT11in3LnYQVBkGFbl1ek QF0AXPGlyN4CiMzChLmnfA9cTJXRi/yB+02DD+VEpmpfCcbcbAA9ToErMx/dDq0ihts+ hf96ooIz4P1tkGbA7raVe1kRReDXiB2UabrapTS7miaphiPii3VRM1QU6jlcTwiE7pBy mFyyrb2uKN38bCqQlmY5lAk+e5bPgZOoUEg1XwLWgXhT90g1DpxIlOkXgH5Jb57+TXEP iWaQT7gxLm2GLmt3hlSHi3MevVoSugdLzCQRcRGCLt8Vg+mRf9cJLo6rUIZpovMG/8yx Q7SQ== 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=+YQldu2slJ4MvSxr35Hf2sVCTu/CxyT5CpVDjVkIaL4=; b=T89Wfc/BDlmhEUvH1pW72GCspcbvCWvYpxOfZc+2woFLAulclgpSOVeorpSfY613q6 bMotqD9NHC14iQ2FzvFp5iDXzCGJ1NTsBE86zzj3oJ4Xqrsv1lLprd/5TfgQ/cR7m4d1 s1TwnQIgE+FtDj6c+Iz1SwQO7/8UKKnUVMipgID4xsDE42HoLEvOVtVd/JUi6UBxNx1N +VOeThbpdEq/EJrkuatCJp4tY153gZ5uosjTEm98uXEdA4yRsGKmhvTWPaG9AGUkGHNc JQghSpxoDKXtF1dnuxNvQYquKHuKwa9vbhS+/lGdAqpeHhWgxhPx5nJJH402Pz2tlM1o Zfbg== X-Gm-Message-State: AFqh2kpLQhcroGSmPahMkZpLXBM+ndv3P81/BJwcCUIZ+HGwkVoGmob6 unKBv/uAUNm34dYHc0kn2m2jQw== X-Google-Smtp-Source: AMrXdXs7vEPT0f5hb4FM+P2AcjT0WieX7ZI6IiWI4IzuOFd1M5WPwj6sqir1GxckesXFYSHejRaysQ== X-Received: by 2002:a05:6000:10d:b0:2be:bfc5:c2ef with SMTP id o13-20020a056000010d00b002bebfc5c2efmr19171815wrx.49.1674749119501; Thu, 26 Jan 2023 08:05:19 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:19 -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 v2 16/17] android: boot: support bootconfig Date: Thu, 26 Jan 2023 17:05:05 +0100 Message-Id: <20230126160506.1026643-17-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 This adds support for Bootconfig feature. - The bootconfig feature replaces the androidboot.* kernel cmdline options. This was adapted from downstream [1] commit : 7af0a0506d4d ("cuttlefish: support bootconfig parameters"). Link:[1] https://android.googlesource.com/platform/external/u-boot/ Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- boot/image-android.c | 58 +++++++++++++++++++++++++++++++++++++++-- include/android_image.h | 11 ++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/boot/image-android.c b/boot/image-android.c index dd06c09279..5c2217676e 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -18,6 +18,45 @@ static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1]; +static ulong checksum(const unsigned char *buffer, ulong size) +{ + ulong sum = 0; + + for (ulong i = 0; i < size; i++) + sum += buffer[i]; + return sum; +} + +static bool is_trailer_present(ulong bootconfig_end_addr) +{ + return !strncmp((char *)(bootconfig_end_addr - BOOTCONFIG_MAGIC_SIZE), + BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_SIZE); +} + +static ulong add_trailer(ulong bootconfig_start_addr, ulong bootconfig_size) +{ + ulong end; + ulong sum; + + if (!bootconfig_start_addr) + return -1; + if (!bootconfig_size) + return 0; + + end = bootconfig_start_addr + bootconfig_size; + if (is_trailer_present(end)) + return 0; + + memcpy((void *)(end), &bootconfig_size, BOOTCONFIG_SIZE_SIZE); + sum = checksum((unsigned char *)bootconfig_start_addr, bootconfig_size); + memcpy((void *)(end + BOOTCONFIG_SIZE_SIZE), &sum, + BOOTCONFIG_CHECKSUM_SIZE); + memcpy((void *)(end + BOOTCONFIG_SIZE_SIZE + BOOTCONFIG_CHECKSUM_SIZE), + BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_SIZE); + + return BOOTCONFIG_TRAILER_SIZE; +} + static void android_boot_image_v3_v4_parse_hdr(const struct andr_boot_img_hdr_v3 *hdr, struct andr_image_data *data) { @@ -61,6 +100,7 @@ static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vendor_i data->kernel_addr = hdr->kernel_addr; data->ramdisk_addr = hdr->ramdisk_addr; data->dtb_load_addr = hdr->dtb_addr; + data->bootconfig_size = hdr->bootconfig_size; end = (ulong)hdr; end += hdr->page_size; if (hdr->vendor_ramdisk_size) { @@ -75,7 +115,13 @@ static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vendor_i 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->bootconfig_addr = end; + if (hdr->bootconfig_size) { + data->bootconfig_size += add_trailer(data->bootconfig_addr, + data->bootconfig_size); + data->ramdisk_size += data->bootconfig_size; + } + end += ALIGN(data->bootconfig_size, hdr->page_size); data->vendor_boot_img_total_size = end - (ulong)hdr; } @@ -352,7 +398,15 @@ int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img, memcpy((void *)(ramdisk_ptr), (void *)img_data.vendor_ramdisk_ptr, img_data.vendor_ramdisk_size); memcpy((void *)(ramdisk_ptr + img_data.vendor_ramdisk_size), - (void *)img_data.ramdisk_ptr, img_data.boot_ramdisk_size); + (void *)img_data.ramdisk_ptr, + img_data.boot_ramdisk_size); + if (img_data.bootconfig_size) { + memcpy((void *) + (ramdisk_ptr + img_data.vendor_ramdisk_size + + img_data.boot_ramdisk_size), + (void *)img_data.bootconfig_addr, + img_data.bootconfig_size); + } } printf("RAM disk load addr 0x%08lx size %u KiB\n", diff --git a/include/android_image.h b/include/android_image.h index 351e17750e..6e1afae4c0 100644 --- a/include/android_image.h +++ b/include/android_image.h @@ -25,6 +25,14 @@ #define ANDR_VENDOR_BOOT_ARGS_SIZE 2048 #define ANDR_VENDOR_BOOT_NAME_SIZE 16 +#define BOOTCONFIG_MAGIC "#BOOTCONFIG\n" +#define BOOTCONFIG_MAGIC_SIZE 12 +#define BOOTCONFIG_SIZE_SIZE 4 +#define BOOTCONFIG_CHECKSUM_SIZE 4 +#define BOOTCONFIG_TRAILER_SIZE BOOTCONFIG_MAGIC_SIZE + \ + BOOTCONFIG_SIZE_SIZE + \ + BOOTCONFIG_CHECKSUM_SIZE + struct andr_boot_img_hdr_v3 { u8 magic[ANDR_BOOT_MAGIC_SIZE]; @@ -333,6 +341,9 @@ struct andr_image_data { ulong recovery_dtbo_ptr; u32 recovery_dtbo_size; + ulong bootconfig_addr; + ulong bootconfig_size; + const char *kcmdline; const char *kcmdline_extra; const char *image_name; From patchwork Thu Jan 26 16:05:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Safae Ouajih X-Patchwork-Id: 1732371 X-Patchwork-Delegate: sjg@chromium.org 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=pass (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=FAWsyVkR; 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 4P2lyt4t5zz23h7 for ; Fri, 27 Jan 2023 03:09:42 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4A49885745; Thu, 26 Jan 2023 17:08:19 +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="FAWsyVkR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A365856D5; Thu, 26 Jan 2023 17:05:39 +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-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) (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 904C6856F9 for ; Thu, 26 Jan 2023 17:05: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=souajih@baylibre.com Received: by mail-wr1-x42a.google.com with SMTP id m7so2250296wru.8 for ; Thu, 26 Jan 2023 08:05:20 -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=ZcJQjocQOK+EsU3n4UgrygVey5ZfTvcCP1pHLpjdhYE=; b=FAWsyVkRRQfzMCZan6n7aWcLHkrUym2d771rCkSjezBPCuuUPWr83iKzuDgRbHi/9p nonlEqoAUXcI7QTUEmfqT8ouhM+8GUQ/xURkzb17mAaJgQhuoOSg4clxXKmroNeE+FE9 qqqeGj1Uou8zFtFLAAb4JpSe7nBHEb0rRfCy66qZArx6g7Pz6L774r7ct6D1KlYlJwcs gaHFSKyyrLlWJHTyyAK5gVDdpnJVYEpIXEejOicxbR/N2mNB7BVNrxmGvaROd+J7JXec BD5h6rLvzEIDc6nfSEc3THPGZbCb7ljd9pATXOSXK/4vJHW87ziYN+f9lc3dO++SW3rJ R4Sg== 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=ZcJQjocQOK+EsU3n4UgrygVey5ZfTvcCP1pHLpjdhYE=; b=5LOS0QUKDlQjJvdn9kxpFQwwo9V02MtWCB/EmCwu9h6liiETgrOH0IFI/JuSOHCD4V Ov5hQSME626DWGbDunKZBQmc8khwaSBQ126AXw1uoSNHliv//P1+JCcx6pK9A2cEnkGj YAela4xjsrh7If9BhJ/AOeop5aTvP6CCDhEroFKcpj58t1quRqHFd7TSH7WehUKJJ1T2 aFVOvr3c4I+ekANCWmSe3V3G940Qd5dMHZe9aNA3AOY1aukJLXfL/ouz07PNI3Wn7jzH qpuoEAx3U29q6vJ0p3EgMF4+4KzSDd+yL4rlWCqK1Ds+o58+/X8GzNqlHck+Gg0mX5E2 p35w== X-Gm-Message-State: AO0yUKXKY3tTL99SbqRQA25vhYH/BgFUzU2nNeskVhQejo46iITPWKQN zrkpWBAxM8Uzk+3LhAj8cyI/Hg== X-Google-Smtp-Source: AK7set8GFNwrFTmdPCbJ8QnzgIt1cbG7es3X8kFzCDGacblhsAH4+/KCdh2vphGid3xKEqlj9zKDsQ== X-Received: by 2002:a5d:58e9:0:b0:2bf:b65f:d144 with SMTP id f9-20020a5d58e9000000b002bfb65fd144mr7392505wrd.50.1674749120314; Thu, 26 Jan 2023 08:05:20 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-295-18.w90-116.abo.wanadoo.fr. [90.116.132.18]) by smtp.gmail.com with ESMTPSA id o1-20020adfcf01000000b002bfb6b9f55bsm1721235wrj.16.2023.01.26.08.05.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 08:05:19 -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 v2 17/17] test/py: android: extend abootimg test Date: Thu, 26 Jan 2023 17:05:06 +0100 Message-Id: <20230126160506.1026643-18-souajih@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126160506.1026643-1-souajih@baylibre.com> References: <20230126160506.1026643-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 test_abootimg is extended to include the testing of boot images version 4. For this, boot.img and vendor_boot.img have been generated using mkbootimg tool with setting the header version to 4. This tests: - Getting the header version using abootimg - Extracting the load address of the dtb - Extracting the dtb start address in RAM Running test: $ ./test/py/test.py --bd sandbox --build -k test_abootimg Signed-off-by: Safae Ouajih Reviewed-by: Simon Glass --- test/py/tests/test_android/test_abootimg.py | 135 ++++++++++++++++++-- 1 file changed, 122 insertions(+), 13 deletions(-) diff --git a/test/py/tests/test_android/test_abootimg.py b/test/py/tests/test_android/test_abootimg.py index 43a7099c46..a5c734b9c5 100644 --- a/test/py/tests/test_android/test_abootimg.py +++ b/test/py/tests/test_android/test_abootimg.py @@ -32,6 +32,23 @@ Now one can obtain original boot.img from this hex dump like this: $ xxd -r -p boot.img.gz.hex boot.img.gz $ gunzip -9 boot.img.gz + +For boot image header version 4, these tests rely on two images that are generated +using the same steps above : + +1- boot.img : + $ mkbootimg --kernel ./kernel --ramdisk ./ramdisk.img \ + --cmdline "cmdline test" --dtb ./dtb.img \ + --os_version R --os_patch_level 2019-06-05 \ + --header_version 4 --output ./boot.img + +2- vendor_boot.img + $ mkbootimg --kernel ./kernel --ramdisk ./ramdisk.img \ + --cmdline "cmdline test" --dtb ./dtb.img \ + --os_version R --os_patch_level 2019-06-05 \ + --pagesize 4096 --vendor_ramdisk ./ramdisk.img \ + --header_version 4 --vendor_boot ./vboot.img \ + """ # boot.img.gz hex dump @@ -44,6 +61,24 @@ b7762ffff07d345446c1281805e8a0868d81e117a45e111c0d8dc101b253 9c03c41a0c90f17fe85400986d82452b6c3680198a192a0ce17c3610ae34 d4a9820881a70f3873f35352731892f3730b124b32937252a96bb9119ae5 463a5546f82c1f05a360148c8251300a462e000085bf67f200200000""" + +# boot img v4 hex dump +boot_img_hex = """1f8b080827b0cd630203626f6f742e696d6700edd8bd0d82601885d1d7c4 +58d8c808b88195bd098d8d246e40e42b083f1aa0717be99d003d277916b8 +e5bddc8a7b792d8e8788c896ce9b88d32ebe6c971e7ddd3543cae734cd01 +c0ffc84c0000b0766d1a87d4e5afeadd3dab7a6f10000000f84163d5d7cd +d43a000000000000000060c53e7544995700400000""" + +# vendor boot image v4 hex dump +vboot_img_hex = """1f8b0808baaecd63020376626f6f742e696d6700edd8310b824018c6f1b3 +222a08f41b3436b4280dcdd19c11d16ee9109d18d59042d047ec8b04cd0d +d19d5a4345534bf6ffc173ef29272f38e93b1d0ec67dd79d548462aa1cd2 +d5d20b0000f8438678f90c18d584b8a4bbb3a557991ecb2a0000f80d6b2f +f4179b656be5c532f2fc066f040000000080e23936af2755f62a3d918df1 +db2a7ab67f9ffdeb7df7cda3465ecb79c4ce7e5c577562bb9364b74449a5 +1e467e20c53c0a57de763193c1779b3b4fcd9d4ee27c6a0e00000000c0ff +309ffea7010000000040f1dc004129855400400000""" + # Expected response for "abootimg dtb_dump" command dtb_dump_resp="""## DTB area contents (concat format): - DTB #0: @@ -56,15 +91,21 @@ dtb_dump_resp="""## DTB area contents (concat format): (DTB)compatible = y2,z2""" # Address in RAM where to load the boot image ('abootimg' looks in $loadaddr) loadaddr = 0x1000 +# Address in RAM where to load the vendor boot image ('abootimg' looks in $vloadaddr) +vloadaddr= 0x10000 # Expected DTB #1 offset from the boot image start address dtb1_offset = 0x187d +# Expected DTB offset from the vendor boot image start address +dtb2_offset = 0x207d # DTB #1 start address in RAM dtb1_addr = loadaddr + dtb1_offset +# DTB #2 start address in RAM +dtb2_addr = vloadaddr + dtb2_offset class AbootimgTestDiskImage(object): """Disk image used by abootimg tests.""" - def __init__(self, u_boot_console): + def __init__(self, u_boot_console, image_name, hex_img): """Initialize a new AbootimgDiskImage object. Args: @@ -74,13 +115,13 @@ class AbootimgTestDiskImage(object): Nothing. """ - gz_hex = u_boot_console.config.persistent_data_dir + '/boot.img.gz.hex' - gz = u_boot_console.config.persistent_data_dir + '/boot.img.gz' + gz_hex = u_boot_console.config.persistent_data_dir + '/' + image_name + '.gz.hex' + gz = u_boot_console.config.persistent_data_dir + '/' + image_name + '.gz' - filename = 'boot.img' + filename = image_name persistent = u_boot_console.config.persistent_data_dir + '/' + filename self.path = u_boot_console.config.result_dir + '/' + filename - + u_boot_console.log.action('persistent is ' + persistent) with u_boot_utils.persistent_file_helper(u_boot_console.log, persistent): if os.path.exists(persistent): u_boot_console.log.action('Disk image file ' + persistent + @@ -89,19 +130,17 @@ class AbootimgTestDiskImage(object): u_boot_console.log.action('Generating ' + persistent) f = open(gz_hex, "w") - f.write(img_hex) + f.write(hex_img) f.close() - cmd = ('xxd', '-r', '-p', gz_hex, gz) u_boot_utils.run_and_log(u_boot_console, cmd) - cmd = ('gunzip', '-9', gz) u_boot_utils.run_and_log(u_boot_console, cmd) cmd = ('cp', persistent, self.path) u_boot_utils.run_and_log(u_boot_console, cmd) -gtdi = None +gtdi1 = None @pytest.fixture(scope='function') def abootimg_disk_image(u_boot_console): """pytest fixture to provide a AbootimgTestDiskImage object to tests. @@ -109,10 +148,36 @@ def abootimg_disk_image(u_boot_console): function-scoped. However, we don't need to actually do any function-scope work, so this simply returns the same object over and over each time.""" - global gtdi - if not gtdi: - gtdi = AbootimgTestDiskImage(u_boot_console) - return gtdi + global gtdi1 + if not gtdi1: + gtdi1 = AbootimgTestDiskImage(u_boot_console, 'boot.img', img_hex) + return gtdi1 + +gtdi2 = None +@pytest.fixture(scope='function') +def abootimgv4_disk_image_vboot(u_boot_console): + """pytest fixture to provide a AbootimgTestDiskImage object to tests. + This is function-scoped because it uses u_boot_console, which is also + function-scoped. However, we don't need to actually do any function-scope + work, so this simply returns the same object over and over each time.""" + + global gtdi2 + if not gtdi2: + gtdi2 = AbootimgTestDiskImage(u_boot_console, 'vendor_boot.img', vboot_img_hex) + return gtdi2 + +gtdi3 = None +@pytest.fixture(scope='function') +def abootimgv4_disk_image_boot(u_boot_console): + """pytest fixture to provide a AbootimgTestDiskImage object to tests. + This is function-scoped because it uses u_boot_console, which is also + function-scoped. However, we don't need to actually do any function-scope + work, so this simply returns the same object over and over each time.""" + + global gtdi3 + if not gtdi3: + gtdi3 = AbootimgTestDiskImage(u_boot_console, 'bootv4.img', boot_img_hex) + return gtdi3 @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('android_boot_image') @@ -157,3 +222,47 @@ def test_abootimg(abootimg_disk_image, u_boot_console): u_boot_console.run_command('fdt get value v / model') response = u_boot_console.run_command('env print v') assert response == 'v=x2' + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('android_boot_image') +@pytest.mark.buildconfigspec('cmd_abootimg') +@pytest.mark.buildconfigspec('cmd_fdt') +@pytest.mark.requiredtool('xxd') +@pytest.mark.requiredtool('gunzip') +def test_abootimgv4(abootimgv4_disk_image_vboot, abootimgv4_disk_image_boot, u_boot_console): + """Test the 'abootimg' command with boot image header v4.""" + + u_boot_console.log.action('Loading disk image to RAM...') + u_boot_console.run_command('setenv loadaddr 0x%x' % (loadaddr)) + u_boot_console.run_command('setenv vloadaddr 0x%x' % (vloadaddr)) + u_boot_console.run_command('host load hostfs - 0x%x %s' % (vloadaddr, + abootimgv4_disk_image_vboot.path)) + u_boot_console.run_command('host load hostfs - 0x%x %s' % (loadaddr, + abootimgv4_disk_image_boot.path)) + u_boot_console.run_command('abootimg addr 0x%x 0x%x' % (loadaddr, vloadaddr)) + u_boot_console.log.action('Testing \'abootimg get ver\'...') + response = u_boot_console.run_command('abootimg get ver') + assert response == "4" + u_boot_console.run_command('abootimg get ver v') + response = u_boot_console.run_command('env print v') + assert response == 'v=4' + + u_boot_console.log.action('Testing \'abootimg get recovery_dtbo\'...') + response = u_boot_console.run_command('abootimg get recovery_dtbo a') + assert response == 'Error: header version must be >= 1 and <= 2 to get dtbo' + + u_boot_console.log.action('Testing \'abootimg get dtb_load_addr\'...') + u_boot_console.run_command('abootimg get dtb_load_addr a') + response = u_boot_console.run_command('env print a') + assert response == 'a=11f00000' + + u_boot_console.log.action('Testing \'abootimg get dtb --index\'...') + u_boot_console.run_command('abootimg get dtb --index=1 dtb2_start') + response = u_boot_console.run_command('env print dtb2_start') + correct_str = "dtb2_start=%x" % (dtb2_addr) + assert response == correct_str + + u_boot_console.run_command('fdt addr $dtb2_start') + u_boot_console.run_command('fdt get value v / model') + response = u_boot_console.run_command('env print v') + assert response == 'v=x2'