booti.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <lmb.h>
  11. #include <mapmem.h>
  12. #include <linux/kernel.h>
  13. #include <linux/sizes.h>
  14. /*
  15. * Image booting support
  16. */
  17. static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
  18. char * const argv[], bootm_headers_t *images)
  19. {
  20. int ret;
  21. ulong ld;
  22. ulong relocated_addr;
  23. ulong image_size;
  24. ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
  25. images, 1);
  26. /* Setup Linux kernel Image entry point */
  27. if (!argc) {
  28. ld = load_addr;
  29. debug("* kernel: default image load address = 0x%08lx\n",
  30. load_addr);
  31. } else {
  32. ld = simple_strtoul(argv[0], NULL, 16);
  33. debug("* kernel: cmdline image address = 0x%08lx\n", ld);
  34. }
  35. ret = booti_setup(ld, &relocated_addr, &image_size, false);
  36. if (ret != 0)
  37. return 1;
  38. /* Handle BOOTM_STATE_LOADOS */
  39. if (relocated_addr != ld) {
  40. debug("Moving Image from 0x%lx to 0x%lx\n", ld, relocated_addr);
  41. memmove((void *)relocated_addr, (void *)ld, image_size);
  42. }
  43. images->ep = relocated_addr;
  44. images->os.start = relocated_addr;
  45. images->os.end = relocated_addr + image_size;
  46. lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size));
  47. /*
  48. * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
  49. * have a header that provide this informaiton.
  50. */
  51. if (bootm_find_images(flag, argc, argv))
  52. return 1;
  53. return 0;
  54. }
  55. int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  56. {
  57. int ret;
  58. /* Consume 'booti' */
  59. argc--; argv++;
  60. if (booti_start(cmdtp, flag, argc, argv, &images))
  61. return 1;
  62. /*
  63. * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
  64. * disable interrupts ourselves
  65. */
  66. bootm_disable_interrupts();
  67. images.os.os = IH_OS_LINUX;
  68. #ifdef CONFIG_RISCV_SMODE
  69. images.os.arch = IH_ARCH_RISCV;
  70. #elif CONFIG_ARM64
  71. images.os.arch = IH_ARCH_ARM64;
  72. #endif
  73. ret = do_bootm_states(cmdtp, flag, argc, argv,
  74. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  75. BOOTM_STATE_RAMDISK |
  76. #endif
  77. BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  78. BOOTM_STATE_OS_GO,
  79. &images, 1);
  80. return ret;
  81. }
  82. #ifdef CONFIG_SYS_LONGHELP
  83. static char booti_help_text[] =
  84. "[addr [initrd[:size]] [fdt]]\n"
  85. " - boot Linux 'Image' stored at 'addr'\n"
  86. "\tThe argument 'initrd' is optional and specifies the address\n"
  87. "\tof an initrd in memory. The optional parameter ':size' allows\n"
  88. "\tspecifying the size of a RAW initrd.\n"
  89. #if defined(CONFIG_OF_LIBFDT)
  90. "\tSince booting a Linux kernel requires a flat device-tree, a\n"
  91. "\tthird argument providing the address of the device-tree blob\n"
  92. "\tis required. To boot a kernel with a device-tree blob but\n"
  93. "\twithout an initrd image, use a '-' for the initrd argument.\n"
  94. #endif
  95. "";
  96. #endif
  97. U_BOOT_CMD(
  98. booti, CONFIG_SYS_MAXARGS, 1, do_booti,
  99. "boot Linux kernel 'Image' format from memory", booti_help_text
  100. );