blob: c2525bd75663d3cfb7a1c31cdcfc260c438c04db [file] [log] [blame]
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -04001/*
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 Vutlaae6b2222016-09-16 10:17:12 +053012#include <image.h>
Tom Rini108ee582016-03-16 09:10:08 -040013#include <mach/mon.h>
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040014asm(".arch_extension sec\n\t");
15
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040016static int do_mon_install(cmd_tbl_t *cmdtp, int flag, int argc,
17 char * const argv[])
18{
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053019 u32 addr, dpsc_base = 0x1E80000, freq, load_addr, size;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040020 int rcode = 0;
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053021 struct image_header *header;
Madan Srinivase8856102017-07-17 12:59:15 -050022 u32 ecrypt_bm_addr = 0;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040023
24 if (argc < 2)
25 return CMD_RET_USAGE;
26
Vitaly Andrianov7fd5b642015-09-19 16:26:41 +053027 freq = CONFIG_SYS_HZ_CLOCK;
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040028
29 addr = simple_strtoul(argv[1], NULL, 16);
30
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053031 header = (struct image_header *)addr;
32
33 if (image_get_magic(header) != IH_MAGIC) {
34 printf("## Please update monitor image\n");
35 return -EFAULT;
36 }
37
38 load_addr = image_get_load(header);
39 size = image_get_data_size(header);
40 memcpy((void *)load_addr, (void *)(addr + sizeof(struct image_header)),
41 size);
42
Madan Srinivase8856102017-07-17 12:59:15 -050043 if (argc >= 3)
44 ecrypt_bm_addr = simple_strtoul(argv[2], NULL, 16);
45
46 rcode = mon_install(load_addr, dpsc_base, freq, ecrypt_bm_addr);
Lokesh Vutlaae6b2222016-09-16 10:17:12 +053047 printf("## installed monitor @ 0x%x, freq [%d], status %d\n",
48 load_addr, freq, rcode);
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040049
50 return 0;
51}
52
Madan Srinivase8856102017-07-17 12:59:15 -050053U_BOOT_CMD(mon_install, 3, 0, do_mon_install,
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040054 "Install boot kernel at 'addr'",
55 ""
56);
57
58static void core_spin(void)
59{
Vitaly Andrianovaa750ed2015-07-08 11:40:14 -040060 while (1) {
61 asm volatile (
62 "dsb\n"
63 "isb\n"
64 "wfi\n"
65 );
66 }
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040067}
68
Vitaly Andrianov7bcf4d62014-04-04 13:16:53 -040069int do_mon_power(cmd_tbl_t *cmdtp, int flag, int argc,
70 char * const argv[])
71{
72 int rcode = 0, core_id, on;
73 void (*fn)(void);
74
75 fn = core_spin;
76
77 if (argc < 3)
78 return CMD_RET_USAGE;
79
80 core_id = simple_strtoul(argv[1], NULL, 16);
81 on = simple_strtoul(argv[2], NULL, 16);
82
83 if (on)
84 rcode = mon_power_on(core_id, fn);
85 else
86 rcode = mon_power_off(core_id);
87
88 if (on) {
89 if (!rcode)
90 printf("core %d powered on successfully\n", core_id);
91 else
92 printf("core %d power on failure\n", core_id);
93 } else {
94 printf("core %d powered off successfully\n", core_id);
95 }
96
97 return 0;
98}
99
100U_BOOT_CMD(mon_power, 3, 0, do_mon_power,
101 "Power On/Off secondary core",
102 "mon_power <coreid> <oper>\n"
103 "- coreid (1-3) and oper (1 - ON, 0 - OFF)\n"
104 ""
105);