SECURE BOOT: change prototype of fsl_secboot_validate function

The prototype and defination of function fsl_secboot_validate
has been changed to support calling this function from another
function within u-boot.
Only two aruments needed:
1) header address - Mandatory
2) SHA256 string - optional

Signed-off-by: Saksham Jain <saksham@freescale.com>
Signed-off-by: Aneesh Bansal <aneesh.bansal@freescale.com>
Acked-by: Ruchika Gupta <ruchika.gupta@nxp.com>
Reviewed-by: York Sun <york.sun@nxp.com>
This commit is contained in:
Aneesh Bansal 2015-12-08 14:14:12 +05:30 committed by York Sun
parent 81dfdee0dc
commit bc71f926e3
3 changed files with 25 additions and 15 deletions

View file

@ -21,10 +21,25 @@ loop:
static int do_esbc_validate(cmd_tbl_t *cmdtp, int flag, int argc, static int do_esbc_validate(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[]) char * const argv[])
{ {
char *hash_str = NULL;
ulong haddr;
int ret;
if (argc < 2) if (argc < 2)
return cmd_usage(cmdtp); return cmd_usage(cmdtp);
else if (argc > 2)
/* Second arg - Optional - Hash Str*/
hash_str = argv[2];
return fsl_secboot_validate(cmdtp, flag, argc, argv); /* First argument - header address -32/64bit */
haddr = simple_strtoul(argv[1], NULL, 16);
ret = fsl_secboot_validate(haddr, hash_str);
if (ret)
return 1;
printf("esbc_validate command successful\n");
return 0;
} }
/***************************************************/ /***************************************************/

View file

@ -699,13 +699,11 @@ static inline int str2longbe(const char *p, ulong *num)
return *p != '\0' && *endptr == '\0'; return *p != '\0' && *endptr == '\0';
} }
int fsl_secboot_validate(cmd_tbl_t *cmdtp, int flag, int argc, int fsl_secboot_validate(ulong haddr, char *arg_hash_str)
char * const argv[])
{ {
struct ccsr_sfp_regs *sfp_regs = (void *)(CONFIG_SYS_SFP_ADDR); struct ccsr_sfp_regs *sfp_regs = (void *)(CONFIG_SYS_SFP_ADDR);
ulong hash[SHA256_BYTES/sizeof(ulong)]; ulong hash[SHA256_BYTES/sizeof(ulong)];
char hash_str[NUM_HEX_CHARS + 1]; char hash_str[NUM_HEX_CHARS + 1];
ulong addr = simple_strtoul(argv[1], NULL, 16);
struct fsl_secboot_img_priv *img; struct fsl_secboot_img_priv *img;
struct fsl_secboot_img_hdr *hdr; struct fsl_secboot_img_hdr *hdr;
void *esbc; void *esbc;
@ -717,8 +715,8 @@ int fsl_secboot_validate(cmd_tbl_t *cmdtp, int flag, int argc,
struct udevice *mod_exp_dev; struct udevice *mod_exp_dev;
#endif #endif
if (argc == 3) { if (arg_hash_str != NULL) {
char *cp = argv[2]; const char *cp = arg_hash_str;
int i = 0; int i = 0;
if (*cp == '0' && *(cp + 1) == 'x') if (*cp == '0' && *(cp + 1) == 'x')
@ -731,7 +729,7 @@ int fsl_secboot_validate(cmd_tbl_t *cmdtp, int flag, int argc,
*/ */
if (strlen(cp) != SHA256_NIBBLES) { if (strlen(cp) != SHA256_NIBBLES) {
printf("%s is not a 256 bits hex string as expected\n", printf("%s is not a 256 bits hex string as expected\n",
argv[2]); arg_hash_str);
return -1; return -1;
} }
@ -741,7 +739,7 @@ int fsl_secboot_validate(cmd_tbl_t *cmdtp, int flag, int argc,
hash_str[NUM_HEX_CHARS] = '\0'; hash_str[NUM_HEX_CHARS] = '\0';
if (!str2longbe(hash_str, &hash[i])) { if (!str2longbe(hash_str, &hash[i])) {
printf("%s is not a 256 bits hex string ", printf("%s is not a 256 bits hex string ",
argv[2]); arg_hash_str);
return -1; return -1;
} }
} }
@ -757,7 +755,7 @@ int fsl_secboot_validate(cmd_tbl_t *cmdtp, int flag, int argc,
memset(img, 0, sizeof(struct fsl_secboot_img_priv)); memset(img, 0, sizeof(struct fsl_secboot_img_priv));
hdr = &img->hdr; hdr = &img->hdr;
img->ehdrloc = addr; img->ehdrloc = haddr;
esbc = (u8 *)(uintptr_t)img->ehdrloc; esbc = (u8 *)(uintptr_t)img->ehdrloc;
memcpy(hdr, esbc, sizeof(struct fsl_secboot_img_hdr)); memcpy(hdr, esbc, sizeof(struct fsl_secboot_img_hdr));
@ -843,8 +841,6 @@ int fsl_secboot_validate(cmd_tbl_t *cmdtp, int flag, int argc,
goto exit; goto exit;
} }
printf("esbc_validate command successful\n");
exit: exit:
return 0; return ret;
} }

View file

@ -193,11 +193,10 @@ struct fsl_secboot_img_priv {
*/ */
struct fsl_secboot_sg_table sgtbl[MAX_SG_ENTRIES]; /* SG table */ struct fsl_secboot_sg_table sgtbl[MAX_SG_ENTRIES]; /* SG table */
u32 ehdrloc; /* ESBC client location */ ulong ehdrloc; /* ESBC client location */
}; };
int fsl_secboot_validate(cmd_tbl_t *cmdtp, int flag, int argc, int fsl_secboot_validate(ulong haddr, char *arg_hash_str);
char * const argv[]);
int fsl_secboot_blob_encap(cmd_tbl_t *cmdtp, int flag, int argc, int fsl_secboot_blob_encap(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[]); char * const argv[]);
int fsl_secboot_blob_decap(cmd_tbl_t *cmdtp, int flag, int argc, int fsl_secboot_blob_decap(cmd_tbl_t *cmdtp, int flag, int argc,