Vitaly Andrianov | ef509b9 | 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> |
Tom Rini | aadd336 | 2016-03-16 09:10:08 -0400 | [diff] [blame] | 12 | #include <mach/mon.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 13 | asm(".arch_extension sec\n\t"); |
| 14 | |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 15 | static int do_mon_install(cmd_tbl_t *cmdtp, int flag, int argc, |
| 16 | char * const argv[]) |
| 17 | { |
| 18 | u32 addr, dpsc_base = 0x1E80000, freq; |
| 19 | int rcode = 0; |
| 20 | |
| 21 | if (argc < 2) |
| 22 | return CMD_RET_USAGE; |
| 23 | |
Vitaly Andrianov | e6d71e1 | 2015-09-19 16:26:41 +0530 | [diff] [blame] | 24 | freq = CONFIG_SYS_HZ_CLOCK; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 25 | |
| 26 | addr = simple_strtoul(argv[1], NULL, 16); |
| 27 | |
| 28 | rcode = mon_install(addr, dpsc_base, freq); |
| 29 | printf("## installed monitor, freq [%d], status %d\n", |
| 30 | freq, rcode); |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | U_BOOT_CMD(mon_install, 2, 0, do_mon_install, |
| 36 | "Install boot kernel at 'addr'", |
| 37 | "" |
| 38 | ); |
| 39 | |
| 40 | static void core_spin(void) |
| 41 | { |
Vitaly Andrianov | 17c5bda | 2015-07-08 11:40:14 -0400 | [diff] [blame] | 42 | while (1) { |
| 43 | asm volatile ( |
| 44 | "dsb\n" |
| 45 | "isb\n" |
| 46 | "wfi\n" |
| 47 | ); |
| 48 | } |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 51 | int do_mon_power(cmd_tbl_t *cmdtp, int flag, int argc, |
| 52 | char * const argv[]) |
| 53 | { |
| 54 | int rcode = 0, core_id, on; |
| 55 | void (*fn)(void); |
| 56 | |
| 57 | fn = core_spin; |
| 58 | |
| 59 | if (argc < 3) |
| 60 | return CMD_RET_USAGE; |
| 61 | |
| 62 | core_id = simple_strtoul(argv[1], NULL, 16); |
| 63 | on = simple_strtoul(argv[2], NULL, 16); |
| 64 | |
| 65 | if (on) |
| 66 | rcode = mon_power_on(core_id, fn); |
| 67 | else |
| 68 | rcode = mon_power_off(core_id); |
| 69 | |
| 70 | if (on) { |
| 71 | if (!rcode) |
| 72 | printf("core %d powered on successfully\n", core_id); |
| 73 | else |
| 74 | printf("core %d power on failure\n", core_id); |
| 75 | } else { |
| 76 | printf("core %d powered off successfully\n", core_id); |
| 77 | } |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | U_BOOT_CMD(mon_power, 3, 0, do_mon_power, |
| 83 | "Power On/Off secondary core", |
| 84 | "mon_power <coreid> <oper>\n" |
| 85 | "- coreid (1-3) and oper (1 - ON, 0 - OFF)\n" |
| 86 | "" |
| 87 | ); |