blob: ec0da1164f3cb888f32a9c711683f4d8b6804a57 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fanfcabb6d2016-01-28 16:55:04 +08002/*
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
Peng Fanfcabb6d2016-01-28 16:55:04 +08004 */
5
6#include <common.h>
Peng Fand7e46ca2018-01-10 13:20:32 +08007#include <asm/io.h>
Peng Fanbac08452018-01-10 13:20:33 +08008#include <asm/mach-imx/sys_proto.h>
Peng Fanfcabb6d2016-01-28 16:55:04 +08009#include <command.h>
Igor Opaniukb65af982019-12-30 13:56:44 +020010#include <elf.h>
Peng Fanbac08452018-01-10 13:20:33 +080011#include <imx_sip.h>
Tom Rini2f218872018-01-03 08:52:39 -050012#include <linux/compiler.h>
Igor Opaniukbfc68a42019-11-28 15:56:20 +020013#include <cpu_func.h>
Peng Fanfcabb6d2016-01-28 16:55:04 +080014
Igor Opaniukb65af982019-12-30 13:56:44 +020015int arch_auxiliary_core_up(u32 core_id, ulong addr)
Peng Fanfcabb6d2016-01-28 16:55:04 +080016{
Peng Fand7e46ca2018-01-10 13:20:32 +080017 ulong stack, pc;
18
Igor Opaniukb65af982019-12-30 13:56:44 +020019 if (!addr)
Peng Fand7e46ca2018-01-10 13:20:32 +080020 return -EINVAL;
21
Igor Opaniukb65af982019-12-30 13:56:44 +020022#ifdef CONFIG_IMX8M
23 stack = *(u32 *)addr;
24 pc = *(u32 *)(addr + 4);
25#else
26 /*
27 * handling ELF64 binaries
28 * isn't supported yet.
29 */
30 if (valid_elf_image(addr)) {
31 stack = 0x0;
32 pc = load_elf_image_phdr(addr);
33 if (!pc)
34 return CMD_RET_FAILURE;
Peng Fand7e46ca2018-01-10 13:20:32 +080035
Igor Opaniukb65af982019-12-30 13:56:44 +020036 } else {
37 /*
38 * Assume binary file with vector table at the beginning.
39 * Cortex-M4 vector tables start with the stack pointer (SP)
40 * and reset vector (initial PC).
41 */
42 stack = *(u32 *)addr;
43 pc = *(u32 *)(addr + 4);
44 }
45#endif
Igor Opaniukebbee912019-11-28 15:56:19 +020046 printf("## Starting auxiliary core stack = 0x%08lX, pc = 0x%08lX...\n",
47 stack, pc);
48
Peng Fand7e46ca2018-01-10 13:20:32 +080049 /* Set the stack and pc to M4 bootROM */
50 writel(stack, M4_BOOTROM_BASE_ADDR);
51 writel(pc, M4_BOOTROM_BASE_ADDR + 4);
52
Igor Opaniukbfc68a42019-11-28 15:56:20 +020053 flush_dcache_all();
54
Peng Fand7e46ca2018-01-10 13:20:32 +080055 /* Enable M4 */
Peng Fan39945c12018-11-20 10:19:25 +000056#ifdef CONFIG_IMX8M
Ye Lie5e91092019-10-26 16:24:03 +020057 call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_START, 0, 0, 0);
Peng Fanbac08452018-01-10 13:20:33 +080058#else
Peng Fand7e46ca2018-01-10 13:20:32 +080059 clrsetbits_le32(SRC_BASE_ADDR + SRC_M4_REG_OFFSET,
60 SRC_M4C_NON_SCLR_RST_MASK, SRC_M4_ENABLE_MASK);
Peng Fanbac08452018-01-10 13:20:33 +080061#endif
Peng Fand7e46ca2018-01-10 13:20:32 +080062
63 return 0;
Peng Fanfcabb6d2016-01-28 16:55:04 +080064}
65
Peng Fand7e46ca2018-01-10 13:20:32 +080066int arch_auxiliary_core_check_up(u32 core_id)
Peng Fanfcabb6d2016-01-28 16:55:04 +080067{
Peng Fan39945c12018-11-20 10:19:25 +000068#ifdef CONFIG_IMX8M
Ye Lie5e91092019-10-26 16:24:03 +020069 return call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_STARTED, 0, 0, 0);
Peng Fanbac08452018-01-10 13:20:33 +080070#else
Peng Fand7e46ca2018-01-10 13:20:32 +080071 unsigned int val;
72
73 val = readl(SRC_BASE_ADDR + SRC_M4_REG_OFFSET);
74
75 if (val & SRC_M4C_NON_SCLR_RST_MASK)
76 return 0; /* assert in reset */
77
78 return 1;
Peng Fanbac08452018-01-10 13:20:33 +080079#endif
Peng Fanfcabb6d2016-01-28 16:55:04 +080080}
81
Peng Fanfcabb6d2016-01-28 16:55:04 +080082/*
83 * To i.MX6SX and i.MX7D, the image supported by bootaux needs
84 * the reset vector at the head for the image, with SP and PC
85 * as the first two words.
86 *
87 * Per the cortex-M reference manual, the reset vector of M4 needs
88 * to exist at 0x0 (TCMUL). The PC and SP are the first two addresses
89 * of that vector. So to boot M4, the A core must build the M4's reset
90 * vector with getting the PC and SP from image and filling them to
91 * TCMUL. When M4 is kicked, it will load the PC and SP by itself.
92 * The TCMUL is mapped to (M4_BOOTROM_BASE_ADDR) at A core side for
93 * accessing the M4 TCMUL.
94 */
Tom Rini2f218872018-01-03 08:52:39 -050095static int do_bootaux(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Peng Fanfcabb6d2016-01-28 16:55:04 +080096{
97 ulong addr;
98 int ret, up;
99
100 if (argc < 2)
101 return CMD_RET_USAGE;
102
103 up = arch_auxiliary_core_check_up(0);
104 if (up) {
105 printf("## Auxiliary core is already up\n");
106 return CMD_RET_SUCCESS;
107 }
108
109 addr = simple_strtoul(argv[1], NULL, 16);
110
Igor Opaniukebbee912019-11-28 15:56:19 +0200111 if (!addr)
112 return CMD_RET_FAILURE;
Peng Fanfcabb6d2016-01-28 16:55:04 +0800113
114 ret = arch_auxiliary_core_up(0, addr);
115 if (ret)
116 return CMD_RET_FAILURE;
117
118 return CMD_RET_SUCCESS;
119}
120
121U_BOOT_CMD(
122 bootaux, CONFIG_SYS_MAXARGS, 1, do_bootaux,
123 "Start auxiliary core",
124 ""
125);