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; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 22 | |
| 23 | if (argc < 2) |
| 24 | return CMD_RET_USAGE; |
| 25 | |
Vitaly Andrianov | 7fd5b64 | 2015-09-19 16:26:41 +0530 | [diff] [blame] | 26 | freq = CONFIG_SYS_HZ_CLOCK; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 27 | |
| 28 | addr = simple_strtoul(argv[1], NULL, 16); |
| 29 | |
Lokesh Vutla | ae6b222 | 2016-09-16 10:17:12 +0530 | [diff] [blame] | 30 | header = (struct image_header *)addr; |
| 31 | |
| 32 | if (image_get_magic(header) != IH_MAGIC) { |
| 33 | printf("## Please update monitor image\n"); |
| 34 | return -EFAULT; |
| 35 | } |
| 36 | |
| 37 | load_addr = image_get_load(header); |
| 38 | size = image_get_data_size(header); |
| 39 | memcpy((void *)load_addr, (void *)(addr + sizeof(struct image_header)), |
| 40 | size); |
| 41 | |
| 42 | rcode = mon_install(load_addr, dpsc_base, freq); |
| 43 | printf("## installed monitor @ 0x%x, freq [%d], status %d\n", |
| 44 | load_addr, freq, rcode); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | U_BOOT_CMD(mon_install, 2, 0, do_mon_install, |
| 50 | "Install boot kernel at 'addr'", |
| 51 | "" |
| 52 | ); |
| 53 | |
| 54 | static void core_spin(void) |
| 55 | { |
Vitaly Andrianov | aa750ed | 2015-07-08 11:40:14 -0400 | [diff] [blame] | 56 | while (1) { |
| 57 | asm volatile ( |
| 58 | "dsb\n" |
| 59 | "isb\n" |
| 60 | "wfi\n" |
| 61 | ); |
| 62 | } |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 63 | } |
| 64 | |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 65 | int do_mon_power(cmd_tbl_t *cmdtp, int flag, int argc, |
| 66 | char * const argv[]) |
| 67 | { |
| 68 | int rcode = 0, core_id, on; |
| 69 | void (*fn)(void); |
| 70 | |
| 71 | fn = core_spin; |
| 72 | |
| 73 | if (argc < 3) |
| 74 | return CMD_RET_USAGE; |
| 75 | |
| 76 | core_id = simple_strtoul(argv[1], NULL, 16); |
| 77 | on = simple_strtoul(argv[2], NULL, 16); |
| 78 | |
| 79 | if (on) |
| 80 | rcode = mon_power_on(core_id, fn); |
| 81 | else |
| 82 | rcode = mon_power_off(core_id); |
| 83 | |
| 84 | if (on) { |
| 85 | if (!rcode) |
| 86 | printf("core %d powered on successfully\n", core_id); |
| 87 | else |
| 88 | printf("core %d power on failure\n", core_id); |
| 89 | } else { |
| 90 | printf("core %d powered off successfully\n", core_id); |
| 91 | } |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | U_BOOT_CMD(mon_power, 3, 0, do_mon_power, |
| 97 | "Power On/Off secondary core", |
| 98 | "mon_power <coreid> <oper>\n" |
| 99 | "- coreid (1-3) and oper (1 - ON, 0 - OFF)\n" |
| 100 | "" |
| 101 | ); |