Merge tag 'efi-2022-01-rc2-2' of https://source.denx.de/u-boot/custodians/u-boot-efi
[platform/kernel/u-boot.git] / board / freescale / common / fsl_validate.c
index ed48c5c..34875d0 100644 (file)
@@ -1,17 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2015 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
+ * Copyright 2021 NXP
  */
 
 #include <common.h>
+#include <dm.h>
+#include <flash.h>
 #include <fsl_validate.h>
 #include <fsl_secboot_err.h>
 #include <fsl_sfp.h>
 #include <fsl_sec.h>
 #include <command.h>
+#include <log.h>
 #include <malloc.h>
-#include <dm/uclass.h>
 #include <u-boot/rsa-mod-exp.h>
 #include <hash.h>
 #include <fsl_secboot_err.h>
@@ -499,7 +501,6 @@ static int calc_img_key_hash(struct fsl_secboot_img_priv *img)
        ret = algo->hash_init(algo, &ctx);
        if (ret)
                return ret;
-
        /* Update hash for ESBC key */
 #ifdef CONFIG_KEY_REVOCATION
        if (check_srk(img)) {
@@ -514,12 +515,12 @@ static int calc_img_key_hash(struct fsl_secboot_img_priv *img)
                        img->img_key, img->key_len, 1);
        if (ret)
                return ret;
-
        /* Copy hash at destination buffer */
        ret = algo->hash_finish(algo, ctx, hash_val, algo->digest_size);
-       if (ret)
+       if (ret) {
+               free(ctx);
                return ret;
-
+       }
        for (i = 0; i < SHA256_BYTES; i++)
                img->img_key_hash[i] = hash_val[i];
 
@@ -582,9 +583,10 @@ static int calc_esbchdr_esbc_hash(struct fsl_secboot_img_priv *img)
 #endif
        if (ret)
                return ret;
-       if (!key_hash)
+       if (!key_hash) {
+               free(ctx);
                return ERROR_KEY_TABLE_NOT_FOUND;
-
+       }
        /* Update hash for actual Image */
        ret = algo->hash_update(algo, ctx,
                (u8 *)(*(img->img_addr_ptr)), img->img_size, 1);
@@ -593,9 +595,10 @@ static int calc_esbchdr_esbc_hash(struct fsl_secboot_img_priv *img)
 
        /* Copy hash at destination buffer */
        ret = algo->hash_finish(algo, ctx, hash_val, algo->digest_size);
-       if (ret)
+       if (ret) {
+               free(ctx);
                return ret;
-
+       }
        return 0;
 }
 
@@ -766,7 +769,7 @@ static inline int str2longbe(const char *p, ulong *num)
        if (!p) {
                return 0;
        } else {
-               tmp = simple_strtoul(p, &endptr, 16);
+               tmp = hextoul(p, &endptr);
                if (sizeof(ulong) == 4)
                        *num = cpu_to_be32(tmp);
                else