Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * K2HK: secure kernel command file |
| 3 | * |
| 4 | * (C) Copyright 2012-2014 |
| 5 | * Texas Instruments Incorporated, <www.ti.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <command.h> |
Lokesh Vutla | ae6b222 | 2016-09-16 10:17:12 +0530 | [diff] [blame] | 12 | #include <image.h> |
Tom Rini | 108ee58 | 2016-03-16 09:10:08 -0400 | [diff] [blame] | 13 | #include <mach/mon.h> |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 14 | asm(".arch_extension sec\n\t"); |
| 15 | |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 16 | static int do_mon_install(cmd_tbl_t *cmdtp, int flag, int argc, |
| 17 | char * const argv[]) |
| 18 | { |
Lokesh Vutla | ae6b222 | 2016-09-16 10:17:12 +0530 | [diff] [blame] | 19 | u32 addr, dpsc_base = 0x1E80000, freq, load_addr, size; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 20 | int rcode = 0; |
Lokesh Vutla | ae6b222 | 2016-09-16 10:17:12 +0530 | [diff] [blame] | 21 | struct image_header *header; |
Madan Srinivas | e885610 | 2017-07-17 12:59:15 -0500 | [diff] [blame^] | 22 | u32 ecrypt_bm_addr = 0; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 23 | |
| 24 | if (argc < 2) |
| 25 | return CMD_RET_USAGE; |
| 26 | |
Vitaly Andrianov | 7fd5b64 | 2015-09-19 16:26:41 +0530 | [diff] [blame] | 27 | freq = CONFIG_SYS_HZ_CLOCK; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 28 | |
| 29 | addr = simple_strtoul(argv[1], NULL, 16); |
| 30 | |
Lokesh Vutla | ae6b222 | 2016-09-16 10:17:12 +0530 | [diff] [blame] | 31 | header = (struct image_header *)addr; |
| 32 | |
| 33 | if (image_get_magic(header) != IH_MAGIC) { |
| 34 | printf("## Please update monitor image\n"); |
| 35 | return -EFAULT; |
| 36 | } |
| 37 | |
| 38 | load_addr = image_get_load(header); |
| 39 | size = image_get_data_size(header); |
| 40 | memcpy((void *)load_addr, (void *)(addr + sizeof(struct image_header)), |
| 41 | size); |
| 42 | |
Madan Srinivas | e885610 | 2017-07-17 12:59:15 -0500 | [diff] [blame^] | 43 | if (argc >= 3) |
| 44 | ecrypt_bm_addr = simple_strtoul(argv[2], NULL, 16); |
| 45 | |
| 46 | rcode = mon_install(load_addr, dpsc_base, freq, ecrypt_bm_addr); |
Lokesh Vutla | ae6b222 | 2016-09-16 10:17:12 +0530 | [diff] [blame] | 47 | printf("## installed monitor @ 0x%x, freq [%d], status %d\n", |
| 48 | load_addr, freq, rcode); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Madan Srinivas | e885610 | 2017-07-17 12:59:15 -0500 | [diff] [blame^] | 53 | U_BOOT_CMD(mon_install, 3, 0, do_mon_install, |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 54 | "Install boot kernel at 'addr'", |
| 55 | "" |
| 56 | ); |
| 57 | |
| 58 | static void core_spin(void) |
| 59 | { |
Vitaly Andrianov | aa750ed | 2015-07-08 11:40:14 -0400 | [diff] [blame] | 60 | while (1) { |
| 61 | asm volatile ( |
| 62 | "dsb\n" |
| 63 | "isb\n" |
| 64 | "wfi\n" |
| 65 | ); |
| 66 | } |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 69 | int do_mon_power(cmd_tbl_t *cmdtp, int flag, int argc, |
| 70 | char * const argv[]) |
| 71 | { |
| 72 | int rcode = 0, core_id, on; |
| 73 | void (*fn)(void); |
| 74 | |
| 75 | fn = core_spin; |
| 76 | |
| 77 | if (argc < 3) |
| 78 | return CMD_RET_USAGE; |
| 79 | |
| 80 | core_id = simple_strtoul(argv[1], NULL, 16); |
| 81 | on = simple_strtoul(argv[2], NULL, 16); |
| 82 | |
| 83 | if (on) |
| 84 | rcode = mon_power_on(core_id, fn); |
| 85 | else |
| 86 | rcode = mon_power_off(core_id); |
| 87 | |
| 88 | if (on) { |
| 89 | if (!rcode) |
| 90 | printf("core %d powered on successfully\n", core_id); |
| 91 | else |
| 92 | printf("core %d power on failure\n", core_id); |
| 93 | } else { |
| 94 | printf("core %d powered off successfully\n", core_id); |
| 95 | } |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | U_BOOT_CMD(mon_power, 3, 0, do_mon_power, |
| 101 | "Power On/Off secondary core", |
| 102 | "mon_power <coreid> <oper>\n" |
| 103 | "- coreid (1-3) and oper (1 - ON, 0 - OFF)\n" |
| 104 | "" |
| 105 | ); |