secure_boot: enable chain of trust for ARM platforms
[oweals/u-boot.git] / board / freescale / common / cmd_esbc_validate.c
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
11 static int do_esbc_halt(cmd_tbl_t *cmdtp, int flag, int argc,
12                                 char * const argv[])
13 {
14         printf("Core is entering spin loop.\n");
15 loop:
16         goto loop;
17
18         return 0;
19 }
20
21 static int do_esbc_validate(cmd_tbl_t *cmdtp, int flag, int argc,
22                                 char * const argv[])
23 {
24         char *hash_str = NULL;
25         uintptr_t haddr;
26         int ret;
27
28         if (argc < 2)
29                 return cmd_usage(cmdtp);
30         else if (argc > 2)
31                 /* Second arg - Optional - Hash Str*/
32                 hash_str = argv[2];
33
34         /* First argument - header address -32/64bit */
35         haddr = (uintptr_t)simple_strtoul(argv[1], NULL, 16);
36
37         /* With esbc_validate command, Image address must be
38          * part of header. So, the function is called
39          * by passing this argument as 0.
40          */
41         ret = fsl_secboot_validate(haddr, hash_str, 0);
42         if (ret)
43                 return 1;
44
45         printf("esbc_validate command successful\n");
46         return 0;
47 }
48
49 /***************************************************/
50 static char esbc_validate_help_text[] =
51         "esbc_validate hdr_addr <hash_val> - Validates signature using\n"
52         "                          RSA verification\n"
53         "                          $hdr_addr Address of header of the image\n"
54         "                          to be validated.\n"
55         "                          $hash_val -Optional\n"
56         "                          It provides Hash of public/srk key to be\n"
57         "                          used to verify signature.\n";
58
59 U_BOOT_CMD(
60         esbc_validate,  3,      0,      do_esbc_validate,
61         "Validates signature on a given image using RSA verification",
62         esbc_validate_help_text
63 );
64
65 U_BOOT_CMD(
66         esbc_halt,      1,      0,      do_esbc_halt,
67         "Put the core in spin loop ",
68         ""
69 );