]> git.ipfire.org Git - people/ms/u-boot.git/blame - board/freescale/common/cmd_esbc_validate.c
Merge git://git.denx.de/u-boot-tegra
[people/ms/u-boot.git] / board / freescale / common / cmd_esbc_validate.c
CommitLineData
47151e4b 1/*
2 * Copyright 2015 Freescale Semiconductor, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <command.h>
9#include <fsl_validate.h>
10
c4666cf6 11int do_esbc_halt(cmd_tbl_t *cmdtp, int flag, int argc,
98cb0efd 12 char * const argv[])
13{
856b2846
AB
14 if (fsl_check_boot_mode_secure() == 0) {
15 printf("Boot Mode is Non-Secure. Not entering spin loop.\n");
16 return 0;
17 }
18
98cb0efd 19 printf("Core is entering spin loop.\n");
20loop:
21 goto loop;
22
23 return 0;
24}
25
47151e4b 26static int do_esbc_validate(cmd_tbl_t *cmdtp, int flag, int argc,
27 char * const argv[])
28{
bc71f926 29 char *hash_str = NULL;
b055a0fd 30 uintptr_t haddr;
bc71f926 31 int ret;
85bb3896
SJ
32 uintptr_t img_addr = 0;
33 char buf[20];
bc71f926 34
47151e4b 35 if (argc < 2)
36 return cmd_usage(cmdtp);
bc71f926
AB
37 else if (argc > 2)
38 /* Second arg - Optional - Hash Str*/
39 hash_str = argv[2];
40
41 /* First argument - header address -32/64bit */
b055a0fd 42 haddr = (uintptr_t)simple_strtoul(argv[1], NULL, 16);
47151e4b 43
b055a0fd
AB
44 /* With esbc_validate command, Image address must be
45 * part of header. So, the function is called
46 * by passing this argument as 0.
47 */
85bb3896
SJ
48 ret = fsl_secboot_validate(haddr, hash_str, &img_addr);
49
50 /* Need to set "img_addr" even if validation failure.
51 * Required when SB_EN in RCW set and non-fatal error
52 * to continue U-Boot
53 */
54 sprintf(buf, "%lx", img_addr);
382bee57 55 env_set("img_addr", buf);
85bb3896 56
bc71f926
AB
57 if (ret)
58 return 1;
59
60 printf("esbc_validate command successful\n");
61 return 0;
47151e4b 62}
63
64/***************************************************/
65static char esbc_validate_help_text[] =
66 "esbc_validate hdr_addr <hash_val> - Validates signature using\n"
67 " RSA verification\n"
68 " $hdr_addr Address of header of the image\n"
69 " to be validated.\n"
70 " $hash_val -Optional\n"
71 " It provides Hash of public/srk key to be\n"
72 " used to verify signature.\n";
73
74U_BOOT_CMD(
75 esbc_validate, 3, 0, do_esbc_validate,
76 "Validates signature on a given image using RSA verification",
77 esbc_validate_help_text
78);
98cb0efd 79
80U_BOOT_CMD(
81 esbc_halt, 1, 0, do_esbc_halt,
856b2846 82 "Put the core in spin loop (Secure Boot Only)",
98cb0efd 83 ""
84);