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