blob: 4734e4c7143ba56ba7a4e85bef03ce037702893f [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
9#include <common.h>
10#include <command.h>
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053011#include <image.h>
Tom Rini108ee582016-03-16 09:10:08 -040012#include <mach/mon.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040013asm(".arch_extension sec\n\t");
14
Simon Glassed38aef2020-05-10 11:40:03 -060015static int do_mon_install(struct cmd_tbl *cmdtp, int flag, int argc,
16 char *const argv[])
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040017{
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053018 u32 addr, dpsc_base = 0x1E80000, freq, load_addr, size;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040019 int rcode = 0;
Simon Glassbb7d3bb2022-09-06 20:26:52 -060020 struct legacy_img_hdr *header;
Madan Srinivase8856102017-07-17 12:59:15 -050021 u32 ecrypt_bm_addr = 0;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040022
23 if (argc < 2)
24 return CMD_RET_USAGE;
25
Vitaly Andrianov7fd5b642015-09-19 16:26:41 +053026 freq = CONFIG_SYS_HZ_CLOCK;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040027
Simon Glass3ff49ec2021-07-24 09:03:29 -060028 addr = hextoul(argv[1], NULL);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040029
Simon Glassbb7d3bb2022-09-06 20:26:52 -060030 header = (struct legacy_img_hdr *)addr;
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053031
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);
Simon Glassbb7d3bb2022-09-06 20:26:52 -060039 memcpy((void *)load_addr, (void *)(addr + sizeof(struct legacy_img_hdr)),
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053040 size);
41
Madan Srinivase8856102017-07-17 12:59:15 -050042 if (argc >= 3)
Simon Glass3ff49ec2021-07-24 09:03:29 -060043 ecrypt_bm_addr = hextoul(argv[2], NULL);
Madan Srinivase8856102017-07-17 12:59:15 -050044
45 rcode = mon_install(load_addr, dpsc_base, freq, ecrypt_bm_addr);
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053046 printf("## installed monitor @ 0x%x, freq [%d], status %d\n",
47 load_addr, freq, rcode);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040048
49 return 0;
50}
51
Madan Srinivase8856102017-07-17 12:59:15 -050052U_BOOT_CMD(mon_install, 3, 0, do_mon_install,
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040053 "Install boot kernel at 'addr'",
54 ""
55);
56
57static void core_spin(void)
58{
Vitaly Andrianovaa750ed2015-07-08 11:40:14 -040059 while (1) {
60 asm volatile (
61 "dsb\n"
62 "isb\n"
63 "wfi\n"
64 );
65 }
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040066}
67
Simon Glassed38aef2020-05-10 11:40:03 -060068int do_mon_power(struct cmd_tbl *cmdtp, int flag, int argc,
69 char *const argv[])
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040070{
71 int rcode = 0, core_id, on;
72 void (*fn)(void);
73
74 fn = core_spin;
75
76 if (argc < 3)
77 return CMD_RET_USAGE;
78
Simon Glass3ff49ec2021-07-24 09:03:29 -060079 core_id = hextoul(argv[1], NULL);
80 on = hextoul(argv[2], NULL);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040081
82 if (on)
83 rcode = mon_power_on(core_id, fn);
84 else
85 rcode = mon_power_off(core_id);
86
87 if (on) {
88 if (!rcode)
89 printf("core %d powered on successfully\n", core_id);
90 else
91 printf("core %d power on failure\n", core_id);
92 } else {
93 printf("core %d powered off successfully\n", core_id);
94 }
95
96 return 0;
97}
98
99U_BOOT_CMD(mon_power, 3, 0, do_mon_power,
100 "Power On/Off secondary core",
101 "mon_power <coreid> <oper>\n"
102 "- coreid (1-3) and oper (1 - ON, 0 - OFF)\n"
103 ""
104);