xref: /openbmc/u-boot/cmd/booti.c (revision 6808ef9a)
15db28905STom Rini /*
25db28905STom Rini  * (C) Copyright 2000-2009
35db28905STom Rini  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
45db28905STom Rini  *
55db28905STom Rini  * SPDX-License-Identifier:	GPL-2.0+
65db28905STom Rini  */
75db28905STom Rini 
85db28905STom Rini #include <common.h>
95db28905STom Rini #include <bootm.h>
105db28905STom Rini #include <command.h>
115db28905STom Rini #include <image.h>
125db28905STom Rini #include <lmb.h>
135db28905STom Rini #include <mapmem.h>
1428085764SMasahiro Yamada #include <linux/kernel.h>
1528085764SMasahiro Yamada #include <linux/sizes.h>
165db28905STom Rini 
175db28905STom Rini DECLARE_GLOBAL_DATA_PTR;
185db28905STom Rini 
195db28905STom Rini /*
205db28905STom Rini  * Image booting support
215db28905STom Rini  */
225db28905STom Rini static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
235db28905STom Rini 			char * const argv[], bootm_headers_t *images)
245db28905STom Rini {
255db28905STom Rini 	int ret;
26*6808ef9aSBin Chen 	ulong ld;
27*6808ef9aSBin Chen 	ulong relocated_addr;
28*6808ef9aSBin Chen 	ulong image_size;
295db28905STom Rini 
305db28905STom Rini 	ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
315db28905STom Rini 			      images, 1);
325db28905STom Rini 
335db28905STom Rini 	/* Setup Linux kernel Image entry point */
345db28905STom Rini 	if (!argc) {
35*6808ef9aSBin Chen 		ld = load_addr;
365db28905STom Rini 		debug("*  kernel: default image load address = 0x%08lx\n",
375db28905STom Rini 				load_addr);
385db28905STom Rini 	} else {
39*6808ef9aSBin Chen 		ld = simple_strtoul(argv[0], NULL, 16);
405db28905STom Rini 		debug("*  kernel: cmdline image address = 0x%08lx\n",
415db28905STom Rini 			images->ep);
425db28905STom Rini 	}
435db28905STom Rini 
44*6808ef9aSBin Chen 	ret = booti_setup(ld, &relocated_addr, &image_size);
455db28905STom Rini 	if (ret != 0)
465db28905STom Rini 		return 1;
475db28905STom Rini 
48*6808ef9aSBin Chen 	/* Handle BOOTM_STATE_LOADOS */
49*6808ef9aSBin Chen 	if (relocated_addr != ld) {
50*6808ef9aSBin Chen 		debug("Moving Image from 0x%lx to 0x%lx\n", ld, relocated_addr);
51*6808ef9aSBin Chen 		memmove((void *)relocated_addr, (void *)ld, image_size);
52*6808ef9aSBin Chen 	}
535db28905STom Rini 
54*6808ef9aSBin Chen 	images->ep = relocated_addr;
55*6808ef9aSBin Chen 	lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size));
565db28905STom Rini 
575db28905STom Rini 	/*
585db28905STom Rini 	 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
595db28905STom Rini 	 * have a header that provide this informaiton.
605db28905STom Rini 	 */
615db28905STom Rini 	if (bootm_find_images(flag, argc, argv))
625db28905STom Rini 		return 1;
635db28905STom Rini 
645db28905STom Rini 	return 0;
655db28905STom Rini }
665db28905STom Rini 
675db28905STom Rini int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
685db28905STom Rini {
695db28905STom Rini 	int ret;
705db28905STom Rini 
715db28905STom Rini 	/* Consume 'booti' */
725db28905STom Rini 	argc--; argv++;
735db28905STom Rini 
745db28905STom Rini 	if (booti_start(cmdtp, flag, argc, argv, &images))
755db28905STom Rini 		return 1;
765db28905STom Rini 
775db28905STom Rini 	/*
785db28905STom Rini 	 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
795db28905STom Rini 	 * disable interrupts ourselves
805db28905STom Rini 	 */
815db28905STom Rini 	bootm_disable_interrupts();
825db28905STom Rini 
835db28905STom Rini 	images.os.os = IH_OS_LINUX;
840fff19a6SScott Wood 	images.os.arch = IH_ARCH_ARM64;
855db28905STom Rini 	ret = do_bootm_states(cmdtp, flag, argc, argv,
864943dc2fSCédric Schieli #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
874943dc2fSCédric Schieli 			      BOOTM_STATE_RAMDISK |
884943dc2fSCédric Schieli #endif
895db28905STom Rini 			      BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
905db28905STom Rini 			      BOOTM_STATE_OS_GO,
915db28905STom Rini 			      &images, 1);
925db28905STom Rini 
935db28905STom Rini 	return ret;
945db28905STom Rini }
955db28905STom Rini 
965db28905STom Rini #ifdef CONFIG_SYS_LONGHELP
975db28905STom Rini static char booti_help_text[] =
985db28905STom Rini 	"[addr [initrd[:size]] [fdt]]\n"
995db28905STom Rini 	"    - boot arm64 Linux Image stored in memory\n"
1005db28905STom Rini 	"\tThe argument 'initrd' is optional and specifies the address\n"
1015db28905STom Rini 	"\tof an initrd in memory. The optional parameter ':size' allows\n"
1025db28905STom Rini 	"\tspecifying the size of a RAW initrd.\n"
1035db28905STom Rini #if defined(CONFIG_OF_LIBFDT)
1045db28905STom Rini 	"\tSince booting a Linux kernel requires a flat device-tree, a\n"
1055db28905STom Rini 	"\tthird argument providing the address of the device-tree blob\n"
1065db28905STom Rini 	"\tis required. To boot a kernel with a device-tree blob but\n"
1075db28905STom Rini 	"\twithout an initrd image, use a '-' for the initrd argument.\n"
1085db28905STom Rini #endif
1095db28905STom Rini 	"";
1105db28905STom Rini #endif
1115db28905STom Rini 
1125db28905STom Rini U_BOOT_CMD(
1135db28905STom Rini 	booti,	CONFIG_SYS_MAXARGS,	1,	do_booti,
1145db28905STom Rini 	"boot arm64 Linux Image image from memory", booti_help_text
1155db28905STom Rini );
116