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 6875CC44501 for ; Mon, 13 Jul 2026 13:21:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D632A84B74; Mon, 13 Jul 2026 15:21:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="CiirAG4+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1989B84A4F; Mon, 13 Jul 2026 08:43:45 +0200 (CEST) Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) (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 DAFF784A48 for ; Mon, 13 Jul 2026 08:43:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=james.hilliard1@gmail.com Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-6a31c05e1f7so478069eaf.0 for ; Sun, 12 Jul 2026 23:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783925021; x=1784529821; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=f99eWAF3nAJQGhqhLaZ6ObFqjbqJ3xRuXpPs85pD4yI=; b=CiirAG4+HGrXXIJ60jXu8ytdT7u13dbnyea7uZc/ptenudeHt9NXgSGD4TS5gODwHr dD4+namBBkYf2QcZY4MfDPBX74+6+6yl7YcfsghzRqGzlEu+mJ3k10WdplkiA9xu0Dhi 1M/NiCmkOdbPFFtyhasDwQWpoGX3akfyjzd92SU6pqCRtFF3OJIJrFesESkPQ1M1XLoe WsqO6f4GUqnB9YL9dskF/4x15qQiruyWTDSDHpG1K7TkvLFc6ZkKVTsB/XBETeFWG5jI +r6TriA3qrnjelraIi3j3xUZ+ptURyg5spjZN6jF1riwM+54G5hZvULhVL0hTZ4OtCoP Bdjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783925021; x=1784529821; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=f99eWAF3nAJQGhqhLaZ6ObFqjbqJ3xRuXpPs85pD4yI=; b=jDcTjm8lGe6wXGdKkT5M5hg1D+YgrEVQ34K/jYEgfDQAx8SDNhGQK1ldWeahUQWvju pw5fp2ZF322L7ZiKVoDJBZs6XmMv9Lkf9p7567rqgsmj4UpLvPlx6H1fFKZmOSxoPfSa Pofrd/WKiX0LABT/1EV2oD1zv/T+kQEupS914F8JVsseY0yqOPsxHBoXRkISrG5fWpaZ r0Qh5DcjpUX56IWLEEFSZcGc4lHGiD+EWc+lnr43fY+AIErbm+QwH8dsM65FoRGTOAKm WiwLxE5V/xBqcm2syaKWB2hwcG9V2bk4DFZzLeMOtKo9seNfgWdQ/GqTkECFWyXsK5JE UsPg== X-Forwarded-Encrypted: i=1; AFNElJ9q9k120nxYVb/pq2dyvwAyvQ//pkbKuz4bpQ9XMQ6cYxEc70lXfNovZB2sCANTscZ90hV/4s0=@lists.denx.de X-Gm-Message-State: AOJu0Yz2BzuKHC13eY8Q+UMQuV6XKXf7f9a4lxzQ/WE+TnSzbncUuCYy NHUovyWfwvO5JOzXawed275FXyIepp0v246BLXq+HuVj2ATQCxwjQqSk X-Gm-Gg: AfdE7cn0kASrbqGF2fdXHvBenBp1doq4XsccdArIi6CZUgIVoV19Kds2ZCTwR/oATKv i8JiEqXIh2QEx+LLBlCN4sNicT6JuXkrjT3UBjekLwBdm//TEhn017K05SRZzle4MBBgZo33uWO Pt8A2Uuba9UBAlYuoeXa7YRDN736bn4dhfhPHAhpBvKpXvS9wb7k99QNfpHqRxYW7lDxHc6KYc/ nWn0O88F8XMaiyDtdLYKj+J3nh6UFf3iVyb0bReKRJT7tjbtloQDqNRBXIW5wIX3EoZiu3GcuVj gyOKxkQFJoiQFMok1XgHmaav+UtZIPbgnP9dS9qRLt2rGer5JCHpRl/nz2UA43GPU6uac6x/AXp yfSFWhcd0IX9zGAJN6xLORz1BKynBRrrfyoNEP8nRNDX/ByS22Rj3NJy9LgceV6AFMeOM0S5SKb CBxo2JtCRl1FtS72Cjvz7+XKx+x7lULqOpEgxmWTCPtrgXEEu+C9DvflUnToZPjj98c5FIL5jxG n4SarmohUVupofSxapocf+ChUiRzae10HUwbJzLPfBToPrPeejYlWDFzFJ95SvC X-Received: by 2002:a05:6820:f02a:b0:6a3:87fd:2135 with SMTP id 006d021491bc7-6a39a71ef64mr4784600eaf.48.1783925021579; Sun, 12 Jul 2026 23:43:41 -0700 (PDT) Received: from [127.0.1.1] (174-29-11-8.hlrn.qwest.net. [174.29.11.8]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-451916ce98dsm12538126fac.13.2026.07.12.23.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jul 2026 23:43:41 -0700 (PDT) From: James Hilliard Date: Mon, 13 Jul 2026 00:43:01 -0600 Subject: [PATCH v4 04/14] crypto: hash: allow DM hash in SPL MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260713-submit-ce-series-v2-v4-4-ff7edc705b8a@gmail.com> References: <20260713-submit-ce-series-v2-v4-0-ff7edc705b8a@gmail.com> In-Reply-To: <20260713-submit-ce-series-v2-v4-0-ff7edc705b8a@gmail.com> To: Svyatoslav Ryhel , Ion Agorria , u-boot@lists.denx.de, Aspeed BMC SW team , Joel Stanley Cc: Chen-Yu Tsai , Samuel Holland , Tom Rini , Simon Glass , Thierry Reding , Quentin Schulz , Marek Vasut , Rasmus Villemoes , Aristo Chen , Anton Ivanov , Daniel Golle , Francois Berder , Peng Fan , Neil Armstrong , Randolph Sapp , Jonas Karlman , Wolfgang Wallner , Alexey Charkov , Ilias Apalodimas , Heiko Schocher , "Kory Maincent (TI.com)" , Anshul Dalal , Johan Jonker , Francesco Valla , Heinrich Schuchardt , Michael Walle , Andre Przywara , Lukasz Majewski , Richard Genoud , Michael Trimarchi , E Shattow , Enric Balletbo i Serra , Mattijs Korpershoek , Lucas Dietrich , David Lechner , Julien Stephan , Kuan-Wei Chiu , Bastien Curutchet , Raymond Mao , Ryan Chen , Chia-Wei Wang , "Lucien.Jheng" , Mateusz Furdyna , Dinesh Maniyam , Heiko Stuebner , James Hilliard X-Mailer: b4 0.15.2 X-Mailman-Approved-At: Mon, 13 Jul 2026 15:20:59 +0200 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.8 at phobos.denx.de X-Virus-Status: Clean The hash uclass is currently keyed only by CONFIG_DM_HASH, so SPL cannot enable UCLASS_HASH independently. Any SPL code using hash_digest*() has to rely on U-Boot proper also enabling DM_HASH, and the FIT hash path selects the driver-model implementation with a non-phase-aware preprocessor check. Add SPL_DM_HASH, build the hash uclass from CONFIG_$(PHASE_)DM_HASH and use CONFIG_IS_ENABLED(DM_HASH) when selecting the FIT hash implementation. This lets SPL FIT verification use a UCLASS_HASH provider without requiring the U-Boot proper hash uclass. Reviewed-by: Simon Glass Signed-off-by: James Hilliard --- Changes v2 -> v3: - Remove the bare software-hash fallback scope (suggested by Simon Glass) - Document that SPL_DM_HASH needs a hardware provider unless a phase-aware software hash provider is added (suggested by Simon Glass) --- boot/image-fit.c | 50 +++++++++++++++++++++++--------------------- drivers/crypto/hash/Kconfig | 13 ++++++++++++ drivers/crypto/hash/Makefile | 2 +- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/boot/image-fit.c b/boot/image-fit.c index 044a40e1910..555cbf81348 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -32,10 +32,8 @@ extern void *aligned_alloc(size_t alignment, size_t size); #include #include #include -#ifdef CONFIG_DM_HASH #include #include -#endif #define aligned_alloc(a, s) memalign((a), (s)) DECLARE_GLOBAL_DATA_PTR; @@ -1318,43 +1316,47 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp) int calculate_hash(const void *data, int data_len, const char *name, uint8_t *value, int *value_len) { -#if !defined(USE_HOSTCC) && defined(CONFIG_DM_HASH) + struct hash_algo *algo; + int ret; + +#ifndef USE_HOSTCC int rc; enum HASH_ALGO hash_algo; struct udevice *dev; - rc = uclass_get_device(UCLASS_HASH, 0, &dev); - if (rc) { - debug("failed to get hash device, rc=%d\n", rc); - return -1; - } + if (CONFIG_IS_ENABLED(DM_HASH)) { + rc = uclass_get_device(UCLASS_HASH, 0, &dev); + if (rc) { + debug("failed to get hash device, rc=%d\n", rc); + return -1; + } - hash_algo = hash_algo_lookup_by_name(name); - if (hash_algo == HASH_ALGO_INVALID) { - debug("Unsupported hash algorithm\n"); - return -1; - }; + hash_algo = hash_algo_lookup_by_name(name); + if (hash_algo == HASH_ALGO_INVALID) { + debug("Unsupported hash algorithm\n"); + return -1; + } - rc = hash_digest_wd(dev, hash_algo, data, data_len, value, CHUNKSZ); - if (rc) { - debug("failed to get hash value, rc=%d\n", rc); - return -1; - } + rc = hash_digest_wd(dev, hash_algo, data, data_len, value, + CHUNKSZ); + if (rc) { + debug("failed to get hash value, rc=%d\n", rc); + return -1; + } - *value_len = hash_algo_digest_size(hash_algo); -#else - struct hash_algo *algo; - int ret; + *value_len = hash_algo_digest_size(hash_algo); + return 0; + } +#endif ret = hash_lookup_algo(name, &algo); if (ret < 0) { - debug("Unsupported hash alogrithm\n"); + debug("Unsupported hash algorithm\n"); return -1; } algo->hash_func_ws(data, data_len, value, algo->chunk_size); *value_len = algo->digest_size; -#endif return 0; } diff --git a/drivers/crypto/hash/Kconfig b/drivers/crypto/hash/Kconfig index 72b955ac791..272af7bce18 100644 --- a/drivers/crypto/hash/Kconfig +++ b/drivers/crypto/hash/Kconfig @@ -4,6 +4,19 @@ config DM_HASH help If you want to use driver model for Hash, say Y. +config SPL_DM_HASH + bool "Enable Driver Model for Hash in SPL" + depends on SPL_DM + select SPL_CRYPTO + help + Enable the hash uclass in SPL so SPL code can bind and use + UCLASS_HASH providers through the driver model. This is useful for + FIT verification paths that want to calculate image hashes through a + hardware hash accelerator before U-Boot proper is loaded. + HASH_SOFTWARE depends on DM_HASH, so SPL_DM_HASH alone does not + provide a software hash device. Enable a hardware hash provider for + SPL when selecting this option. + config HASH_SOFTWARE bool "Enable driver for Hash in software" depends on DM_HASH diff --git a/drivers/crypto/hash/Makefile b/drivers/crypto/hash/Makefile index 33d88161ed4..9f0d30f9be3 100644 --- a/drivers/crypto/hash/Makefile +++ b/drivers/crypto/hash/Makefile @@ -2,5 +2,5 @@ # # Copyright (c) 2021 ASPEED Technology Inc. -obj-$(CONFIG_DM_HASH) += hash-uclass.o +obj-$(CONFIG_$(PHASE_)DM_HASH) += hash-uclass.o obj-$(CONFIG_HASH_SOFTWARE) += hash_sw.o -- 2.53.0