global: Migrate CONFIG_SYS_FSL* symbols to the CFG_SYS namespace
[platform/kernel/u-boot.git] / board / freescale / common / fsl_validate.c
index ed48c5c..3424d49 100644 (file)
@@ -1,23 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2015 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
+ * Copyright 2021-2022 NXP
  */
 
 #include <common.h>
+#include <dm.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>
 #ifdef CONFIG_ARCH_LS1021A
 #include <asm/arch/immap_ls102xa.h>
 #endif
+#include <dm/lists.h>
 
 #define SHA256_BITS    256
 #define SHA256_BYTES   (256/8)
@@ -77,9 +79,11 @@ static u32 check_ie(struct fsl_secboot_img_priv *img)
  * address
  */
 #if defined(CONFIG_MPC85xx)
+#include <flash.h>
+
 int get_csf_base_addr(u32 *csf_addr, u32 *flash_base_addr)
 {
-       struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+       struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
        u32 csf_hdr_addr = in_be32(&gur->scratchrw[0]);
        u32 csf_flash_offset = csf_hdr_addr & ~(CONFIG_SYS_PBI_FLASH_BASE);
        u32 flash_addr, addr;
@@ -110,7 +114,7 @@ int get_csf_base_addr(u32 *csf_addr, u32 *flash_base_addr)
  */
 int get_csf_base_addr(u32 *csf_addr, u32 *flash_base_addr)
 {
-       struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
+       struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR);
        u32 csf_hdr_addr = in_be32(&gur->scratchrw[0]);
 
        if (memcmp((u8 *)(uintptr_t)csf_hdr_addr,
@@ -126,7 +130,7 @@ int get_csf_base_addr(u32 *csf_addr, u32 *flash_base_addr)
 #if defined(CONFIG_ESBC_HDR_LS)
 static int get_ie_info_addr(uintptr_t *ie_addr)
 {
-       struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
+       struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR);
        /* For LS-CH3, the address of IE Table is
         * stated in Scratch13 and scratch14 of DCFG.
         * Bootrom validates this table while validating uboot.
@@ -499,7 +503,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 +517,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 +585,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 +597,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 +771,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
@@ -803,6 +808,13 @@ static int calculate_cmp_img_sig(struct fsl_secboot_img_priv *img)
        prop.num_bits = key_len * 8;
        prop.exp_len = key_len;
 
+#if defined(CONFIG_SPL_BUILD)
+       ret = device_bind_driver(NULL, "fsl_rsa_mod_exp", "fsl_rsa_mod_exp", NULL);
+       if (ret) {
+               printf("Couldn't bind fsl_rsa_mod_exp driver (%d)\n", ret);
+               return -EINVAL;
+       }
+#endif
        ret = uclass_get_device(UCLASS_MOD_EXP, 0, &mod_exp_dev);
        if (ret) {
                printf("RSA: Can't find Modular Exp implementation\n");
@@ -868,7 +880,7 @@ int fsl_secboot_validate(uintptr_t haddr, char *arg_hash_str,
        int ret, i, hash_cmd = 0;
        u32 srk_hash[8];
 
-       if (arg_hash_str != NULL) {
+       if (strlen(arg_hash_str) != 0) {
                const char *cp = arg_hash_str;
                int i = 0;