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