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