1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * (C) Copyright 2000-2009
3*4882a593Smuzhiyun * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <common.h>
9*4882a593Smuzhiyun #include <bootm.h>
10*4882a593Smuzhiyun #include <command.h>
11*4882a593Smuzhiyun #include <lmb.h>
12*4882a593Smuzhiyun #include <linux/compiler.h>
13*4882a593Smuzhiyun
bootz_setup(ulong image,ulong * start,ulong * end)14*4882a593Smuzhiyun int __weak bootz_setup(ulong image, ulong *start, ulong *end)
15*4882a593Smuzhiyun {
16*4882a593Smuzhiyun /* Please define bootz_setup() for your platform */
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun puts("Your platform's zImage format isn't supported yet!\n");
19*4882a593Smuzhiyun return -1;
20*4882a593Smuzhiyun }
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun /*
23*4882a593Smuzhiyun * zImage booting support
24*4882a593Smuzhiyun */
bootz_start(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[],bootm_headers_t * images)25*4882a593Smuzhiyun static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
26*4882a593Smuzhiyun char * const argv[], bootm_headers_t *images)
27*4882a593Smuzhiyun {
28*4882a593Smuzhiyun int ret;
29*4882a593Smuzhiyun ulong zi_start, zi_end;
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
32*4882a593Smuzhiyun images, 1);
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun /* Setup Linux kernel zImage entry point */
35*4882a593Smuzhiyun if (!argc) {
36*4882a593Smuzhiyun images->ep = load_addr;
37*4882a593Smuzhiyun debug("* kernel: default image load address = 0x%08lx\n",
38*4882a593Smuzhiyun load_addr);
39*4882a593Smuzhiyun } else {
40*4882a593Smuzhiyun images->ep = simple_strtoul(argv[0], NULL, 16);
41*4882a593Smuzhiyun debug("* kernel: cmdline image address = 0x%08lx\n",
42*4882a593Smuzhiyun images->ep);
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun ret = bootz_setup(images->ep, &zi_start, &zi_end);
46*4882a593Smuzhiyun if (ret != 0)
47*4882a593Smuzhiyun return 1;
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun /*
52*4882a593Smuzhiyun * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
53*4882a593Smuzhiyun * have a header that provide this informaiton.
54*4882a593Smuzhiyun */
55*4882a593Smuzhiyun if (bootm_find_images(flag, argc, argv))
56*4882a593Smuzhiyun return 1;
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun return 0;
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun
do_bootz(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])61*4882a593Smuzhiyun int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun int ret;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /* Consume 'bootz' */
66*4882a593Smuzhiyun argc--; argv++;
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun if (bootz_start(cmdtp, flag, argc, argv, &images))
69*4882a593Smuzhiyun return 1;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun /*
72*4882a593Smuzhiyun * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
73*4882a593Smuzhiyun * disable interrupts ourselves
74*4882a593Smuzhiyun */
75*4882a593Smuzhiyun bootm_disable_interrupts();
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun images.os.os = IH_OS_LINUX;
78*4882a593Smuzhiyun ret = do_bootm_states(cmdtp, flag, argc, argv,
79*4882a593Smuzhiyun #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
80*4882a593Smuzhiyun BOOTM_STATE_RAMDISK |
81*4882a593Smuzhiyun #endif
82*4882a593Smuzhiyun BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
83*4882a593Smuzhiyun BOOTM_STATE_OS_GO,
84*4882a593Smuzhiyun &images, 1);
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun return ret;
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun #ifdef CONFIG_SYS_LONGHELP
90*4882a593Smuzhiyun static char bootz_help_text[] =
91*4882a593Smuzhiyun "[addr [initrd[:size]] [fdt]]\n"
92*4882a593Smuzhiyun " - boot Linux zImage stored in memory\n"
93*4882a593Smuzhiyun "\tThe argument 'initrd' is optional and specifies the address\n"
94*4882a593Smuzhiyun "\tof the initrd in memory. The optional argument ':size' allows\n"
95*4882a593Smuzhiyun "\tspecifying the size of RAW initrd.\n"
96*4882a593Smuzhiyun #if defined(CONFIG_OF_LIBFDT)
97*4882a593Smuzhiyun "\tWhen booting a Linux kernel which requires a flat device-tree\n"
98*4882a593Smuzhiyun "\ta third argument is required which is the address of the\n"
99*4882a593Smuzhiyun "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
100*4882a593Smuzhiyun "\tuse a '-' for the second argument. If you do not pass a third\n"
101*4882a593Smuzhiyun "\ta bd_info struct will be passed instead\n"
102*4882a593Smuzhiyun #endif
103*4882a593Smuzhiyun "";
104*4882a593Smuzhiyun #endif
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun U_BOOT_CMD(
107*4882a593Smuzhiyun bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
108*4882a593Smuzhiyun "boot Linux zImage image from memory", bootz_help_text
109*4882a593Smuzhiyun );
110