booti.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #ifdef CONFIG_SYS_LONGHELP
  84. static char booti_help_text[] =
  85. "[addr [initrd[:size]] [fdt]]\n"
  86. " - boot Linux 'Image' stored at 'addr'\n"
  87. "\tThe argument 'initrd' is optional and specifies the address\n"
  88. "\tof an initrd in memory. The optional parameter ':size' allows\n"
  89. "\tspecifying the size of a RAW initrd.\n"
  90. #if defined(CONFIG_OF_LIBFDT)
  91. "\tSince booting a Linux kernel requires a flat device-tree, a\n"
  92. "\tthird argument providing the address of the device-tree blob\n"
  93. "\tis required. To boot a kernel with a device-tree blob but\n"
  94. "\twithout an initrd image, use a '-' for the initrd argument.\n"
  95. #endif
  96. "";
  97. #endif
  98. U_BOOT_CMD(
  99. booti, CONFIG_SYS_MAXARGS, 1, do_booti,
  100. "boot Linux kernel 'Image' format from memory", booti_help_text
  101. );