From patchwork Tue Sep 14 06:31:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathew McBride X-Patchwork-Id: 1527746 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=traverse.com.au header.i=@traverse.com.au header.a=rsa-sha256 header.s=fm1 header.b=YzlGZ2jj; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=dVffNAIV; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H7tnf0Vy9z9sW4 for ; Tue, 14 Sep 2021 16:32:52 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CDDD982BC4; Tue, 14 Sep 2021 08:32:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=traverse.com.au 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=traverse.com.au header.i=@traverse.com.au header.b="YzlGZ2jj"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="dVffNAIV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E3F0882C47; Tue, 14 Sep 2021 08:32:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 117B28296F for ; Tue, 14 Sep 2021 08:32:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=traverse.com.au Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=matt@traverse.com.au Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 3B02332009BD; Tue, 14 Sep 2021 02:32:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 14 Sep 2021 02:32:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=traverse.com.au; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm1; bh=w4zm97F0IjC3YGWjsKjPibStih /GSDK9+DNxYBtsHEc=; b=YzlGZ2jj1Sw7SIPJ+qEJ3mZJr2B0xRGTIvNj02qQ6B zdftsGnZpAQnQalS+HvWghESH1XYEg6TyDIcifyc01K4Apojil8ITS/uuoonXPAr rECppSsKZ/HdjKZpqgHYj3DN0UAq0YzNX5UTKoq32KxX2CwJun7iw1I8q8d/S8D0 3JtkIoMxe8k3TB5m/HXzcQXT5bkcBl/+dbGb45Mz30zjUzNzCZ1XWUTIFeK6KPwf GD5YpYmjCMdM/ZUAsInPBiKF30A1SoIrJwm1mt6Ej9sbzRzM+FXIjca79YjrLRj7 WHhHfK6+OhrBvmpOL1+QkTyQDW+Sx0z7oGA7TeFQ5qsQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=w4zm97F0IjC3YGWjs KjPibStih/GSDK9+DNxYBtsHEc=; b=dVffNAIVTmAfxwGf0+JfJstKu+JjpuYeL 71vxqFP4tVhFTU7fggYJRL4cOnHz9uihFJ1m4hDA/iCEi33zl9Jtc1d0zAJ/WryI ieXQbgnQ1cGL2Cwh/P1BxCvRB47VwZ00oK+WaHLXjTp9qod/IM4scjOu2IFFX5dr JjdmlhPrYFR5sL/uEr/AuBQpJvD7xPh8vU2YVOMRHWmXYkn0Kt6yOx+UKSPowF+Q ceGqiel/EPAS3GfugMyu+sf2HK8XT1Lfq4pdg2nfihuGTn4g4nKVQg9Ddxq6KTxO DjIMNhMyKWePwCRNEf9qL/9jEUsNfqU0gm6SUFfWpcMLO9EHtm+fw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudegkedguddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffoggfgsedtkeertd ertddtnecuhfhrohhmpeforghthhgvficuofgtuehrihguvgcuoehmrghtthesthhrrghv vghrshgvrdgtohhmrdgruheqnecuggftrfgrthhtvghrnhepgfekhefgieehffetudehve evudeutddtteeiffeugfevuedttddtgeelfeekledvnecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomhepmhgrthhtsehtrhgrvhgvrhhsvgdrtghomh drrghu X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Sep 2021 02:32:29 -0400 (EDT) From: Mathew McBride To: u-boot@lists.denx.de, Alexandru Gagniuc , Simon Glass , trini@konsulko.com Cc: Mathew McBride Subject: [PATCH] image: fit: fix byte order for crc32 hash check Date: Tue, 14 Sep 2021 06:31:41 +0000 Message-Id: <20210914063141.28737-1-matt@traverse.com.au> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 In 92055e138f ("image: Drop if/elseif hash selection in calculate_hash()") the FIT image hash verification code was simplified to use the hash API. This broke verification of CRC32 hash FIT images (e.g NXP MC firmware) as the hash API crc32 calculates in big endian (refer commit 74a18ee8a563, "crc32: Correct endianness of crc32 result"), whereas the previous call directly to crc32_wd does not do a byteswap. Example: dumpimage -l qoriq-mc-binary/ls1088a/mc_ls1088a_10.29.1.itb FIT description: MC Firmware Created: Fri Aug 27 14:14:32 2021 ... Hash algo: crc32 Hash value: c09d959c Was returning FB9D3710 to fit_image_check_hash instead of C09D959C Correct the byte order in the crc32_uimage_fixup so the little endian values are returned. Fixes: 92055e138f "image: Drop if/elseif hash selection in calculate_hash()" Signed-off-by: Mathew McBride --- common/image-fit.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/image-fit.c b/common/image-fit.c index 92d9141bcd..97b4f0b4b2 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1195,6 +1195,11 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp) static void crc32_uimage_fixup(void *value) { + /* In the CRC32 case, value will be byte swapped by the hash library + * function, but the FIT is specified (and checked) in little-endian + */ + *((uint32_t *)value) = ntohl(*((uint32_t *)value)); + /* TODO: In C, this type punning is undefined behavior: */ *((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value)); }