cmd_mon.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. u32 ecrypt_bm_addr = 0;
  21. if (argc < 2)
  22. return CMD_RET_USAGE;
  23. freq = CONFIG_SYS_HZ_CLOCK;
  24. addr = simple_strtoul(argv[1], NULL, 16);
  25. header = (struct image_header *)addr;
  26. if (image_get_magic(header) != IH_MAGIC) {
  27. printf("## Please update monitor image\n");
  28. return -EFAULT;
  29. }
  30. load_addr = image_get_load(header);
  31. size = image_get_data_size(header);
  32. memcpy((void *)load_addr, (void *)(addr + sizeof(struct image_header)),
  33. size);
  34. if (argc >= 3)
  35. ecrypt_bm_addr = simple_strtoul(argv[2], NULL, 16);
  36. rcode = mon_install(load_addr, dpsc_base, freq, ecrypt_bm_addr);
  37. printf("## installed monitor @ 0x%x, freq [%d], status %d\n",
  38. load_addr, freq, rcode);
  39. return 0;
  40. }
  41. U_BOOT_CMD(mon_install, 3, 0, do_mon_install,
  42. "Install boot kernel at 'addr'",
  43. ""
  44. );
  45. static void core_spin(void)
  46. {
  47. while (1) {
  48. asm volatile (
  49. "dsb\n"
  50. "isb\n"
  51. "wfi\n"
  52. );
  53. }
  54. }
  55. int do_mon_power(cmd_tbl_t *cmdtp, int flag, int argc,
  56. char * const argv[])
  57. {
  58. int rcode = 0, core_id, on;
  59. void (*fn)(void);
  60. fn = core_spin;
  61. if (argc < 3)
  62. return CMD_RET_USAGE;
  63. core_id = simple_strtoul(argv[1], NULL, 16);
  64. on = simple_strtoul(argv[2], NULL, 16);
  65. if (on)
  66. rcode = mon_power_on(core_id, fn);
  67. else
  68. rcode = mon_power_off(core_id);
  69. if (on) {
  70. if (!rcode)
  71. printf("core %d powered on successfully\n", core_id);
  72. else
  73. printf("core %d power on failure\n", core_id);
  74. } else {
  75. printf("core %d powered off successfully\n", core_id);
  76. }
  77. return 0;
  78. }
  79. U_BOOT_CMD(mon_power, 3, 0, do_mon_power,
  80. "Power On/Off secondary core",
  81. "mon_power <coreid> <oper>\n"
  82. "- coreid (1-3) and oper (1 - ON, 0 - OFF)\n"
  83. ""
  84. );