imx_bootaux.c 2.2 KB

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