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