blob: 44af7d012aa0c9dcc43e995523ad714309484896 [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
Tom Rini36f067f2016-08-12 08:31:15 -04007#include <bootm.h>
8#include <command.h>
Simon Glass85f13782019-12-28 10:45:03 -07009#include <image.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070010#include <irq_func.h>
Tom Rini36f067f2016-08-12 08:31:15 -040011#include <lmb.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Tom Rini36f067f2016-08-12 08:31:15 -040013#include <linux/compiler.h>
14
15int __weak bootz_setup(ulong image, ulong *start, ulong *end)
16{
17 /* Please define bootz_setup() for your platform */
18
19 puts("Your platform's zImage format isn't supported yet!\n");
20 return -1;
21}
22
23/*
24 * zImage booting support
25 */
Simon Glassed38aef2020-05-10 11:40:03 -060026static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc,
Simon Glassdf00afa2022-09-06 20:26:50 -060027 char *const argv[], struct bootm_headers *images)
Tom Rini36f067f2016-08-12 08:31:15 -040028{
Tom Rini36f067f2016-08-12 08:31:15 -040029 ulong zi_start, zi_end;
Simon Glass50fa2fe2023-12-15 20:14:18 -070030 struct bootm_info bmi;
Sughosh Ganu9b0765a2025-06-17 16:13:40 +053031 phys_addr_t ep_addr;
Simon Glass50fa2fe2023-12-15 20:14:18 -070032 int ret;
Tom Rini36f067f2016-08-12 08:31:15 -040033
Simon Glass50fa2fe2023-12-15 20:14:18 -070034 bootm_init(&bmi);
35 if (argc)
36 bmi.addr_img = argv[0];
37 if (argc > 1)
38 bmi.conf_ramdisk = argv[1];
39 if (argc > 2)
40 bmi.conf_fdt = argv[2];
41 /* do not set up argc and argv[] since nothing uses them */
42
Simon Glassd90f94f2023-12-15 20:14:19 -070043 ret = bootm_run_states(&bmi, BOOTM_STATE_START);
Tom Rini36f067f2016-08-12 08:31:15 -040044
45 /* Setup Linux kernel zImage entry point */
46 if (!argc) {
Simon Glass892265d2019-12-28 10:45:02 -070047 images->ep = image_load_addr;
Tom Rini36f067f2016-08-12 08:31:15 -040048 debug("* kernel: default image load address = 0x%08lx\n",
Simon Glass892265d2019-12-28 10:45:02 -070049 image_load_addr);
Tom Rini36f067f2016-08-12 08:31:15 -040050 } else {
Simon Glass3ff49ec2021-07-24 09:03:29 -060051 images->ep = hextoul(argv[0], NULL);
Tom Rini36f067f2016-08-12 08:31:15 -040052 debug("* kernel: cmdline image address = 0x%08lx\n",
53 images->ep);
54 }
55
56 ret = bootz_setup(images->ep, &zi_start, &zi_end);
57 if (ret != 0)
58 return 1;
59
Sughosh Ganu9b0765a2025-06-17 16:13:40 +053060 ep_addr = (phys_addr_t)images->ep;
61 ret = lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0, &ep_addr, zi_end - zi_start,
62 LMB_NONE);
63 if (ret) {
64 printf("Failed to allocate memory for the image at %#llx\n",
65 (unsigned long long)images->ep);
66 return 1;
67 }
Tom Rini36f067f2016-08-12 08:31:15 -040068
69 /*
70 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
71 * have a header that provide this informaiton.
72 */
Simon Glass793a98e2023-11-18 14:05:20 -070073 if (bootm_find_images(image_load_addr, cmd_arg1(argc, argv),
74 cmd_arg2(argc, argv), images->ep,
Simon Glassd46c81e2023-11-18 14:05:16 -070075 zi_end - zi_start))
Tom Rini36f067f2016-08-12 08:31:15 -040076 return 1;
77
78 return 0;
79}
80
Simon Glassed38aef2020-05-10 11:40:03 -060081int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Tom Rini36f067f2016-08-12 08:31:15 -040082{
Simon Glass50fa2fe2023-12-15 20:14:18 -070083 struct bootm_info bmi;
Simon Glasse176bb12023-12-15 20:14:23 -070084 int ret;
Tom Rini36f067f2016-08-12 08:31:15 -040085
86 /* Consume 'bootz' */
87 argc--; argv++;
88
89 if (bootz_start(cmdtp, flag, argc, argv, &images))
90 return 1;
91
92 /*
93 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
94 * disable interrupts ourselves
95 */
96 bootm_disable_interrupts();
97
98 images.os.os = IH_OS_LINUX;
Simon Glass5fb0d142023-12-15 20:14:17 -070099
Simon Glass50fa2fe2023-12-15 20:14:18 -0700100 bootm_init(&bmi);
101 if (argc)
102 bmi.addr_img = argv[0];
103 if (argc > 1)
104 bmi.conf_ramdisk = argv[1];
105 if (argc > 2)
106 bmi.conf_fdt = argv[2];
107 bmi.cmd_name = "bootz";
108
Simon Glasse176bb12023-12-15 20:14:23 -0700109 ret = bootz_run(&bmi);
Tom Rini36f067f2016-08-12 08:31:15 -0400110
111 return ret;
112}
113
Tom Rini03f146c2023-10-07 15:13:08 -0400114U_BOOT_LONGHELP(bootz,
Tom Rini36f067f2016-08-12 08:31:15 -0400115 "[addr [initrd[:size]] [fdt]]\n"
116 " - boot Linux zImage stored in memory\n"
117 "\tThe argument 'initrd' is optional and specifies the address\n"
118 "\tof the initrd in memory. The optional argument ':size' allows\n"
119 "\tspecifying the size of RAW initrd.\n"
120#if defined(CONFIG_OF_LIBFDT)
121 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
122 "\ta third argument is required which is the address of the\n"
123 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
124 "\tuse a '-' for the second argument. If you do not pass a third\n"
125 "\ta bd_info struct will be passed instead\n"
126#endif
Tom Rini03f146c2023-10-07 15:13:08 -0400127 );
Tom Rini36f067f2016-08-12 08:31:15 -0400128
129U_BOOT_CMD(
130 bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
131 "boot Linux zImage image from memory", bootz_help_text
132);