imx_bootaux.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/mach-imx/sys_proto.h>
  9. #include <command.h>
  10. #include <imx_sip.h>
  11. #include <linux/compiler.h>
  12. int arch_auxiliary_core_up(u32 core_id, ulong boot_private_data)
  13. {
  14. ulong stack, pc;
  15. if (!boot_private_data)
  16. return -EINVAL;
  17. stack = *(ulong *)boot_private_data;
  18. pc = *(ulong *)(boot_private_data + 4);
  19. /* Set the stack and pc to M4 bootROM */
  20. writel(stack, M4_BOOTROM_BASE_ADDR);
  21. writel(pc, M4_BOOTROM_BASE_ADDR + 4);
  22. /* Enable M4 */
  23. #ifdef CONFIG_MX8M
  24. call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_START, 0, 0);
  25. #else
  26. clrsetbits_le32(SRC_BASE_ADDR + SRC_M4_REG_OFFSET,
  27. SRC_M4C_NON_SCLR_RST_MASK, SRC_M4_ENABLE_MASK);
  28. #endif
  29. return 0;
  30. }
  31. int arch_auxiliary_core_check_up(u32 core_id)
  32. {
  33. #ifdef CONFIG_MX8M
  34. return call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_STARTED, 0, 0);
  35. #else
  36. unsigned int val;
  37. val = readl(SRC_BASE_ADDR + SRC_M4_REG_OFFSET);
  38. if (val & SRC_M4C_NON_SCLR_RST_MASK)
  39. return 0; /* assert in reset */
  40. return 1;
  41. #endif
  42. }
  43. /*
  44. * To i.MX6SX and i.MX7D, the image supported by bootaux needs
  45. * the reset vector at the head for the image, with SP and PC
  46. * as the first two words.
  47. *
  48. * Per the cortex-M reference manual, the reset vector of M4 needs
  49. * to exist at 0x0 (TCMUL). The PC and SP are the first two addresses
  50. * of that vector. So to boot M4, the A core must build the M4's reset
  51. * vector with getting the PC and SP from image and filling them to
  52. * TCMUL. When M4 is kicked, it will load the PC and SP by itself.
  53. * The TCMUL is mapped to (M4_BOOTROM_BASE_ADDR) at A core side for
  54. * accessing the M4 TCMUL.
  55. */
  56. static int do_bootaux(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  57. {
  58. ulong addr;
  59. int ret, up;
  60. if (argc < 2)
  61. return CMD_RET_USAGE;
  62. up = arch_auxiliary_core_check_up(0);
  63. if (up) {
  64. printf("## Auxiliary core is already up\n");
  65. return CMD_RET_SUCCESS;
  66. }
  67. addr = simple_strtoul(argv[1], NULL, 16);
  68. printf("## Starting auxiliary core at 0x%08lX ...\n", addr);
  69. ret = arch_auxiliary_core_up(0, addr);
  70. if (ret)
  71. return CMD_RET_FAILURE;
  72. return CMD_RET_SUCCESS;
  73. }
  74. U_BOOT_CMD(
  75. bootaux, CONFIG_SYS_MAXARGS, 1, do_bootaux,
  76. "Start auxiliary core",
  77. ""
  78. );