booti.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2000-2009
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. #include <common.h>
  7. #include <bootm.h>
  8. #include <command.h>
  9. #include <image.h>
  10. #include <irq_func.h>
  11. #include <lmb.h>
  12. #include <mapmem.h>
  13. #include <linux/kernel.h>
  14. #include <linux/sizes.h>
  15. /*
  16. * Image booting support
  17. */
  18. static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
  19. char * const argv[], bootm_headers_t *images)
  20. {
  21. int ret;
  22. ulong ld;
  23. ulong relocated_addr;
  24. ulong image_size;
  25. ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
  26. images, 1);
  27. /* Setup Linux kernel Image entry point */
  28. if (!argc) {
  29. ld = load_addr;
  30. debug("* kernel: default image load address = 0x%08lx\n",
  31. load_addr);
  32. } else {
  33. ld = simple_strtoul(argv[0], NULL, 16);
  34. debug("* kernel: cmdline image address = 0x%08lx\n", ld);
  35. }
  36. ret = booti_setup(ld, &relocated_addr, &image_size, false);
  37. if (ret != 0)
  38. return 1;
  39. /* Handle BOOTM_STATE_LOADOS */
  40. if (relocated_addr != ld) {
  41. debug("Moving Image from 0x%lx to 0x%lx\n", ld, relocated_addr);
  42. memmove((void *)relocated_addr, (void *)ld, image_size);
  43. }
  44. images->ep = relocated_addr;
  45. images->os.start = relocated_addr;
  46. images->os.end = relocated_addr + image_size;
  47. lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size));
  48. /*
  49. * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
  50. * have a header that provide this informaiton.
  51. */
  52. if (bootm_find_images(flag, argc, argv))
  53. return 1;
  54. return 0;
  55. }
  56. int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  57. {
  58. int ret;
  59. /* Consume 'booti' */
  60. argc--; argv++;
  61. if (booti_start(cmdtp, flag, argc, argv, &images))
  62. return 1;
  63. /*
  64. * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
  65. * disable interrupts ourselves
  66. */
  67. bootm_disable_interrupts();
  68. images.os.os = IH_OS_LINUX;
  69. #ifdef CONFIG_RISCV_SMODE
  70. images.os.arch = IH_ARCH_RISCV;
  71. #elif CONFIG_ARM64
  72. images.os.arch = IH_ARCH_ARM64;
  73. #endif
  74. ret = do_bootm_states(cmdtp, flag, argc, argv,
  75. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  76. BOOTM_STATE_RAMDISK |
  77. #endif
  78. BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  79. BOOTM_STATE_OS_GO,
  80. &images, 1);
  81. return ret;
  82. }
  83. /*******************************************************************/
  84. /* sboot - boot security image */
  85. /*******************************************************************/
  86. #ifdef CONFIG_TARGET_LIGHT_C910
  87. #if CONFIG_IS_ENABLED(LIGHT_SEC_UPGRADE)
  88. extern int light_vimage(int argc, char *const argv[]);
  89. int do_vimage(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  90. {
  91. if (light_vimage(argc, argv) != 0)
  92. return 1;
  93. return 0;
  94. }
  95. U_BOOT_CMD(
  96. vimage, CONFIG_SYS_MAXARGS, 1, do_vimage,
  97. "verify image file with known pubkey which reside in father image or itself!",
  98. "vimage addr imgname[[tee/tf] - verify specifed image resides in addr\n"
  99. );
  100. #endif
  101. #if CONFIG_IS_ENABLED(LIGHT_SEC_BOOT_WITH_VERIFY_VAL_A) || CONFIG_IS_ENABLED(LIGHT_SEC_BOOT_WITH_VERIFY_VAL_B) || CONFIG_IS_ENABLED(LIGHT_SEC_BOOT_WITH_VERIFY_ANT_REF)
  102. extern int light_secboot(int argc, char * const argv[]);
  103. int do_secboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  104. {
  105. if (light_secboot(argc, argv) != 0) {
  106. run_command("reset", 0);
  107. return -1;
  108. }
  109. return 0;
  110. }
  111. U_BOOT_CMD(
  112. secboot, CONFIG_SYS_MAXARGS, 1, do_secboot,
  113. "verify image file with known pubkey which reside in father image or itself!",
  114. "vimage addr imgname[[tee/tf] - verify specifed image resides in addr\n"
  115. );
  116. #endif
  117. #endif
  118. #ifdef CONFIG_SYS_LONGHELP
  119. static char booti_help_text[] =
  120. "[addr [initrd[:size]] [fdt]]\n"
  121. " - boot Linux 'Image' stored at 'addr'\n"
  122. "\tThe argument 'initrd' is optional and specifies the address\n"
  123. "\tof an initrd in memory. The optional parameter ':size' allows\n"
  124. "\tspecifying the size of a RAW initrd.\n"
  125. #if defined(CONFIG_OF_LIBFDT)
  126. "\tSince booting a Linux kernel requires a flat device-tree, a\n"
  127. "\tthird argument providing the address of the device-tree blob\n"
  128. "\tis required. To boot a kernel with a device-tree blob but\n"
  129. "\twithout an initrd image, use a '-' for the initrd argument.\n"
  130. #endif
  131. "";
  132. #endif
  133. U_BOOT_CMD(
  134. booti, CONFIG_SYS_MAXARGS, 1, do_booti,
  135. "boot Linux kernel 'Image' format from memory", booti_help_text
  136. );