blob: 868633cf8a47d51ee9e8855e8f9d98a5b7833862 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fan6f6058b2016-01-28 16:55:04 +08002/*
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
Peng Fan6f6058b2016-01-28 16:55:04 +08004 */
5
6#include <common.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06007#include <log.h>
Peng Fan8cf22312018-01-10 13:20:32 +08008#include <asm/io.h>
Peng Fanecd7ab52018-01-10 13:20:33 +08009#include <asm/mach-imx/sys_proto.h>
Peng Fan6f6058b2016-01-28 16:55:04 +080010#include <command.h>
Igor Opaniukc0f037f2019-12-30 13:56:44 +020011#include <elf.h>
Peng Fanecd7ab52018-01-10 13:20:33 +080012#include <imx_sip.h>
Tom Rini20b9f2e2018-01-03 08:52:39 -050013#include <linux/compiler.h>
Igor Opaniuk89038262019-11-28 15:56:20 +020014#include <cpu_func.h>
Peng Fan6f6058b2016-01-28 16:55:04 +080015
Igor Opaniukc0f037f2019-12-30 13:56:44 +020016int arch_auxiliary_core_up(u32 core_id, ulong addr)
Peng Fan6f6058b2016-01-28 16:55:04 +080017{
Peng Fan8cf22312018-01-10 13:20:32 +080018 ulong stack, pc;
19
Igor Opaniukc0f037f2019-12-30 13:56:44 +020020 if (!addr)
Peng Fan8cf22312018-01-10 13:20:32 +080021 return -EINVAL;
22
Igor Opaniukc0f037f2019-12-30 13:56:44 +020023#ifdef CONFIG_IMX8M
24 stack = *(u32 *)addr;
25 pc = *(u32 *)(addr + 4);
26#else
27 /*
28 * handling ELF64 binaries
29 * isn't supported yet.
30 */
31 if (valid_elf_image(addr)) {
32 stack = 0x0;
33 pc = load_elf_image_phdr(addr);
34 if (!pc)
35 return CMD_RET_FAILURE;
Peng Fan8cf22312018-01-10 13:20:32 +080036
Igor Opaniukc0f037f2019-12-30 13:56:44 +020037 } else {
38 /*
39 * Assume binary file with vector table at the beginning.
40 * Cortex-M4 vector tables start with the stack pointer (SP)
41 * and reset vector (initial PC).
42 */
43 stack = *(u32 *)addr;
44 pc = *(u32 *)(addr + 4);
45 }
46#endif
Igor Opaniuk0ba1b4d2019-11-28 15:56:19 +020047 printf("## Starting auxiliary core stack = 0x%08lX, pc = 0x%08lX...\n",
48 stack, pc);
49
Peng Fan8cf22312018-01-10 13:20:32 +080050 /* Set the stack and pc to M4 bootROM */
51 writel(stack, M4_BOOTROM_BASE_ADDR);
52 writel(pc, M4_BOOTROM_BASE_ADDR + 4);
53
Igor Opaniuk89038262019-11-28 15:56:20 +020054 flush_dcache_all();
55
Peng Fan8cf22312018-01-10 13:20:32 +080056 /* Enable M4 */
Peng Fancd357ad2018-11-20 10:19:25 +000057#ifdef CONFIG_IMX8M
Ye Li264977d2019-10-26 16:24:03 +020058 call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_START, 0, 0, 0);
Peng Fanecd7ab52018-01-10 13:20:33 +080059#else
Peng Fan8cf22312018-01-10 13:20:32 +080060 clrsetbits_le32(SRC_BASE_ADDR + SRC_M4_REG_OFFSET,
61 SRC_M4C_NON_SCLR_RST_MASK, SRC_M4_ENABLE_MASK);
Peng Fanecd7ab52018-01-10 13:20:33 +080062#endif
Peng Fan8cf22312018-01-10 13:20:32 +080063
64 return 0;
Peng Fan6f6058b2016-01-28 16:55:04 +080065}
66
Peng Fan8cf22312018-01-10 13:20:32 +080067int arch_auxiliary_core_check_up(u32 core_id)
Peng Fan6f6058b2016-01-28 16:55:04 +080068{
Peng Fancd357ad2018-11-20 10:19:25 +000069#ifdef CONFIG_IMX8M
Ye Li264977d2019-10-26 16:24:03 +020070 return call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_STARTED, 0, 0, 0);
Peng Fanecd7ab52018-01-10 13:20:33 +080071#else
Peng Fan8cf22312018-01-10 13:20:32 +080072 unsigned int val;
73
74 val = readl(SRC_BASE_ADDR + SRC_M4_REG_OFFSET);
75
76 if (val & SRC_M4C_NON_SCLR_RST_MASK)
77 return 0; /* assert in reset */
78
79 return 1;
Peng Fanecd7ab52018-01-10 13:20:33 +080080#endif
Peng Fan6f6058b2016-01-28 16:55:04 +080081}
82
Peng Fan6f6058b2016-01-28 16:55:04 +080083/*
84 * To i.MX6SX and i.MX7D, the image supported by bootaux needs
85 * the reset vector at the head for the image, with SP and PC
86 * as the first two words.
87 *
88 * Per the cortex-M reference manual, the reset vector of M4 needs
89 * to exist at 0x0 (TCMUL). The PC and SP are the first two addresses
90 * of that vector. So to boot M4, the A core must build the M4's reset
91 * vector with getting the PC and SP from image and filling them to
92 * TCMUL. When M4 is kicked, it will load the PC and SP by itself.
93 * The TCMUL is mapped to (M4_BOOTROM_BASE_ADDR) at A core side for
94 * accessing the M4 TCMUL.
95 */
Simon Glass09140112020-05-10 11:40:03 -060096static int do_bootaux(struct cmd_tbl *cmdtp, int flag, int argc,
97 char *const argv[])
Peng Fan6f6058b2016-01-28 16:55:04 +080098{
99 ulong addr;
100 int ret, up;
101
102 if (argc < 2)
103 return CMD_RET_USAGE;
104
105 up = arch_auxiliary_core_check_up(0);
106 if (up) {
107 printf("## Auxiliary core is already up\n");
108 return CMD_RET_SUCCESS;
109 }
110
111 addr = simple_strtoul(argv[1], NULL, 16);
112
Igor Opaniuk0ba1b4d2019-11-28 15:56:19 +0200113 if (!addr)
114 return CMD_RET_FAILURE;
Peng Fan6f6058b2016-01-28 16:55:04 +0800115
116 ret = arch_auxiliary_core_up(0, addr);
117 if (ret)
118 return CMD_RET_FAILURE;
119
120 return CMD_RET_SUCCESS;
121}
122
123U_BOOT_CMD(
124 bootaux, CONFIG_SYS_MAXARGS, 1, do_bootaux,
125 "Start auxiliary core",
126 ""
127);