1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
9 #include <asm/mach-imx/sys_proto.h>
13 #include <linux/compiler.h>
16 int arch_auxiliary_core_up(u32 core_id, ulong addr)
25 pc = *(u32 *)(addr + 4);
28 * handling ELF64 binaries
29 * isn't supported yet.
31 if (valid_elf_image(addr)) {
33 pc = load_elf_image_phdr(addr);
35 return CMD_RET_FAILURE;
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).
44 pc = *(u32 *)(addr + 4);
47 printf("## Starting auxiliary core stack = 0x%08lX, pc = 0x%08lX...\n",
50 /* Set the stack and pc to M4 bootROM */
51 writel(stack, M4_BOOTROM_BASE_ADDR);
52 writel(pc, M4_BOOTROM_BASE_ADDR + 4);
58 call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_START, 0, 0, 0);
60 clrsetbits_le32(SRC_BASE_ADDR + SRC_M4_REG_OFFSET,
61 SRC_M4C_NON_SCLR_RST_MASK, SRC_M4_ENABLE_MASK);
67 int arch_auxiliary_core_check_up(u32 core_id)
70 return call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_STARTED, 0, 0, 0);
74 val = readl(SRC_BASE_ADDR + SRC_M4_REG_OFFSET);
76 if (val & SRC_M4C_NON_SCLR_RST_MASK)
77 return 0; /* assert in reset */
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.
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.
96 static int do_bootaux(struct cmd_tbl *cmdtp, int flag, int argc,
103 return CMD_RET_USAGE;
105 up = arch_auxiliary_core_check_up(0);
107 printf("## Auxiliary core is already up\n");
108 return CMD_RET_SUCCESS;
111 addr = simple_strtoul(argv[1], NULL, 16);
114 return CMD_RET_FAILURE;
116 ret = arch_auxiliary_core_up(0, addr);
118 return CMD_RET_FAILURE;
120 return CMD_RET_SUCCESS;
124 bootaux, CONFIG_SYS_MAXARGS, 1, do_bootaux,
125 "Start auxiliary core",