Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5DC4CC4321E for ; Sat, 26 Nov 2022 17:20:16 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5B1A585280; Sat, 26 Nov 2022 18:18:40 +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="2ClB8rzz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E284F85098; Sat, 26 Nov 2022 17:59:52 +0100 (CET) Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3FED885023 for ; Sat, 26 Nov 2022 17:59: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=souajih@baylibre.com Received: by mail-wr1-x42e.google.com with SMTP id h11so3524017wrw.13 for ; Sat, 26 Nov 2022 08:59:50 -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=7KCjs3M/TeJ+ms5jyRYYi7h79+QEMYXnnui1RUoMMaA=; b=2ClB8rzzqp5CnaJ2ygAdMMcQy5Nk6K/4YUuypdHrih6dEY6VlRRejENZS9X+f5HhK3 cV0hqUX0p4rmKWIKX5xnJEobFlk1RGN7Lum3IF/EuoKmGtinA0C+tKRFg0SkdepP/q4C XNPIgh6qcGfOAPVTadduQHIP8JtUWwA7uYc9+gnN3kuJ57A409f4RsrbSFptBqWfs8/G rcUK14sEKPnyc29+TAcGXjLMZFP4ZEuWNMeWJ+g6pZNAcYQGEU/FA9BZ8rZe9aI7+wDL fhvD8+eZwIkp22qnGTbxKU36lXH4qnstbsxVzV2uImzfZwray4rpoXOgPu9o8jsb4Nri LtcA== 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=7KCjs3M/TeJ+ms5jyRYYi7h79+QEMYXnnui1RUoMMaA=; b=If/0UziAaVjLkJtuLumbBV5nXSWQsXCXZTLMfdQ0luVuC9aOfGW2ikcCpXXXxsQ1MU V/uAm85qgCxVMOKXQnddu6rHzidTQqfJQld6PbU09iWsDszetU78wh7rISx3DBWFb+nr v73qh3oYY604oYuHrUfhZtACquQVQGjejMnsep3CHquU5oZyl4nVHZ0jUaUq4dyv5SYz 1A+0zUKcrIvr9O+qruTmdofKNXe4au8gYaP5nCMRZ1GiB9W8GvAwyUqUpiMYN65Lkw+B /k21gz4OJf3fgiw09ERhbXBFO24wC+FJSHAPO5moR7B+NDJ55Mrq7uImxMGEcoKMEUTt 3YuA== X-Gm-Message-State: ANoB5pmDdM+pnUN12kMT73690QeVJs/vODX/LDmjA+xM+Rwkj/AxHMgv kMakTw/S4RnooeY8LtsqhDfCUA== X-Google-Smtp-Source: AA0mqf5pkaEpRwhvjmrZDTM252qITxyLObbEBExdW4VAiI1qP/KKRLzqXSwncRLC3ccCUeRNYK2++Q== X-Received: by 2002:adf:ec84:0:b0:241:c36f:c3b1 with SMTP id z4-20020adfec84000000b00241c36fc3b1mr23964012wrn.310.1669481989747; Sat, 26 Nov 2022 08:59:49 -0800 (PST) Received: from safae.baylibre.local ([2a04:cec0:11b5:4031:7588:eb2c:a5c2:aa6d]) by smtp.gmail.com with ESMTPSA id c15-20020adfe70f000000b00241e8d00b79sm7462408wrm.54.2022.11.26.08.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Nov 2022 08:59:49 -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 10/17] android: boot: add vendor boot image to prepare for v3, v4 support Date: Sat, 26 Nov 2022 17:59:24 +0100 Message-Id: <20221126165931.197607-11-souajih@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221126165931.197607-1-souajih@baylibre.com> References: <20221126165931.197607-1-souajih@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Sat, 26 Nov 2022 18:18:14 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 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 | 40 ++++++++++++++++++++++++---------------- boot/image-board.c | 3 +-- boot/image-fdt.c | 3 ++- cmd/abootimg.c | 4 ++-- include/image.h | 22 ++++++++++++++-------- 6 files changed, 47 insertions(+), 33 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index a4c0870c0fea..e44dc550077d 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; @@ -968,7 +968,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 daf51a7e3b8b..eb821b08ccf4 100644 --- a/boot/image-android.c +++ b/boot/image-android.c @@ -65,7 +65,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"); @@ -113,8 +114,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. @@ -126,14 +129,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_v1_v2 *hdr, int verify, +int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *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); @@ -200,11 +204,12 @@ bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr) return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE); } -ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr) +ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *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) @@ -213,22 +218,24 @@ ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr) return img_data.boot_img_total_size; } -ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr) +ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *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_v1_v2 *hdr) +ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *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; @@ -241,11 +248,11 @@ ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr) } int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *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) { @@ -267,7 +274,7 @@ int android_image_get_second(const struct andr_boot_img_hdr_v0_v1_v2 *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) { @@ -398,6 +405,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 @@ -407,12 +415,12 @@ 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, const void *vendor_boot_img, + u32 index, ulong *addr, u32 *size) { struct andr_image_data img_data; - if (!android_image_get_data((void *)hdr_addr, &img_data)) + if (!android_image_get_data((void *)hdr_addr, vendor_boot_img, &img_data)) return false; ulong dtb_img_addr; /* address of DTB part in boot image */ diff --git a/boot/image-board.c b/boot/image-board.c index acbaafc1b12e..c8e41cc8706f 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 b7cc9bfd538f..6a08e8a07ed7 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, NULL, + 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 41b733f7713b..e8c70a93cbf4 100644 --- a/cmd/abootimg.c +++ b/cmd/abootimg.c @@ -70,7 +70,7 @@ static int abootimg_get_dtb_load_addr(int argc, char *const argv[]) return CMD_RET_USAGE; struct andr_image_data img_data = {0}; - if (!android_image_get_data((void *)abootimg_addr(), &img_data)) + if (!android_image_get_data((void *)abootimg_addr(), NULL, &img_data)) return CMD_RET_FAILURE; if (img_data.header_version < 2) { @@ -114,7 +114,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(), NULL, num, &addr, &size)) { return CMD_RET_FAILURE; } diff --git a/include/image.h b/include/image.h index 3b5742104cf7..a0affc514a5d 100644 --- a/include/image.h +++ b/include/image.h @@ -1724,20 +1724,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_v1_v2; -int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify, +int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *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_v1_v2 *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_v1_v2 *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_v1_v2 *hdr); -ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr); -ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr); +bool android_image_get_dtb_by_index(ulong hdr_addr, const void *vendor_boot_img, + u32 index, ulong *addr, u32 *size); +ulong android_image_get_end(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, + const void *vendor_boot_img); +ulong android_image_get_kload(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, + const void *vendor_boot_img); +ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, + const void *vendor_boot_img); void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr); #ifdef CONFIG_CMD_ABOOTIMG bool android_image_print_dtb_contents(ulong hdr_addr); -- 2.25.1