FIT hash calculation currently selects UCLASS_HASH device zero directly,
so a provider which does not implement the requested algorithm prevents a
later capable provider from being used. It also turns every provider error
into the same generic FIT hash failure.

Use the common hash provider-selection helper. Fall back to the configured
software implementation only when no DM provider supports the algorithm,
and preserve probe and digest failures from providers which accept it.

Signed-off-by: James Hilliard <[email protected]>
---
Changes v3 -> v4:
  - New patch
---
 boot/image-fit.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/boot/image-fit.c b/boot/image-fit.c
index 555cbf81348..9af38ed8d82 100644
--- a/boot/image-fit.c
+++ b/boot/image-fit.c
@@ -1322,30 +1322,22 @@ int calculate_hash(const void *data, int data_len, 
const char *name,
 #ifndef USE_HOSTCC
        int rc;
        enum HASH_ALGO hash_algo;
-       struct udevice *dev;
 
        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;
+               if (hash_algo != HASH_ALGO_INVALID)
+                       rc = hash_digest_wd_lookup(hash_algo, data, data_len,
+                                                  value, CHUNKSZ);
+               else
+                       rc = -EOPNOTSUPP;
+               if (!rc) {
+                       *value_len = hash_algo_digest_size(hash_algo);
+                       return 0;
                }
-
-               rc = hash_digest_wd(dev, hash_algo, data, data_len, value,
-                                   CHUNKSZ);
-               if (rc) {
+               if (rc != -ENODEV && rc != -EOPNOTSUPP) {
                        debug("failed to get hash value, rc=%d\n", rc);
                        return -1;
                }
-
-               *value_len = hash_algo_digest_size(hash_algo);
-               return 0;
        }
 #endif
 

-- 
2.53.0

Reply via email to