blob: c6e7e2c3097d787c62d7cc97119c498ec7face2b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04002/*
3 * K2HK: secure kernel command file
4 *
5 * (C) Copyright 2012-2014
6 * Texas Instruments Incorporated, <www.ti.com>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04007 */
8
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04009#include <command.h>
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053010#include <image.h>
Tom Rini108ee582016-03-16 09:10:08 -040011#include <mach/mon.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040012asm(".arch_extension sec\n\t");
13
Simon Glassed38aef2020-05-10 11:40:03 -060014static int do_mon_install(struct cmd_tbl *cmdtp, int flag, int argc,
15 char *const argv[])
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040016{
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053017 u32 addr, dpsc_base = 0x1E80000, freq, load_addr, size;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040018 int rcode = 0;
Simon Glassbb7d3bb2022-09-06 20:26:52 -060019 struct legacy_img_hdr *header;
Madan Srinivase8856102017-07-17 12:59:15 -050020 u32 ecrypt_bm_addr = 0;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040021
22 if (argc < 2)
23 return CMD_RET_USAGE;
24
Tom Rini6a5dccc2022-11-16 13:10:41 -050025 freq = CFG_SYS_HZ_CLOCK;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040026
Simon Glass3ff49ec2021-07-24 09:03:29 -060027 addr = hextoul(argv[1], NULL);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040028
Simon Glassbb7d3bb2022-09-06 20:26:52 -060029 header = (struct legacy_img_hdr *)addr;
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053030
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 Glassbb7d3bb2022-09-06 20:26:52 -060038 memcpy((void *)load_addr, (void *)(addr + sizeof(struct legacy_img_hdr)),
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053039 size);
40
Madan Srinivase8856102017-07-17 12:59:15 -050041 if (argc >= 3)
Simon Glass3ff49ec2021-07-24 09:03:29 -060042 ecrypt_bm_addr = hextoul(argv[2], NULL);
Madan Srinivase8856102017-07-17 12:59:15 -050043
44 rcode = mon_install(load_addr, dpsc_base, freq, ecrypt_bm_addr);
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053045 printf("## installed monitor @ 0x%x, freq [%d], status %d\n",
46 load_addr, freq, rcode);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040047
48 return 0;
49}
50
Madan Srinivase8856102017-07-17 12:59:15 -050051U_BOOT_CMD(mon_install, 3, 0, do_mon_install,
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040052 "Install boot kernel at 'addr'",
53 ""
54);
55
56static void core_spin(void)
57{
Vitaly Andrianovaa750ed2015-07-08 11:40:14 -040058 while (1) {
59 asm volatile (
60 "dsb\n"
61 "isb\n"
62 "wfi\n"
63 );
64 }
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040065}
66
Simon Glassed38aef2020-05-10 11:40:03 -060067int do_mon_power(struct cmd_tbl *cmdtp, int flag, int argc,
68 char *const argv[])
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040069{
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 Glass3ff49ec2021-07-24 09:03:29 -060078 core_id = hextoul(argv[1], NULL);
79 on = hextoul(argv[2], NULL);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040080
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
98U_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);