cmd_bootm.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. /*
  2. * (C) Copyright 2000-2009
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * Boot support
  9. */
  10. #include <common.h>
  11. #include <bootm.h>
  12. #include <command.h>
  13. #include <environment.h>
  14. #include <image.h>
  15. #include <lmb.h>
  16. #include <malloc.h>
  17. #include <nand.h>
  18. #include <asm/byteorder.h>
  19. #include <linux/compiler.h>
  20. #include <linux/ctype.h>
  21. #include <linux/err.h>
  22. #include <u-boot/zlib.h>
  23. DECLARE_GLOBAL_DATA_PTR;
  24. #if defined(CONFIG_CMD_IMI)
  25. static int image_info(unsigned long addr);
  26. #endif
  27. #if defined(CONFIG_CMD_IMLS)
  28. #include <flash.h>
  29. #include <mtd/cfi_flash.h>
  30. extern flash_info_t flash_info[]; /* info for FLASH chips */
  31. #endif
  32. #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
  33. static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  34. #endif
  35. bootm_headers_t images; /* pointers to os/initrd/fdt images */
  36. /* we overload the cmd field with our state machine info instead of a
  37. * function pointer */
  38. static cmd_tbl_t cmd_bootm_sub[] = {
  39. U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
  40. U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
  41. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  42. U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
  43. #endif
  44. #ifdef CONFIG_OF_LIBFDT
  45. U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
  46. #endif
  47. U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
  48. U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
  49. U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
  50. U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""),
  51. U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
  52. };
  53. static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
  54. char * const argv[])
  55. {
  56. int ret = 0;
  57. long state;
  58. cmd_tbl_t *c;
  59. c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
  60. argc--; argv++;
  61. if (c) {
  62. state = (long)c->cmd;
  63. if (state == BOOTM_STATE_START)
  64. state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER;
  65. } else {
  66. /* Unrecognized command */
  67. return CMD_RET_USAGE;
  68. }
  69. if (state != BOOTM_STATE_START && images.state >= state) {
  70. printf("Trying to execute a command out of order\n");
  71. return CMD_RET_USAGE;
  72. }
  73. ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
  74. return ret;
  75. }
  76. /*******************************************************************/
  77. /* bootm - boot application image from image in memory */
  78. /*******************************************************************/
  79. int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  80. {
  81. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  82. static int relocated = 0;
  83. if (!relocated) {
  84. int i;
  85. /* relocate names of sub-command table */
  86. for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
  87. cmd_bootm_sub[i].name += gd->reloc_off;
  88. relocated = 1;
  89. }
  90. #endif
  91. /* determine if we have a sub command */
  92. argc--; argv++;
  93. if (argc > 0) {
  94. char *endp;
  95. simple_strtoul(argv[0], &endp, 16);
  96. /* endp pointing to NULL means that argv[0] was just a
  97. * valid number, pass it along to the normal bootm processing
  98. *
  99. * If endp is ':' or '#' assume a FIT identifier so pass
  100. * along for normal processing.
  101. *
  102. * Right now we assume the first arg should never be '-'
  103. */
  104. if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
  105. return do_bootm_subcommand(cmdtp, flag, argc, argv);
  106. }
  107. return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
  108. BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
  109. BOOTM_STATE_LOADOS |
  110. #if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
  111. BOOTM_STATE_OS_CMDLINE |
  112. #endif
  113. BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  114. BOOTM_STATE_OS_GO, &images, 1);
  115. }
  116. int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
  117. {
  118. const char *ep = getenv("autostart");
  119. if (ep && !strcmp(ep, "yes")) {
  120. char *local_args[2];
  121. local_args[0] = (char *)cmd;
  122. local_args[1] = NULL;
  123. printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
  124. return do_bootm(cmdtp, 0, 1, local_args);
  125. }
  126. return 0;
  127. }
  128. #ifdef CONFIG_SYS_LONGHELP
  129. static char bootm_help_text[] =
  130. "[addr [arg ...]]\n - boot application image stored in memory\n"
  131. "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
  132. "\t'arg' can be the address of an initrd image\n"
  133. #if defined(CONFIG_OF_LIBFDT)
  134. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  135. "\ta third argument is required which is the address of the\n"
  136. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  137. "\tuse a '-' for the second argument. If you do not pass a third\n"
  138. "\ta bd_info struct will be passed instead\n"
  139. #endif
  140. #if defined(CONFIG_FIT)
  141. "\t\nFor the new multi component uImage format (FIT) addresses\n"
  142. "\tmust be extened to include component or configuration unit name:\n"
  143. "\taddr:<subimg_uname> - direct component image specification\n"
  144. "\taddr#<conf_uname> - configuration specification\n"
  145. "\tUse iminfo command to get the list of existing component\n"
  146. "\timages and configurations.\n"
  147. #endif
  148. "\nSub-commands to do part of the bootm sequence. The sub-commands "
  149. "must be\n"
  150. "issued in the order below (it's ok to not issue all sub-commands):\n"
  151. "\tstart [addr [arg ...]]\n"
  152. "\tloados - load OS image\n"
  153. #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
  154. "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
  155. #endif
  156. #if defined(CONFIG_OF_LIBFDT)
  157. "\tfdt - relocate flat device tree\n"
  158. #endif
  159. "\tcmdline - OS specific command line processing/setup\n"
  160. "\tbdt - OS specific bd_t processing\n"
  161. "\tprep - OS specific prep before relocation or go\n"
  162. "\tgo - start OS";
  163. #endif
  164. U_BOOT_CMD(
  165. bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
  166. "boot application image from memory", bootm_help_text
  167. );
  168. /*******************************************************************/
  169. /* bootd - boot default image */
  170. /*******************************************************************/
  171. #if defined(CONFIG_CMD_BOOTD)
  172. int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  173. {
  174. return run_command(getenv("bootcmd"), flag);
  175. }
  176. U_BOOT_CMD(
  177. boot, 1, 1, do_bootd,
  178. "boot default, i.e., run 'bootcmd'",
  179. ""
  180. );
  181. /* keep old command name "bootd" for backward compatibility */
  182. U_BOOT_CMD(
  183. bootd, 1, 1, do_bootd,
  184. "boot default, i.e., run 'bootcmd'",
  185. ""
  186. );
  187. #endif
  188. /*******************************************************************/
  189. /* iminfo - print header info for a requested image */
  190. /*******************************************************************/
  191. #if defined(CONFIG_CMD_IMI)
  192. static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  193. {
  194. int arg;
  195. ulong addr;
  196. int rcode = 0;
  197. if (argc < 2) {
  198. return image_info(load_addr);
  199. }
  200. for (arg = 1; arg < argc; ++arg) {
  201. addr = simple_strtoul(argv[arg], NULL, 16);
  202. if (image_info(addr) != 0)
  203. rcode = 1;
  204. }
  205. return rcode;
  206. }
  207. static int image_info(ulong addr)
  208. {
  209. void *hdr = (void *)addr;
  210. printf("\n## Checking Image at %08lx ...\n", addr);
  211. switch (genimg_get_format(hdr)) {
  212. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  213. case IMAGE_FORMAT_LEGACY:
  214. puts(" Legacy image found\n");
  215. if (!image_check_magic(hdr)) {
  216. puts(" Bad Magic Number\n");
  217. return 1;
  218. }
  219. if (!image_check_hcrc(hdr)) {
  220. puts(" Bad Header Checksum\n");
  221. return 1;
  222. }
  223. image_print_contents(hdr);
  224. puts(" Verifying Checksum ... ");
  225. if (!image_check_dcrc(hdr)) {
  226. puts(" Bad Data CRC\n");
  227. return 1;
  228. }
  229. puts("OK\n");
  230. return 0;
  231. #endif
  232. #if defined(CONFIG_FIT)
  233. case IMAGE_FORMAT_FIT:
  234. puts(" FIT image found\n");
  235. if (!fit_check_format(hdr)) {
  236. puts("Bad FIT image format!\n");
  237. return 1;
  238. }
  239. fit_print_contents(hdr);
  240. if (!fit_all_image_verify(hdr)) {
  241. puts("Bad hash in FIT image!\n");
  242. return 1;
  243. }
  244. return 0;
  245. #endif
  246. default:
  247. puts("Unknown image format!\n");
  248. break;
  249. }
  250. return 1;
  251. }
  252. U_BOOT_CMD(
  253. iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
  254. "print header information for application image",
  255. "addr [addr ...]\n"
  256. " - print header information for application image starting at\n"
  257. " address 'addr' in memory; this includes verification of the\n"
  258. " image contents (magic number, header and payload checksums)"
  259. );
  260. #endif
  261. /*******************************************************************/
  262. /* imls - list all images found in flash */
  263. /*******************************************************************/
  264. #if defined(CONFIG_CMD_IMLS)
  265. static int do_imls_nor(void)
  266. {
  267. flash_info_t *info;
  268. int i, j;
  269. void *hdr;
  270. for (i = 0, info = &flash_info[0];
  271. i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
  272. if (info->flash_id == FLASH_UNKNOWN)
  273. goto next_bank;
  274. for (j = 0; j < info->sector_count; ++j) {
  275. hdr = (void *)info->start[j];
  276. if (!hdr)
  277. goto next_sector;
  278. switch (genimg_get_format(hdr)) {
  279. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  280. case IMAGE_FORMAT_LEGACY:
  281. if (!image_check_hcrc(hdr))
  282. goto next_sector;
  283. printf("Legacy Image at %08lX:\n", (ulong)hdr);
  284. image_print_contents(hdr);
  285. puts(" Verifying Checksum ... ");
  286. if (!image_check_dcrc(hdr)) {
  287. puts("Bad Data CRC\n");
  288. } else {
  289. puts("OK\n");
  290. }
  291. break;
  292. #endif
  293. #if defined(CONFIG_FIT)
  294. case IMAGE_FORMAT_FIT:
  295. if (!fit_check_format(hdr))
  296. goto next_sector;
  297. printf("FIT Image at %08lX:\n", (ulong)hdr);
  298. fit_print_contents(hdr);
  299. break;
  300. #endif
  301. default:
  302. goto next_sector;
  303. }
  304. next_sector: ;
  305. }
  306. next_bank: ;
  307. }
  308. return 0;
  309. }
  310. #endif
  311. #if defined(CONFIG_CMD_IMLS_NAND)
  312. static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
  313. size_t len)
  314. {
  315. void *imgdata;
  316. int ret;
  317. imgdata = malloc(len);
  318. if (!imgdata) {
  319. printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
  320. nand_dev, off);
  321. printf(" Low memory(cannot allocate memory for image)\n");
  322. return -ENOMEM;
  323. }
  324. ret = nand_read_skip_bad(nand, off, &len,
  325. imgdata);
  326. if (ret < 0 && ret != -EUCLEAN) {
  327. free(imgdata);
  328. return ret;
  329. }
  330. if (!image_check_hcrc(imgdata)) {
  331. free(imgdata);
  332. return 0;
  333. }
  334. printf("Legacy Image at NAND device %d offset %08llX:\n",
  335. nand_dev, off);
  336. image_print_contents(imgdata);
  337. puts(" Verifying Checksum ... ");
  338. if (!image_check_dcrc(imgdata))
  339. puts("Bad Data CRC\n");
  340. else
  341. puts("OK\n");
  342. free(imgdata);
  343. return 0;
  344. }
  345. static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
  346. size_t len)
  347. {
  348. void *imgdata;
  349. int ret;
  350. imgdata = malloc(len);
  351. if (!imgdata) {
  352. printf("May be a FIT Image at NAND device %d offset %08llX:\n",
  353. nand_dev, off);
  354. printf(" Low memory(cannot allocate memory for image)\n");
  355. return -ENOMEM;
  356. }
  357. ret = nand_read_skip_bad(nand, off, &len,
  358. imgdata);
  359. if (ret < 0 && ret != -EUCLEAN) {
  360. free(imgdata);
  361. return ret;
  362. }
  363. if (!fit_check_format(imgdata)) {
  364. free(imgdata);
  365. return 0;
  366. }
  367. printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
  368. fit_print_contents(imgdata);
  369. free(imgdata);
  370. return 0;
  371. }
  372. static int do_imls_nand(void)
  373. {
  374. nand_info_t *nand;
  375. int nand_dev = nand_curr_device;
  376. size_t len;
  377. loff_t off;
  378. u32 buffer[16];
  379. if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
  380. puts("\nNo NAND devices available\n");
  381. return -ENODEV;
  382. }
  383. printf("\n");
  384. for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
  385. nand = &nand_info[nand_dev];
  386. if (!nand->name || !nand->size)
  387. continue;
  388. for (off = 0; off < nand->size; off += nand->erasesize) {
  389. const image_header_t *header;
  390. int ret;
  391. if (nand_block_isbad(nand, off))
  392. continue;
  393. len = sizeof(buffer);
  394. ret = nand_read(nand, off, &len, (u8 *)buffer);
  395. if (ret < 0 && ret != -EUCLEAN) {
  396. printf("NAND read error %d at offset %08llX\n",
  397. ret, off);
  398. continue;
  399. }
  400. switch (genimg_get_format(buffer)) {
  401. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  402. case IMAGE_FORMAT_LEGACY:
  403. header = (const image_header_t *)buffer;
  404. len = image_get_image_size(header);
  405. nand_imls_legacyimage(nand, nand_dev, off, len);
  406. break;
  407. #endif
  408. #if defined(CONFIG_FIT)
  409. case IMAGE_FORMAT_FIT:
  410. len = fit_get_size(buffer);
  411. nand_imls_fitimage(nand, nand_dev, off, len);
  412. break;
  413. #endif
  414. }
  415. }
  416. }
  417. return 0;
  418. }
  419. #endif
  420. #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
  421. static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  422. {
  423. int ret_nor = 0, ret_nand = 0;
  424. #if defined(CONFIG_CMD_IMLS)
  425. ret_nor = do_imls_nor();
  426. #endif
  427. #if defined(CONFIG_CMD_IMLS_NAND)
  428. ret_nand = do_imls_nand();
  429. #endif
  430. if (ret_nor)
  431. return ret_nor;
  432. if (ret_nand)
  433. return ret_nand;
  434. return (0);
  435. }
  436. U_BOOT_CMD(
  437. imls, 1, 1, do_imls,
  438. "list all images found in flash",
  439. "\n"
  440. " - Prints information about all images found at sector/block\n"
  441. " boundaries in nor/nand flash."
  442. );
  443. #endif
  444. #ifdef CONFIG_CMD_BOOTZ
  445. int __weak bootz_setup(ulong image, ulong *start, ulong *end)
  446. {
  447. /* Please define bootz_setup() for your platform */
  448. puts("Your platform's zImage format isn't supported yet!\n");
  449. return -1;
  450. }
  451. /*
  452. * zImage booting support
  453. */
  454. static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
  455. char * const argv[], bootm_headers_t *images)
  456. {
  457. int ret;
  458. ulong zi_start, zi_end;
  459. ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
  460. images, 1);
  461. /* Setup Linux kernel zImage entry point */
  462. if (!argc) {
  463. images->ep = load_addr;
  464. debug("* kernel: default image load address = 0x%08lx\n",
  465. load_addr);
  466. } else {
  467. images->ep = simple_strtoul(argv[0], NULL, 16);
  468. debug("* kernel: cmdline image address = 0x%08lx\n",
  469. images->ep);
  470. }
  471. ret = bootz_setup(images->ep, &zi_start, &zi_end);
  472. if (ret != 0)
  473. return 1;
  474. lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
  475. /*
  476. * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
  477. * have a header that provide this informaiton.
  478. */
  479. if (bootm_find_ramdisk_fdt(flag, argc, argv))
  480. return 1;
  481. return 0;
  482. }
  483. int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  484. {
  485. int ret;
  486. /* Consume 'bootz' */
  487. argc--; argv++;
  488. if (bootz_start(cmdtp, flag, argc, argv, &images))
  489. return 1;
  490. /*
  491. * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
  492. * disable interrupts ourselves
  493. */
  494. bootm_disable_interrupts();
  495. images.os.os = IH_OS_LINUX;
  496. ret = do_bootm_states(cmdtp, flag, argc, argv,
  497. BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  498. BOOTM_STATE_OS_GO,
  499. &images, 1);
  500. return ret;
  501. }
  502. #ifdef CONFIG_SYS_LONGHELP
  503. static char bootz_help_text[] =
  504. "[addr [initrd[:size]] [fdt]]\n"
  505. " - boot Linux zImage stored in memory\n"
  506. "\tThe argument 'initrd' is optional and specifies the address\n"
  507. "\tof the initrd in memory. The optional argument ':size' allows\n"
  508. "\tspecifying the size of RAW initrd.\n"
  509. #if defined(CONFIG_OF_LIBFDT)
  510. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  511. "\ta third argument is required which is the address of the\n"
  512. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  513. "\tuse a '-' for the second argument. If you do not pass a third\n"
  514. "\ta bd_info struct will be passed instead\n"
  515. #endif
  516. "";
  517. #endif
  518. U_BOOT_CMD(
  519. bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
  520. "boot Linux zImage image from memory", bootz_help_text
  521. );
  522. #endif /* CONFIG_CMD_BOOTZ */
  523. #ifdef CONFIG_CMD_BOOTI
  524. /* See Documentation/arm64/booting.txt in the Linux kernel */
  525. struct Image_header {
  526. uint32_t code0; /* Executable code */
  527. uint32_t code1; /* Executable code */
  528. uint64_t text_offset; /* Image load offset, LE */
  529. uint64_t image_size; /* Effective Image size, LE */
  530. uint64_t res1; /* reserved */
  531. uint64_t res2; /* reserved */
  532. uint64_t res3; /* reserved */
  533. uint64_t res4; /* reserved */
  534. uint32_t magic; /* Magic number */
  535. uint32_t res5;
  536. };
  537. #define LINUX_ARM64_IMAGE_MAGIC 0x644d5241
  538. static int booti_setup(bootm_headers_t *images)
  539. {
  540. struct Image_header *ih;
  541. uint64_t dst;
  542. ih = (struct Image_header *)map_sysmem(images->ep, 0);
  543. if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) {
  544. puts("Bad Linux ARM64 Image magic!\n");
  545. return 1;
  546. }
  547. if (ih->image_size == 0) {
  548. puts("Image lacks image_size field, assuming 16MiB\n");
  549. ih->image_size = (16 << 20);
  550. }
  551. /*
  552. * If we are not at the correct run-time location, set the new
  553. * correct location and then move the image there.
  554. */
  555. dst = gd->bd->bi_dram[0].start + le32_to_cpu(ih->text_offset);
  556. if (images->ep != dst) {
  557. void *src;
  558. debug("Moving Image from 0x%lx to 0x%llx\n", images->ep, dst);
  559. src = (void *)images->ep;
  560. images->ep = dst;
  561. memmove((void *)dst, src, le32_to_cpu(ih->image_size));
  562. }
  563. return 0;
  564. }
  565. /*
  566. * Image booting support
  567. */
  568. static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
  569. char * const argv[], bootm_headers_t *images)
  570. {
  571. int ret;
  572. struct Image_header *ih;
  573. ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
  574. images, 1);
  575. /* Setup Linux kernel Image entry point */
  576. if (!argc) {
  577. images->ep = load_addr;
  578. debug("* kernel: default image load address = 0x%08lx\n",
  579. load_addr);
  580. } else {
  581. images->ep = simple_strtoul(argv[0], NULL, 16);
  582. debug("* kernel: cmdline image address = 0x%08lx\n",
  583. images->ep);
  584. }
  585. ret = booti_setup(images);
  586. if (ret != 0)
  587. return 1;
  588. ih = (struct Image_header *)map_sysmem(images->ep, 0);
  589. lmb_reserve(&images->lmb, images->ep, le32_to_cpu(ih->image_size));
  590. /*
  591. * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
  592. * have a header that provide this informaiton.
  593. */
  594. if (bootm_find_ramdisk_fdt(flag, argc, argv))
  595. return 1;
  596. return 0;
  597. }
  598. int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  599. {
  600. int ret;
  601. /* Consume 'booti' */
  602. argc--; argv++;
  603. if (booti_start(cmdtp, flag, argc, argv, &images))
  604. return 1;
  605. /*
  606. * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
  607. * disable interrupts ourselves
  608. */
  609. bootm_disable_interrupts();
  610. images.os.os = IH_OS_LINUX;
  611. ret = do_bootm_states(cmdtp, flag, argc, argv,
  612. BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  613. BOOTM_STATE_OS_GO,
  614. &images, 1);
  615. return ret;
  616. }
  617. #ifdef CONFIG_SYS_LONGHELP
  618. static char booti_help_text[] =
  619. "[addr [initrd[:size]] [fdt]]\n"
  620. " - boot Linux Image stored in memory\n"
  621. "\tThe argument 'initrd' is optional and specifies the address\n"
  622. "\tof the initrd in memory. The optional argument ':size' allows\n"
  623. "\tspecifying the size of RAW initrd.\n"
  624. #if defined(CONFIG_OF_LIBFDT)
  625. "\tSince booting a Linux kernelrequires a flat device-tree\n"
  626. "\ta third argument is required which is the address of the\n"
  627. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  628. "\tuse a '-' for the second argument.\n"
  629. #endif
  630. "";
  631. #endif
  632. U_BOOT_CMD(
  633. booti, CONFIG_SYS_MAXARGS, 1, do_booti,
  634. "boot arm64 Linux Image image from memory", booti_help_text
  635. );
  636. #endif /* CONFIG_CMD_BOOTI */