cmd_mon.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * K2HK: secure kernel command file
  3. *
  4. * (C) Copyright 2012-2014
  5. * Texas Instruments Incorporated, <www.ti.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <command.h>
  11. #include <image.h>
  12. #include <mach/mon.h>
  13. asm(".arch_extension sec\n\t");
  14. static int do_mon_install(cmd_tbl_t *cmdtp, int flag, int argc,
  15. char * const argv[])
  16. {
  17. u32 addr, dpsc_base = 0x1E80000, freq, load_addr, size;
  18. int rcode = 0;
  19. struct image_header *header;
  20. if (argc < 2)
  21. return CMD_RET_USAGE;
  22. freq = CONFIG_SYS_HZ_CLOCK;
  23. addr = simple_strtoul(argv[1], NULL, 16);
  24. header = (struct image_header *)addr;
  25. if (image_get_magic(header) != IH_MAGIC) {
  26. printf("## Please update monitor image\n");
  27. return -EFAULT;
  28. }
  29. load_addr = image_get_load(header);
  30. size = image_get_data_size(header);
  31. memcpy((void *)load_addr, (void *)(addr + sizeof(struct image_header)),
  32. size);
  33. rcode = mon_install(load_addr, dpsc_base, freq);
  34. printf("## installed monitor @ 0x%x, freq [%d], status %d\n",
  35. load_addr, freq, rcode);
  36. return 0;
  37. }
  38. U_BOOT_CMD(mon_install, 2, 0, do_mon_install,
  39. "Install boot kernel at 'addr'",
  40. ""
  41. );
  42. static void core_spin(void)
  43. {
  44. while (1) {
  45. asm volatile (
  46. "dsb\n"
  47. "isb\n"
  48. "wfi\n"
  49. );
  50. }
  51. }
  52. int do_mon_power(cmd_tbl_t *cmdtp, int flag, int argc,
  53. char * const argv[])
  54. {
  55. int rcode = 0, core_id, on;
  56. void (*fn)(void);
  57. fn = core_spin;
  58. if (argc < 3)
  59. return CMD_RET_USAGE;
  60. core_id = simple_strtoul(argv[1], NULL, 16);
  61. on = simple_strtoul(argv[2], NULL, 16);
  62. if (on)
  63. rcode = mon_power_on(core_id, fn);
  64. else
  65. rcode = mon_power_off(core_id);
  66. if (on) {
  67. if (!rcode)
  68. printf("core %d powered on successfully\n", core_id);
  69. else
  70. printf("core %d power on failure\n", core_id);
  71. } else {
  72. printf("core %d powered off successfully\n", core_id);
  73. }
  74. return 0;
  75. }
  76. U_BOOT_CMD(mon_power, 3, 0, do_mon_power,
  77. "Power On/Off secondary core",
  78. "mon_power <coreid> <oper>\n"
  79. "- coreid (1-3) and oper (1 - ON, 0 - OFF)\n"
  80. ""
  81. );