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 37CADC4321E for ; Sat, 26 Nov 2022 17:18:55 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E0045851EA; Sat, 26 Nov 2022 18:18: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=pass (2048-bit key; unprotected) header.d=baylibre-com.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="OUUeo80K"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6644185160; Sat, 26 Nov 2022 17:59:42 +0100 (CET) Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (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 2D30985023 for ; Sat, 26 Nov 2022 17:59:39 +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-x434.google.com with SMTP id b12so10838034wrn.2 for ; Sat, 26 Nov 2022 08:59:39 -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=8SVFv5Z3vF4BXoICWJV28ukRCxuqzPszvySWxxYSkUU=; b=OUUeo80KBMbDwka1xcj5gEqO/4bQbGTEwOhVoNkky2hm2jbWfmWOvMUdU285lnTFSe mcIu9WADELYUozukWlCHC9KBkzMRUbrRULwOSTiufuZYkj/cozazpb0+3pIjT02TvPoA WyJrj5BIRxKJbf3ggz37VI8jJNiB5HPi+r63i5HkI12DrC4PNUQfGs5OTdZHoyBbRYqw KgAN+2VkWM+0nnJ7Zy/vs9dfs8WWRWkgvAHcedURPKqF/Jk3BNT0nC2vuncjWn3IOM4y pRrZhRT1Fz+YL4F/zbxnGkkYzdlTjlNPCBqgaI4Sq2jCG6k8JUQf4hjVjbrHBb8cHywi 1Rsw== 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=8SVFv5Z3vF4BXoICWJV28ukRCxuqzPszvySWxxYSkUU=; b=VjbydspZupYH/S4+yDkbufHvEcx+qFVuLOAAWoDBEeDERjLHu7BU0HgZ9LLm1wkhNI xfDpUNf4s1/TNPUgqWPUN38yCFgiD1bLfxEjBn3VMxlkrIUHhXGTR2ggn0dUn9zaWse3 aFYXnHUQospV3rF3V+0xLVsNsgs3cuOHGn/CojJ0W7QKTX89QFZx80TjxgknseoHP2E9 4RvVg4X5sb3hhNkiOJSm6ozdFb2oMD3YNTNRZhehH+y8/ngWEIeVPJCTXkMCMkhIf2MT ROI1oS6FzvH1RxLROSaour9LH1ivdgN6RYF1WhWrG+zg20dOZ/tf/lQqf6PMqE/+z5t7 fa9g== X-Gm-Message-State: ANoB5pk8rfU9jujbqNzh8UkMThm3lo8EZbOABv5g76xlhTluSOlhESLl ehe9AGuHI5/SZe6n0HqFXtlqFA== X-Google-Smtp-Source: AA0mqf5mtIBYW7YbKsoptqpZIfzw4PRNPIf1/XzCYMGCzjH8LzrBStsABrjgST+1vmu8ZBUqiXLf+g== X-Received: by 2002:adf:cd0f:0:b0:236:5700:d4cb with SMTP id w15-20020adfcd0f000000b002365700d4cbmr27816547wrm.597.1669481978654; Sat, 26 Nov 2022 08:59:38 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Nov 2022 08:59:38 -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 03/17] android: boot: replace android_image_check_header Date: Sat, 26 Nov 2022 17:59:17 +0100 Message-Id: <20221126165931.197607-4-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 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 --- 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 926d94ecbe8e..c67949b8b563 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_v1_v2 *hdr, int v return 0; } -int android_image_check_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr) +bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *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_v1_v2 *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 34d1e5f18bef..acbaafc1b12e 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 ad61cce7588d..3c344b6c0367 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 7b2f964b4c72..4cfdc108e8f7 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 931cf18c7e82..e175c920d3fb 100644 --- a/include/image.h +++ b/include/image.h @@ -1724,7 +1724,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_v1_v2; -int android_image_check_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr); int android_image_get_kernel(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, int verify, ulong *os_data, ulong *os_len); int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0_v1_v2 *hdr, @@ -1739,6 +1738,7 @@ 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); void android_print_contents(const struct andr_boot_img_hdr_v0_v1_v2 *hdr); bool android_image_print_dtb_contents(ulong hdr_addr); +bool is_android_boot_image_header(const struct andr_boot_img_hdr_v0_v1_v2 *hdr); /** * board_fit_config_name_match() - Check for a matching board name -- 2.25.1