gaurav rana | c3a5042 | 2015-02-27 09:45:35 +0530 | [diff] [blame] | 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 | |
gaurav rana | f79323c | 2015-03-10 14:08:50 +0530 | [diff] [blame] | 11 | static int do_esbc_halt(cmd_tbl_t *cmdtp, int flag, int argc, |
| 12 | char * const argv[]) |
| 13 | { |
Aneesh Bansal | 8a47d5c | 2016-01-22 16:37:28 +0530 | [diff] [blame] | 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 | |
gaurav rana | f79323c | 2015-03-10 14:08:50 +0530 | [diff] [blame] | 19 | printf("Core is entering spin loop.\n"); |
| 20 | loop: |
| 21 | goto loop; |
| 22 | |
| 23 | return 0; |
| 24 | } |
| 25 | |
gaurav rana | c3a5042 | 2015-02-27 09:45:35 +0530 | [diff] [blame] | 26 | static int do_esbc_validate(cmd_tbl_t *cmdtp, int flag, int argc, |
| 27 | char * const argv[]) |
| 28 | { |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 29 | char *hash_str = NULL; |
Aneesh Bansal | 85921ba | 2015-12-08 14:14:15 +0530 | [diff] [blame] | 30 | uintptr_t haddr; |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 31 | int ret; |
| 32 | |
gaurav rana | c3a5042 | 2015-02-27 09:45:35 +0530 | [diff] [blame] | 33 | if (argc < 2) |
| 34 | return cmd_usage(cmdtp); |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 35 | else if (argc > 2) |
| 36 | /* Second arg - Optional - Hash Str*/ |
| 37 | hash_str = argv[2]; |
| 38 | |
| 39 | /* First argument - header address -32/64bit */ |
Aneesh Bansal | 85921ba | 2015-12-08 14:14:15 +0530 | [diff] [blame] | 40 | haddr = (uintptr_t)simple_strtoul(argv[1], NULL, 16); |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 41 | |
Aneesh Bansal | 85921ba | 2015-12-08 14:14:15 +0530 | [diff] [blame] | 42 | /* With esbc_validate command, Image address must be |
| 43 | * part of header. So, the function is called |
| 44 | * by passing this argument as 0. |
| 45 | */ |
| 46 | ret = fsl_secboot_validate(haddr, hash_str, 0); |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 47 | if (ret) |
| 48 | return 1; |
gaurav rana | c3a5042 | 2015-02-27 09:45:35 +0530 | [diff] [blame] | 49 | |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 50 | printf("esbc_validate command successful\n"); |
| 51 | return 0; |
gaurav rana | c3a5042 | 2015-02-27 09:45:35 +0530 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /***************************************************/ |
| 55 | static char esbc_validate_help_text[] = |
| 56 | "esbc_validate hdr_addr <hash_val> - Validates signature using\n" |
| 57 | " RSA verification\n" |
| 58 | " $hdr_addr Address of header of the image\n" |
| 59 | " to be validated.\n" |
| 60 | " $hash_val -Optional\n" |
| 61 | " It provides Hash of public/srk key to be\n" |
| 62 | " used to verify signature.\n"; |
| 63 | |
| 64 | U_BOOT_CMD( |
| 65 | esbc_validate, 3, 0, do_esbc_validate, |
| 66 | "Validates signature on a given image using RSA verification", |
| 67 | esbc_validate_help_text |
| 68 | ); |
gaurav rana | f79323c | 2015-03-10 14:08:50 +0530 | [diff] [blame] | 69 | |
| 70 | U_BOOT_CMD( |
| 71 | esbc_halt, 1, 0, do_esbc_halt, |
Aneesh Bansal | 8a47d5c | 2016-01-22 16:37:28 +0530 | [diff] [blame] | 72 | "Put the core in spin loop (Secure Boot Only)", |
gaurav rana | f79323c | 2015-03-10 14:08:50 +0530 | [diff] [blame] | 73 | "" |
| 74 | ); |