booti.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size));
  45. /*
  46. * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
  47. * have a header that provide this informaiton.
  48. */
  49. if (bootm_find_images(flag, argc, argv))
  50. return 1;
  51. return 0;
  52. }
  53. int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  54. {
  55. int ret;
  56. /* Consume 'booti' */
  57. argc--; argv++;
  58. if (booti_start(cmdtp, flag, argc, argv, &images))
  59. return 1;
  60. /*
  61. * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
  62. * disable interrupts ourselves
  63. */
  64. bootm_disable_interrupts();
  65. images.os.os = IH_OS_LINUX;
  66. #ifdef CONFIG_RISCV_SMODE
  67. images.os.arch = IH_ARCH_RISCV;
  68. #elif CONFIG_ARM64
  69. images.os.arch = IH_ARCH_ARM64;
  70. #endif
  71. ret = do_bootm_states(cmdtp, flag, argc, argv,
  72. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  73. BOOTM_STATE_RAMDISK |
  74. #endif
  75. BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  76. BOOTM_STATE_OS_GO,
  77. &images, 1);
  78. return ret;
  79. }
  80. #ifdef CONFIG_SYS_LONGHELP
  81. static char booti_help_text[] =
  82. "[addr [initrd[:size]] [fdt]]\n"
  83. " - boot Linux 'Image' stored at 'addr'\n"
  84. "\tThe argument 'initrd' is optional and specifies the address\n"
  85. "\tof an initrd in memory. The optional parameter ':size' allows\n"
  86. "\tspecifying the size of a RAW initrd.\n"
  87. #if defined(CONFIG_OF_LIBFDT)
  88. "\tSince booting a Linux kernel requires a flat device-tree, a\n"
  89. "\tthird argument providing the address of the device-tree blob\n"
  90. "\tis required. To boot a kernel with a device-tree blob but\n"
  91. "\twithout an initrd image, use a '-' for the initrd argument.\n"
  92. #endif
  93. "";
  94. #endif
  95. U_BOOT_CMD(
  96. booti, CONFIG_SYS_MAXARGS, 1, do_booti,
  97. "boot Linux kernel 'Image' format from memory", booti_help_text
  98. );