xref: /openbmc/u-boot/cmd/bootz.c (revision 2502bfc4)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
25db28905STom Rini /*
35db28905STom Rini  * (C) Copyright 2000-2009
45db28905STom Rini  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
55db28905STom Rini  */
65db28905STom Rini 
75db28905STom Rini #include <common.h>
85db28905STom Rini #include <bootm.h>
95db28905STom Rini #include <command.h>
105db28905STom Rini #include <lmb.h>
115db28905STom Rini #include <linux/compiler.h>
125db28905STom Rini 
bootz_setup(ulong image,ulong * start,ulong * end)135db28905STom Rini int __weak bootz_setup(ulong image, ulong *start, ulong *end)
145db28905STom Rini {
155db28905STom Rini 	/* Please define bootz_setup() for your platform */
165db28905STom Rini 
175db28905STom Rini 	puts("Your platform's zImage format isn't supported yet!\n");
185db28905STom Rini 	return -1;
195db28905STom Rini }
205db28905STom Rini 
215db28905STom Rini /*
225db28905STom Rini  * zImage booting support
235db28905STom Rini  */
bootz_start(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[],bootm_headers_t * images)245db28905STom Rini static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
255db28905STom Rini 			char * const argv[], bootm_headers_t *images)
265db28905STom Rini {
275db28905STom Rini 	int ret;
285db28905STom Rini 	ulong zi_start, zi_end;
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 zImage entry point */
345db28905STom Rini 	if (!argc) {
355db28905STom Rini 		images->ep = load_addr;
365db28905STom Rini 		debug("*  kernel: default image load address = 0x%08lx\n",
375db28905STom Rini 				load_addr);
385db28905STom Rini 	} else {
395db28905STom Rini 		images->ep = simple_strtoul(argv[0], NULL, 16);
405db28905STom Rini 		debug("*  kernel: cmdline image address = 0x%08lx\n",
415db28905STom Rini 			images->ep);
425db28905STom Rini 	}
435db28905STom Rini 
445db28905STom Rini 	ret = bootz_setup(images->ep, &zi_start, &zi_end);
455db28905STom Rini 	if (ret != 0)
465db28905STom Rini 		return 1;
475db28905STom Rini 
485db28905STom Rini 	lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
495db28905STom Rini 
505db28905STom Rini 	/*
515db28905STom Rini 	 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
525db28905STom Rini 	 * have a header that provide this informaiton.
535db28905STom Rini 	 */
545db28905STom Rini 	if (bootm_find_images(flag, argc, argv))
555db28905STom Rini 		return 1;
565db28905STom Rini 
575db28905STom Rini 	return 0;
585db28905STom Rini }
595db28905STom Rini 
do_bootz(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])605db28905STom Rini int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
615db28905STom Rini {
625db28905STom Rini 	int ret;
635db28905STom Rini 
645db28905STom Rini 	/* Consume 'bootz' */
655db28905STom Rini 	argc--; argv++;
665db28905STom Rini 
675db28905STom Rini 	if (bootz_start(cmdtp, flag, argc, argv, &images))
685db28905STom Rini 		return 1;
695db28905STom Rini 
705db28905STom Rini 	/*
715db28905STom Rini 	 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
725db28905STom Rini 	 * disable interrupts ourselves
735db28905STom Rini 	 */
745db28905STom Rini 	bootm_disable_interrupts();
755db28905STom Rini 
765db28905STom Rini 	images.os.os = IH_OS_LINUX;
775db28905STom Rini 	ret = do_bootm_states(cmdtp, flag, argc, argv,
784943dc2fSCédric Schieli #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
794943dc2fSCédric Schieli 			      BOOTM_STATE_RAMDISK |
804943dc2fSCédric Schieli #endif
81*2502bfc4SEddie James 			      BOOTM_STATE_MEASURE |
825db28905STom Rini 			      BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
835db28905STom Rini 			      BOOTM_STATE_OS_GO,
845db28905STom Rini 			      &images, 1);
855db28905STom Rini 
865db28905STom Rini 	return ret;
875db28905STom Rini }
885db28905STom Rini 
895db28905STom Rini #ifdef CONFIG_SYS_LONGHELP
905db28905STom Rini static char bootz_help_text[] =
915db28905STom Rini 	"[addr [initrd[:size]] [fdt]]\n"
925db28905STom Rini 	"    - boot Linux zImage stored in memory\n"
935db28905STom Rini 	"\tThe argument 'initrd' is optional and specifies the address\n"
945db28905STom Rini 	"\tof the initrd in memory. The optional argument ':size' allows\n"
955db28905STom Rini 	"\tspecifying the size of RAW initrd.\n"
965db28905STom Rini #if defined(CONFIG_OF_LIBFDT)
975db28905STom Rini 	"\tWhen booting a Linux kernel which requires a flat device-tree\n"
985db28905STom Rini 	"\ta third argument is required which is the address of the\n"
995db28905STom Rini 	"\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1005db28905STom Rini 	"\tuse a '-' for the second argument. If you do not pass a third\n"
1015db28905STom Rini 	"\ta bd_info struct will be passed instead\n"
1025db28905STom Rini #endif
1035db28905STom Rini 	"";
1045db28905STom Rini #endif
1055db28905STom Rini 
1065db28905STom Rini U_BOOT_CMD(
1075db28905STom Rini 	bootz,	CONFIG_SYS_MAXARGS,	1,	do_bootz,
1085db28905STom Rini 	"boot Linux zImage image from memory", bootz_help_text
1095db28905STom Rini );
110