cmd_mon.c 2.1 KB

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