From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4F2CC433F5 for ; Tue, 21 Dec 2021 15:58:59 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F1CC38379E; Tue, 21 Dec 2021 16:57:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="sYJWpO8f"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F1D288304F; Tue, 21 Dec 2021 16:56:31 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2FC8A8350D for ; Tue, 21 Dec 2021 16:55:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DF74A61666; Tue, 21 Dec 2021 15:55:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CDF7C36AE9; Tue, 21 Dec 2021 15:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640102150; bh=a6YPJ1OVaKpvn1yzmV+2w4TdrwYz1fNtn05E4YjALxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sYJWpO8fxMMlGCe9G1Ll1RNaAZCZQF0fHIOMw6dAwAZZDKaGBVpAObtm/FeAgORme yevWiB1vYZyoxudjI/i2xYHEyYqKLcsIq6tLAlyHbga3EwSj+4UXKWBhzdS8MoxtMS /jYu/HaC2Qugjs/rj06/3aH1vDS/13ShU17pH3ZCd8lhgyLEXpLD6wM7xJ7nLPmvAW diZ2g18vAB6Q5hFLxmWMtAdx7/z3MHVlt+eP5hYtTPDC6Xfxv7Ae5Hl5MfCl+f0V6B jbQjXOG5/rP1phjViogCBvHXhjeXx8tHmNyMQD82aPgaUNyFCbl67/ZPLNX1fWrN13 iNzbu0NQ4EKHg== Received: by pali.im (Postfix) id D9A9F284D; Tue, 21 Dec 2021 16:55:49 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Chris Packham Cc: u-boot@lists.denx.de Subject: [PATCH u-boot-marvell 14/16] tools: kwbimage/kwboot: Check ext field for non-zero value Date: Tue, 21 Dec 2021 16:54:14 +0100 Message-Id: <20211221155416.8557-15-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211221155416.8557-1-pali@kernel.org> References: <20211221155416.8557-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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.2 at phobos.denx.de X-Virus-Status: Clean Despite the official specification, BootROM does not look at the lowest bit of ext field but rather checks if ext field is non-zero. Moreover original Marvell doimage tool puts into the mhdr->ext field the number of extended headers, so basically it sets ext filed to non-zero value if some extended header is present. Fix U-Boot dumpimage and kwboot tools to parse correctly also kwbimage files created by Marvell doimage tool, in the same way as the BootROM is doing it when booting these images. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- tools/kwbimage.c | 2 +- tools/kwbimage.h | 6 +++--- tools/kwboot.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 2a0216a537ba..08b0332f5979 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1899,7 +1899,7 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, if (kwbimage_version(ptr) == 0) { struct main_hdr_v0 *mhdr = (struct main_hdr_v0 *)ptr; - if (mhdr->ext & 0x1) { + if (mhdr->ext) { struct ext_hdr_v0 *ext_hdr = (void *)(mhdr + 1); csum = image_checksum8(ext_hdr, sizeof(*ext_hdr) - 1); diff --git a/tools/kwbimage.h b/tools/kwbimage.h index c000cba4b8d1..9ebc7d72d363 100644 --- a/tools/kwbimage.h +++ b/tools/kwbimage.h @@ -208,7 +208,7 @@ static inline size_t kwbheader_size(const void *header) const struct main_hdr_v0 *hdr = header; return sizeof(*hdr) + - (hdr->ext & 0x1) ? sizeof(struct ext_hdr_v0) : 0; + hdr->ext ? sizeof(struct ext_hdr_v0) : 0; } else { const struct main_hdr_v1 *hdr = header; @@ -252,7 +252,7 @@ static inline struct opt_hdr_v1 *opt_hdr_v1_first(void *img) { return NULL; mhdr = img; - if (mhdr->ext & 0x1) + if (mhdr->ext) return (struct opt_hdr_v1 *)(mhdr + 1); else return NULL; @@ -272,7 +272,7 @@ static inline struct opt_hdr_v1 *_opt_hdr_v1_next(struct opt_hdr_v1 *cur) static inline struct opt_hdr_v1 *opt_hdr_v1_next(struct opt_hdr_v1 *cur) { - if (*opt_hdr_v1_ext(cur) & 0x1) + if (*opt_hdr_v1_ext(cur)) return _opt_hdr_v1_next(cur); else return NULL; diff --git a/tools/kwboot.c b/tools/kwboot.c index d22e6ea96a5c..c3d8ab654417 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -1398,7 +1398,7 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz) uint32_t ohdrsz; uint8_t *prev_ext; - if (hdr->ext & 0x1) { + if (hdr->ext) { for_each_opt_hdr_v1 (ohdr, img) if (opt_hdr_v1_next(ohdr) == NULL) break; @@ -1422,7 +1422,7 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz) ohdrsz = sizeof(*ohdr) + 4 + 4 * num_args + binsz + 4; kwboot_img_grow_hdr(hdr, size, ohdrsz); - *prev_ext |= 1; + *prev_ext = 1; ohdr->headertype = OPT_HDR_V1_BINARY_TYPE; ohdr->headersz_msb = ohdrsz >> 16; -- 2.20.1