xref: /rk3399_rockchip-uboot/cmd/bootz.c (revision 4943dc2f1977cf89297b87f93f96ad4d7f09d24d)
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 <lmb.h>
125db28905STom Rini #include <linux/compiler.h>
135db28905STom Rini 
bootz_setup(ulong image,ulong * start,ulong * end)145db28905STom Rini int __weak bootz_setup(ulong image, ulong *start, ulong *end)
155db28905STom Rini {
165db28905STom Rini 	/* Please define bootz_setup() for your platform */
175db28905STom Rini 
185db28905STom Rini 	puts("Your platform's zImage format isn't supported yet!\n");
195db28905STom Rini 	return -1;
205db28905STom Rini }
215db28905STom Rini 
225db28905STom Rini /*
235db28905STom Rini  * zImage booting support
245db28905STom Rini  */
bootz_start(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[],bootm_headers_t * images)255db28905STom Rini static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
265db28905STom Rini 			char * const argv[], bootm_headers_t *images)
275db28905STom Rini {
285db28905STom Rini 	int ret;
295db28905STom Rini 	ulong zi_start, zi_end;
305db28905STom Rini 
315db28905STom Rini 	ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
325db28905STom Rini 			      images, 1);
335db28905STom Rini 
345db28905STom Rini 	/* Setup Linux kernel zImage entry point */
355db28905STom Rini 	if (!argc) {
365db28905STom Rini 		images->ep = load_addr;
375db28905STom Rini 		debug("*  kernel: default image load address = 0x%08lx\n",
385db28905STom Rini 				load_addr);
395db28905STom Rini 	} else {
405db28905STom Rini 		images->ep = simple_strtoul(argv[0], NULL, 16);
415db28905STom Rini 		debug("*  kernel: cmdline image address = 0x%08lx\n",
425db28905STom Rini 			images->ep);
435db28905STom Rini 	}
445db28905STom Rini 
455db28905STom Rini 	ret = bootz_setup(images->ep, &zi_start, &zi_end);
465db28905STom Rini 	if (ret != 0)
475db28905STom Rini 		return 1;
485db28905STom Rini 
495db28905STom Rini 	lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
505db28905STom Rini 
515db28905STom Rini 	/*
525db28905STom Rini 	 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
535db28905STom Rini 	 * have a header that provide this informaiton.
545db28905STom Rini 	 */
555db28905STom Rini 	if (bootm_find_images(flag, argc, argv))
565db28905STom Rini 		return 1;
575db28905STom Rini 
585db28905STom Rini 	return 0;
595db28905STom Rini }
605db28905STom Rini 
do_bootz(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])615db28905STom Rini int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
625db28905STom Rini {
635db28905STom Rini 	int ret;
645db28905STom Rini 
655db28905STom Rini 	/* Consume 'bootz' */
665db28905STom Rini 	argc--; argv++;
675db28905STom Rini 
685db28905STom Rini 	if (bootz_start(cmdtp, flag, argc, argv, &images))
695db28905STom Rini 		return 1;
705db28905STom Rini 
715db28905STom Rini 	/*
725db28905STom Rini 	 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
735db28905STom Rini 	 * disable interrupts ourselves
745db28905STom Rini 	 */
755db28905STom Rini 	bootm_disable_interrupts();
765db28905STom Rini 
775db28905STom Rini 	images.os.os = IH_OS_LINUX;
785db28905STom Rini 	ret = do_bootm_states(cmdtp, flag, argc, argv,
79*4943dc2fSCédric Schieli #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
80*4943dc2fSCédric Schieli 			      BOOTM_STATE_RAMDISK |
81*4943dc2fSCédric Schieli #endif
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