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