From: James Hilliard <james.hilliard1@gmail.com>
To: Svyatoslav Ryhel <clamor95@gmail.com>,
Ion Agorria <ion@agorria.com>,
u-boot@lists.denx.de, Aspeed BMC SW team <BMC-SW@aspeedtech.com>,
Joel Stanley <joel@jms.id.au>
Cc: Chen-Yu Tsai <wens@kernel.org>,
Samuel Holland <samuel@sholland.org>,
Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
Thierry Reding <treding@nvidia.com>,
Quentin Schulz <quentin.schulz@cherry.de>,
Marek Vasut <marek.vasut+renesas@mailbox.org>,
Rasmus Villemoes <ravi@prevas.dk>,
Aristo Chen <aristo.chen@canonical.com>,
Anton Ivanov <anton@binarly.io>,
Daniel Golle <daniel@makrotopia.org>,
Francois Berder <fberder@outlook.fr>,
Peng Fan <peng.fan@nxp.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Randolph Sapp <rs@ti.com>, Jonas Karlman <jonas@kwiboo.se>,
Wolfgang Wallner <wolfgang.wallner@at.abb.com>,
Alexey Charkov <alchark@gmail.com>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Heiko Schocher <hs@nabladev.com>,
"Kory Maincent (TI.com)" <kory.maincent@bootlin.com>,
Anshul Dalal <anshuld@ti.com>, Johan Jonker <jbx6244@gmail.com>,
Francesco Valla <francesco@valla.it>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Michael Walle <mwalle@kernel.org>,
Andre Przywara <andre.przywara@arm.com>,
Lukasz Majewski <lukma@denx.de>,
Richard Genoud <richard.genoud@bootlin.com>,
Michael Trimarchi <michael@amarulasolutions.com>,
E Shattow <e@freeshell.de>,
Enric Balletbo i Serra <eballetbo@kernel.org>,
Mattijs Korpershoek <mkorpershoek@kernel.org>,
Lucas Dietrich <ld.adecy@gmail.com>,
David Lechner <dlechner@baylibre.com>,
Julien Stephan <jstephan@baylibre.com>,
Kuan-Wei Chiu <visitorckw@gmail.com>,
Bastien Curutchet <bastien.curutchet@bootlin.com>,
Raymond Mao <raymond.mao@riscstar.com>,
Ryan Chen <ryan_chen@aspeedtech.com>,
Chia-Wei Wang <chiawei_wang@aspeedtech.com>,
"Lucien.Jheng" <lucienzx159@gmail.com>,
Mateusz Furdyna <mateusz.furdyna@nokia.com>,
Dinesh Maniyam <dinesh.maniyam@altera.com>,
Heiko Stuebner <heiko@sntech.de>,
James Hilliard <james.hilliard1@gmail.com>
Subject: [PATCH v4 04/14] crypto: hash: allow DM hash in SPL
Date: Mon, 13 Jul 2026 00:43:01 -0600 [thread overview]
Message-ID: <20260713-submit-ce-series-v2-v4-4-ff7edc705b8a@gmail.com> (raw)
In-Reply-To: <20260713-submit-ce-series-v2-v4-0-ff7edc705b8a@gmail.com>
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 <sjg@chromium.org>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
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 <malloc.h>
#include <memalign.h>
#include <asm/global_data.h>
-#ifdef CONFIG_DM_HASH
#include <dm.h>
#include <u-boot/hash.h>
-#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
next prev parent reply other threads:[~2026-07-13 13:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 6:42 [PATCH v4 00/14] crypto: allwinner: enable sun8i-ce FIT crypto James Hilliard
2026-07-13 6:42 ` [PATCH v4 01/14] cmd: aes: fix DM operation handling James Hilliard
2026-07-13 6:42 ` [PATCH v4 02/14] crypto: hash: use DM providers from hash command James Hilliard
2026-07-13 6:43 ` [PATCH v4 03/14] crypto: aes: allow DM AES in SPL James Hilliard
2026-07-13 6:43 ` James Hilliard [this message]
2026-07-13 6:43 ` [PATCH v4 05/14] boot: image: try all DM hash providers James Hilliard
2026-07-13 6:43 ` [PATCH v4 06/14] crypto: aes: fix software key-size handling James Hilliard
2026-07-13 6:43 ` [PATCH v4 07/14] crypto: aes: add software-key provider dispatch James Hilliard
2026-07-13 6:43 ` [PATCH v4 08/14] boot: image: add FIT decrypt-to-buffer helper James Hilliard
2026-07-13 6:43 ` [PATCH v4 09/14] spl: fit: support encrypted payloads James Hilliard
2026-07-13 6:43 ` [PATCH v4 10/14] clk: sunxi: add H6/H616 CE gates and reset James Hilliard
2026-07-13 6:43 ` [PATCH v4 11/14] lib: ecdsa: support additional curve sizes James Hilliard
2026-07-13 6:43 ` [PATCH v4 12/14] crypto: allwinner: add sun8i-ce AES driver James Hilliard
2026-07-13 6:43 ` [PATCH v4 13/14] crypto: allwinner: add sun8i-ce ECDSA verifier James Hilliard
2026-07-13 6:43 ` [PATCH v4 14/14] crypto: allwinner: add sun8i-ce hash driver James Hilliard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260713-submit-ce-series-v2-v4-4-ff7edc705b8a@gmail.com \
--to=james.hilliard1@gmail.com \
--cc=BMC-SW@aspeedtech.com \
--cc=alchark@gmail.com \
--cc=andre.przywara@arm.com \
--cc=anshuld@ti.com \
--cc=anton@binarly.io \
--cc=aristo.chen@canonical.com \
--cc=bastien.curutchet@bootlin.com \
--cc=chiawei_wang@aspeedtech.com \
--cc=clamor95@gmail.com \
--cc=daniel@makrotopia.org \
--cc=dinesh.maniyam@altera.com \
--cc=dlechner@baylibre.com \
--cc=e@freeshell.de \
--cc=eballetbo@kernel.org \
--cc=fberder@outlook.fr \
--cc=francesco@valla.it \
--cc=heiko@sntech.de \
--cc=hs@nabladev.com \
--cc=ilias.apalodimas@linaro.org \
--cc=ion@agorria.com \
--cc=jbx6244@gmail.com \
--cc=joel@jms.id.au \
--cc=jonas@kwiboo.se \
--cc=jstephan@baylibre.com \
--cc=kory.maincent@bootlin.com \
--cc=ld.adecy@gmail.com \
--cc=lucienzx159@gmail.com \
--cc=lukma@denx.de \
--cc=marek.vasut+renesas@mailbox.org \
--cc=mateusz.furdyna@nokia.com \
--cc=michael@amarulasolutions.com \
--cc=mkorpershoek@kernel.org \
--cc=mwalle@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=peng.fan@nxp.com \
--cc=quentin.schulz@cherry.de \
--cc=ravi@prevas.dk \
--cc=raymond.mao@riscstar.com \
--cc=richard.genoud@bootlin.com \
--cc=rs@ti.com \
--cc=ryan_chen@aspeedtech.com \
--cc=samuel@sholland.org \
--cc=sjg@chromium.org \
--cc=treding@nvidia.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=visitorckw@gmail.com \
--cc=wens@kernel.org \
--cc=wolfgang.wallner@at.abb.com \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox