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: 510917 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1260446jao; Mon, 13 Sep 2021 23:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLRushbJ9OD0mNnm8SRaXqyKcSGi9m7Zkni5iMVZ2NhdH7lU5P94xPUBzQWwPZ4Qf1HTVW X-Received: by 2002:a17:906:2556:: with SMTP id j22mr17849477ejb.233.1631601166491; Mon, 13 Sep 2021 23:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631601166; cv=none; d=google.com; s=arc-20160816; b=Xfj5Y/mxuo1GMqew233IWBxKcJYmFAcRd1pYDLP6ZMsnKLgb+Z67Qpa2lZI4DZzKx4 cHivalGTW+qHW9m6n7240rjsyQwI8KF471t3J/sk3gG1IDo8dD55+vBHQM7xPTLXDuqt bxBJSldOLcy2K0KlaFSIwAu+GQ8vBWkzSkD6GN0BdJJhJZD80KWwaMi1eWHLsHirBY4C gpu0WZFJMsgQNwYwRtOzu//oDcEWuI+VkV44wx0KsGX29KwPXs9YdyTZLbiEU4G0UbUV eigqXxp/tSecttI/cBqej7WfXq9PjtpIE4wctKnjXw42PVKU+uQ8PRn7x218RWa6iFK7 vbxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dkim-signature; bh=w4zm97F0IjC3YGWjsKjPibStih/GSDK9+DNxYBtsHEc=; b=qK0I/V+/xqFGM41qd5rig7vDxxOod2jktH4ptYYgZKLOhvmD3IVp6qLPC1UbcMswis akgwCnkKzFLxkR7N2JBTnW/v0oQGgiSfvwVmrWD5dWdEEA0j/cGYj9UrFvQ6EJweGjfL L5Ay2vQtrMClasu8DLpBfDy6lORqK/LqZohOHHZeeZhCWEqjevFVKafggX6oO4Q3y0Go WrPmv7tg3O5AzwefZiW7HSHYU21ERcEJI9DKJ0/7RgqF5zrLe9s+CahrQi59BgwCWyPG gcQMf+nx24kheGKfM4sA0VE+CCf3dQMjQvp3xrdeo5ZYycPFjLcR8Bu8oNGelJQzT52w IE2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@traverse.com.au header.s=fm1 header.b=YzlGZ2jj; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=dVffNAIV; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id y28si4572515ejk.300.2021.09.13.23.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 23:32:46 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@traverse.com.au header.s=fm1 header.b=YzlGZ2jj; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=dVffNAIV; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de 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(+) -- 2.30.1 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)); }