blob: 8c25905598a815962103d96b951c440099f9e258 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Rini36f067f2016-08-12 08:31:15 -04002/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Tom Rini36f067f2016-08-12 08:31:15 -04005 */
6
7#include <common.h>
8#include <bootm.h>
9#include <command.h>
Simon Glass85f13782019-12-28 10:45:03 -070010#include <image.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070011#include <irq_func.h>
Tom Rini36f067f2016-08-12 08:31:15 -040012#include <lmb.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Tom Rini36f067f2016-08-12 08:31:15 -040014#include <linux/compiler.h>
15
16int __weak bootz_setup(ulong image, ulong *start, ulong *end)
17{
18 /* Please define bootz_setup() for your platform */
19
20 puts("Your platform's zImage format isn't supported yet!\n");
21 return -1;
22}
23
24/*
25 * zImage booting support
26 */
Simon Glassed38aef2020-05-10 11:40:03 -060027static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glassdf00afa2022-09-06 20:26:50 -060028 char *const argv[], struct bootm_headers *images)
Tom Rini36f067f2016-08-12 08:31:15 -040029{
30 int ret;
31 ulong zi_start, zi_end;
32
33 ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
34 images, 1);
35
36 /* Setup Linux kernel zImage entry point */
37 if (!argc) {
Simon Glass892265d2019-12-28 10:45:02 -070038 images->ep = image_load_addr;
Tom Rini36f067f2016-08-12 08:31:15 -040039 debug("* kernel: default image load address = 0x%08lx\n",
Simon Glass892265d2019-12-28 10:45:02 -070040 image_load_addr);
Tom Rini36f067f2016-08-12 08:31:15 -040041 } else {
Simon Glass3ff49ec2021-07-24 09:03:29 -060042 images->ep = hextoul(argv[0], NULL);
Tom Rini36f067f2016-08-12 08:31:15 -040043 debug("* kernel: cmdline image address = 0x%08lx\n",
44 images->ep);
45 }
46
47 ret = bootz_setup(images->ep, &zi_start, &zi_end);
48 if (ret != 0)
49 return 1;
50
51 lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
52
53 /*
54 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
55 * have a header that provide this informaiton.
56 */
Simon Glass793a98e2023-11-18 14:05:20 -070057 if (bootm_find_images(image_load_addr, cmd_arg1(argc, argv),
58 cmd_arg2(argc, argv), images->ep,
Simon Glassd46c81e2023-11-18 14:05:16 -070059 zi_end - zi_start))
Tom Rini36f067f2016-08-12 08:31:15 -040060 return 1;
61
62 return 0;
63}
64
Simon Glassed38aef2020-05-10 11:40:03 -060065int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Tom Rini36f067f2016-08-12 08:31:15 -040066{
Simon Glass5fb0d142023-12-15 20:14:17 -070067 int states, ret;
Tom Rini36f067f2016-08-12 08:31:15 -040068
69 /* Consume 'bootz' */
70 argc--; argv++;
71
72 if (bootz_start(cmdtp, flag, argc, argv, &images))
73 return 1;
74
75 /*
76 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
77 * disable interrupts ourselves
78 */
79 bootm_disable_interrupts();
80
81 images.os.os = IH_OS_LINUX;
Simon Glass5fb0d142023-12-15 20:14:17 -070082
83 states = BOOTM_STATE_MEASURE | BOOTM_STATE_OS_PREP |
84 BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO;
85 if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH))
86 states |= BOOTM_STATE_RAMDISK;
87
88 ret = do_bootm_states(cmdtp, flag, argc, argv, states, &images, 1);
Tom Rini36f067f2016-08-12 08:31:15 -040089
90 return ret;
91}
92
Tom Rini03f146c2023-10-07 15:13:08 -040093U_BOOT_LONGHELP(bootz,
Tom Rini36f067f2016-08-12 08:31:15 -040094 "[addr [initrd[:size]] [fdt]]\n"
95 " - boot Linux zImage stored in memory\n"
96 "\tThe argument 'initrd' is optional and specifies the address\n"
97 "\tof the initrd in memory. The optional argument ':size' allows\n"
98 "\tspecifying the size of RAW initrd.\n"
99#if defined(CONFIG_OF_LIBFDT)
100 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
101 "\ta third argument is required which is the address of the\n"
102 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
103 "\tuse a '-' for the second argument. If you do not pass a third\n"
104 "\ta bd_info struct will be passed instead\n"
105#endif
Tom Rini03f146c2023-10-07 15:13:08 -0400106 );
Tom Rini36f067f2016-08-12 08:31:15 -0400107
108U_BOOT_CMD(
109 bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
110 "boot Linux zImage image from memory", bootz_help_text
111);