Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
gaurav rana | c3a5042 | 2015-02-27 09:45:35 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2015 Freescale Semiconductor, Inc. |
gaurav rana | c3a5042 | 2015-02-27 09:45:35 +0530 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <command.h> |
| 8 | #include <fsl_validate.h> |
| 9 | |
Saksham Jain | 7f048b3 | 2016-03-23 16:24:44 +0530 | [diff] [blame] | 10 | int do_esbc_halt(cmd_tbl_t *cmdtp, int flag, int argc, |
gaurav rana | f79323c | 2015-03-10 14:08:50 +0530 | [diff] [blame] | 11 | char * const argv[]) |
| 12 | { |
Aneesh Bansal | 8a47d5c | 2016-01-22 16:37:28 +0530 | [diff] [blame] | 13 | if (fsl_check_boot_mode_secure() == 0) { |
| 14 | printf("Boot Mode is Non-Secure. Not entering spin loop.\n"); |
| 15 | return 0; |
| 16 | } |
| 17 | |
gaurav rana | f79323c | 2015-03-10 14:08:50 +0530 | [diff] [blame] | 18 | printf("Core is entering spin loop.\n"); |
| 19 | loop: |
| 20 | goto loop; |
| 21 | |
| 22 | return 0; |
| 23 | } |
| 24 | |
Tom Rini | d5a7385 | 2018-01-03 08:57:50 -0500 | [diff] [blame] | 25 | #ifndef CONFIG_SPL_BUILD |
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; |
Saksham Jain | 04fcf52 | 2016-03-23 16:24:45 +0530 | [diff] [blame] | 32 | uintptr_t img_addr = 0; |
| 33 | char buf[20]; |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 34 | |
gaurav rana | c3a5042 | 2015-02-27 09:45:35 +0530 | [diff] [blame] | 35 | if (argc < 2) |
| 36 | return cmd_usage(cmdtp); |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 37 | else if (argc > 2) |
| 38 | /* Second arg - Optional - Hash Str*/ |
| 39 | hash_str = argv[2]; |
| 40 | |
| 41 | /* First argument - header address -32/64bit */ |
Aneesh Bansal | 85921ba | 2015-12-08 14:14:15 +0530 | [diff] [blame] | 42 | haddr = (uintptr_t)simple_strtoul(argv[1], NULL, 16); |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 43 | |
Aneesh Bansal | 85921ba | 2015-12-08 14:14:15 +0530 | [diff] [blame] | 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 | */ |
Saksham Jain | 04fcf52 | 2016-03-23 16:24:45 +0530 | [diff] [blame] | 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); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 55 | env_set("img_addr", buf); |
Saksham Jain | 04fcf52 | 2016-03-23 16:24:45 +0530 | [diff] [blame] | 56 | |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 57 | if (ret) |
| 58 | return 1; |
gaurav rana | c3a5042 | 2015-02-27 09:45:35 +0530 | [diff] [blame] | 59 | |
Aneesh Bansal | 2b379bf | 2015-12-08 14:14:12 +0530 | [diff] [blame] | 60 | printf("esbc_validate command successful\n"); |
| 61 | return 0; |
gaurav rana | c3a5042 | 2015-02-27 09:45:35 +0530 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /***************************************************/ |
| 65 | static 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 | |
| 74 | U_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 | ); |
gaurav rana | f79323c | 2015-03-10 14:08:50 +0530 | [diff] [blame] | 79 | |
| 80 | U_BOOT_CMD( |
| 81 | esbc_halt, 1, 0, do_esbc_halt, |
Aneesh Bansal | 8a47d5c | 2016-01-22 16:37:28 +0530 | [diff] [blame] | 82 | "Put the core in spin loop (Secure Boot Only)", |
gaurav rana | f79323c | 2015-03-10 14:08:50 +0530 | [diff] [blame] | 83 | "" |
| 84 | ); |
Tom Rini | d5a7385 | 2018-01-03 08:57:50 -0500 | [diff] [blame] | 85 | #endif |