[PATCH v2 09/10] crypto: hash: allow DM hash in SPL

Simon Glass sjg at chromium.org
Thu Jul 9 20:37:35 CEST 2026


Hi James,

On 2026-07-03T01:49:45, James Hilliard <james.hilliard1 at gmail.com> wrote:
> crypto: hash: allow DM hash in SPL
>
> 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.
>
> Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
>
> boot/image-fit.c             | 62 +++++++++++++++++++++++---------------------
>  drivers/crypto/hash/Kconfig  | 10 +++++++
>  drivers/crypto/hash/Makefile |  2 +-
>  3 files changed, 44 insertions(+), 30 deletions(-)

> diff --git a/boot/image-fit.c b/boot/image-fit.c
> @@ -1321,43 +1319,49 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp)
> +     {
> +             struct hash_algo *algo;
> +             int ret;
>
> -     ret = hash_lookup_algo(name, &algo);
> -     if (ret < 0) {
> -             debug("Unsupported hash alogrithm\n");
> -             return -1;
> +             ret = hash_lookup_algo(name, &algo);
> +             if (ret < 0) {
> +                     debug("Unsupported hash algorithm\n");
> +                     return -1;
> +             }
>
> -     algo->hash_func_ws(data, data_len, value, algo->chunk_size);
> -     *value_len = algo->digest_size;
> -#endif
> +             algo->hash_func_ws(data, data_len, value, algo->chunk_size);
> +             *value_len = algo->digest_size;
> +     }

The bare '{ ... }' scope reads oddly. Since the DM branch always
returns, please move the declarations up with the others (or use an
else after the DM if) and lose the extra indent level.

> diff --git a/drivers/crypto/hash/Kconfig b/drivers/crypto/hash/Kconfig
> @@ -4,6 +4,16 @@ config DM_HASH
> +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 still depends on DM_HASH (not the phase-keyed form), so
enabling SPL_DM_HASH alone gives SPL a hash uclass with no software
provider - only hardware drivers such as the sun8i-ce hash child in
patch 10 will work. Please say so in the help text, so users don't try
SPL_DM_HASH without a hardware provider and wonder why hash_digest()
has no device.

Regards,
Simon


More information about the U-Boot mailing list