blob: 8e4aefa0606e4ba6d6ff8dfffd08406a277a0cb9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk591dda52002-11-18 00:14:45 +00002/*
Gabe Black1cf51212011-12-05 12:09:23 +00003 * Copyright (c) 2011 The Chromium OS Authors.
wdenk591dda52002-11-18 00:14:45 +00004 * (C) Copyright 2002
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02005 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk591dda52002-11-18 00:14:45 +00006 */
7
wdenk57b2d802003-06-27 21:31:46 +00008/*
Graeme Russ45fc1d82011-04-13 19:43:26 +10009 * Linux x86 zImage and bzImage loading
wdenk57b2d802003-06-27 21:31:46 +000010 *
11 * based on the procdure described in
wdenk591dda52002-11-18 00:14:45 +000012 * linux/Documentation/i386/boot.txt
13 */
14
15#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -060016#include <command.h>
Simon Glass83c2e492019-08-01 09:46:50 -060017#include <env.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070018#include <irq_func.h>
Ivan Gorinov901bb0b2018-03-26 18:06:54 -070019#include <malloc.h>
Simon Glass858fed12020-04-08 16:57:36 -060020#include <acpi/acpi_table.h>
wdenk591dda52002-11-18 00:14:45 +000021#include <asm/io.h>
22#include <asm/ptrace.h>
23#include <asm/zimage.h>
wdenk591dda52002-11-18 00:14:45 +000024#include <asm/byteorder.h>
Simon Glassaa83f2b2014-10-19 21:11:20 -060025#include <asm/bootm.h>
Graeme Russ1bab1042010-04-24 00:05:49 +100026#include <asm/bootparam.h>
Vadim Bendebury8cd22c82012-10-23 18:04:34 +000027#ifdef CONFIG_SYS_COREBOOT
28#include <asm/arch/timestamp.h>
29#endif
Stefan Reinauer2e5225e2012-10-23 18:04:37 +000030#include <linux/compiler.h>
Ivan Gorinov901bb0b2018-03-26 18:06:54 -070031#include <linux/libfdt.h>
wdenk591dda52002-11-18 00:14:45 +000032
33/*
34 * Memory lay-out:
wdenk57b2d802003-06-27 21:31:46 +000035 *
wdenk591dda52002-11-18 00:14:45 +000036 * relative to setup_base (which is 0x90000 currently)
wdenk57b2d802003-06-27 21:31:46 +000037 *
38 * 0x0000-0x7FFF Real mode kernel
wdenk591dda52002-11-18 00:14:45 +000039 * 0x8000-0x8FFF Stack and heap
40 * 0x9000-0x90FF Kernel command line
41 */
Graeme Russ883c6032011-11-08 02:33:15 +000042#define DEFAULT_SETUP_BASE 0x90000
43#define COMMAND_LINE_OFFSET 0x9000
44#define HEAP_END_OFFSET 0x8e00
wdenk591dda52002-11-18 00:14:45 +000045
Graeme Russ883c6032011-11-08 02:33:15 +000046#define COMMAND_LINE_SIZE 2048
wdenk591dda52002-11-18 00:14:45 +000047
Simon Glass48800f42020-09-05 14:50:38 -060048/**
49 * struct zboot_state - Current state of the boot
50 *
51 * @bzimage_addr: Address of the bzImage to boot
52 * @bzimage_size: Size of the bzImage, or 0 to detect this
53 * @initrd_addr: Address of the initial ramdisk, or 0 if none
54 * @initrd_size: Size of the initial ramdisk, or 0 if none
55 * @load_address: Address where the bzImage is moved before booting, either
56 * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
57 */
58struct zboot_state {
59 ulong bzimage_addr;
60 ulong bzimage_size;
61 ulong initrd_addr;
62 ulong initrd_size;
63 ulong load_address;
64} state;
65
Simon Glassd9b3c982020-09-05 14:50:43 -060066enum {
67 ZBOOT_STATE_START = BIT(0),
68
69 ZBOOT_STATE_COUNT = 1,
70};
71
wdenk591dda52002-11-18 00:14:45 +000072static void build_command_line(char *command_line, int auto_boot)
73{
74 char *env_command_line;
wdenk57b2d802003-06-27 21:31:46 +000075
wdenk591dda52002-11-18 00:14:45 +000076 command_line[0] = '\0';
wdenk57b2d802003-06-27 21:31:46 +000077
Simon Glass64b723f2017-08-03 12:22:12 -060078 env_command_line = env_get("bootargs");
wdenk57b2d802003-06-27 21:31:46 +000079
wdenk591dda52002-11-18 00:14:45 +000080 /* set console= argument if we use a serial console */
Graeme Russ883c6032011-11-08 02:33:15 +000081 if (!strstr(env_command_line, "console=")) {
Simon Glass64b723f2017-08-03 12:22:12 -060082 if (!strcmp(env_get("stdout"), "serial")) {
wdenk57b2d802003-06-27 21:31:46 +000083
wdenk591dda52002-11-18 00:14:45 +000084 /* We seem to use serial console */
wdenk57b2d802003-06-27 21:31:46 +000085 sprintf(command_line, "console=ttyS0,%s ",
Simon Glass64b723f2017-08-03 12:22:12 -060086 env_get("baudrate"));
wdenk591dda52002-11-18 00:14:45 +000087 }
88 }
wdenk57b2d802003-06-27 21:31:46 +000089
Graeme Russ883c6032011-11-08 02:33:15 +000090 if (auto_boot)
wdenk591dda52002-11-18 00:14:45 +000091 strcat(command_line, "auto ");
wdenk57b2d802003-06-27 21:31:46 +000092
Graeme Russ883c6032011-11-08 02:33:15 +000093 if (env_command_line)
wdenk591dda52002-11-18 00:14:45 +000094 strcat(command_line, env_command_line);
wdenk57b2d802003-06-27 21:31:46 +000095
wdenk591dda52002-11-18 00:14:45 +000096 printf("Kernel command line: \"%s\"\n", command_line);
97}
98
Gabe Black540c2622011-12-05 12:09:26 +000099static int kernel_magic_ok(struct setup_header *hdr)
wdenk591dda52002-11-18 00:14:45 +0000100{
Graeme Russ1bab1042010-04-24 00:05:49 +1000101 if (KERNEL_MAGIC != hdr->boot_flag) {
Gabe Black1cf51212011-12-05 12:09:23 +0000102 printf("Error: Invalid Boot Flag "
103 "(found 0x%04x, expected 0x%04x)\n",
104 hdr->boot_flag, KERNEL_MAGIC);
wdenk591dda52002-11-18 00:14:45 +0000105 return 0;
Graeme Russ1bab1042010-04-24 00:05:49 +1000106 } else {
107 printf("Valid Boot Flag\n");
Gabe Black540c2622011-12-05 12:09:26 +0000108 return 1;
wdenk591dda52002-11-18 00:14:45 +0000109 }
Gabe Black540c2622011-12-05 12:09:26 +0000110}
wdenk57b2d802003-06-27 21:31:46 +0000111
Simon Glassdf30d412020-09-05 14:50:40 -0600112static int get_boot_protocol(struct setup_header *hdr, bool verbose)
Gabe Black540c2622011-12-05 12:09:26 +0000113{
114 if (hdr->header == KERNEL_V2_MAGIC) {
Simon Glassdf30d412020-09-05 14:50:40 -0600115 if (verbose)
116 printf("Magic signature found\n");
Gabe Black540c2622011-12-05 12:09:26 +0000117 return hdr->version;
wdenk591dda52002-11-18 00:14:45 +0000118 } else {
119 /* Very old kernel */
Simon Glassdf30d412020-09-05 14:50:40 -0600120 if (verbose)
121 printf("Magic signature not found\n");
Gabe Black540c2622011-12-05 12:09:26 +0000122 return 0x0100;
wdenk591dda52002-11-18 00:14:45 +0000123 }
Gabe Black540c2622011-12-05 12:09:26 +0000124}
125
Ivan Gorinov901bb0b2018-03-26 18:06:54 -0700126static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob)
127{
Simon Glassdf30d412020-09-05 14:50:40 -0600128 int bootproto = get_boot_protocol(hdr, false);
Ivan Gorinov901bb0b2018-03-26 18:06:54 -0700129 struct setup_data *sd;
130 int size;
131
132 if (bootproto < 0x0209)
133 return -ENOTSUPP;
134
135 if (!fdt_blob)
136 return 0;
137
138 size = fdt_totalsize(fdt_blob);
139 if (size < 0)
140 return -EINVAL;
141
142 size += sizeof(struct setup_data);
143 sd = (struct setup_data *)malloc(size);
144 if (!sd) {
145 printf("Not enough memory for DTB setup data\n");
146 return -ENOMEM;
147 }
148
149 sd->next = hdr->setup_data;
150 sd->type = SETUP_DTB;
151 sd->len = fdt_totalsize(fdt_blob);
152 memcpy(sd->data, fdt_blob, sd->len);
153 hdr->setup_data = (unsigned long)sd;
154
155 return 0;
156}
157
Simon Glassdf30d412020-09-05 14:50:40 -0600158static const char *get_kernel_version(struct boot_params *params,
159 void *kernel_base)
160{
161 struct setup_header *hdr = &params->hdr;
162 int bootproto;
163
164 bootproto = get_boot_protocol(hdr, false);
165 if (bootproto < 0x0200 || hdr->setup_sects < 15)
166 return NULL;
167
168 return kernel_base + hdr->kernel_version + 0x200;
169}
170
Gabe Black540c2622011-12-05 12:09:26 +0000171struct boot_params *load_zimage(char *image, unsigned long kernel_size,
Simon Glassd98a5bd2014-10-10 08:21:56 -0600172 ulong *load_addressp)
Gabe Black540c2622011-12-05 12:09:26 +0000173{
174 struct boot_params *setup_base;
Simon Glassdf30d412020-09-05 14:50:40 -0600175 const char *version;
Gabe Black540c2622011-12-05 12:09:26 +0000176 int setup_size;
177 int bootproto;
178 int big_image;
179
180 struct boot_params *params = (struct boot_params *)image;
181 struct setup_header *hdr = &params->hdr;
182
183 /* base address for real-mode segment */
184 setup_base = (struct boot_params *)DEFAULT_SETUP_BASE;
185
186 if (!kernel_magic_ok(hdr))
187 return 0;
wdenk57b2d802003-06-27 21:31:46 +0000188
wdenk591dda52002-11-18 00:14:45 +0000189 /* determine size of setup */
Graeme Russ1bab1042010-04-24 00:05:49 +1000190 if (0 == hdr->setup_sects) {
191 printf("Setup Sectors = 0 (defaulting to 4)\n");
wdenk591dda52002-11-18 00:14:45 +0000192 setup_size = 5 * 512;
193 } else {
Graeme Russ1bab1042010-04-24 00:05:49 +1000194 setup_size = (hdr->setup_sects + 1) * 512;
wdenk591dda52002-11-18 00:14:45 +0000195 }
wdenk57b2d802003-06-27 21:31:46 +0000196
Graeme Russ1bab1042010-04-24 00:05:49 +1000197 printf("Setup Size = 0x%8.8lx\n", (ulong)setup_size);
198
Graeme Russ883c6032011-11-08 02:33:15 +0000199 if (setup_size > SETUP_MAX_SIZE)
wdenk591dda52002-11-18 00:14:45 +0000200 printf("Error: Setup is too large (%d bytes)\n", setup_size);
wdenk57b2d802003-06-27 21:31:46 +0000201
Gabe Black540c2622011-12-05 12:09:26 +0000202 /* determine boot protocol version */
Simon Glassdf30d412020-09-05 14:50:40 -0600203 bootproto = get_boot_protocol(hdr, true);
Gabe Black540c2622011-12-05 12:09:26 +0000204
205 printf("Using boot protocol version %x.%02x\n",
206 (bootproto & 0xff00) >> 8, bootproto & 0xff);
207
Simon Glassdf30d412020-09-05 14:50:40 -0600208 version = get_kernel_version(params, image);
209 if (version)
210 printf("Linux kernel version %s\n", version);
211 else
212 printf("Setup Sectors < 15 - Cannot print kernel version\n");
Gabe Black540c2622011-12-05 12:09:26 +0000213
wdenk591dda52002-11-18 00:14:45 +0000214 /* Determine image type */
Graeme Russ883c6032011-11-08 02:33:15 +0000215 big_image = (bootproto >= 0x0200) &&
216 (hdr->loadflags & BIG_KERNEL_FLAG);
wdenk57b2d802003-06-27 21:31:46 +0000217
Graeme Russ1bab1042010-04-24 00:05:49 +1000218 /* Determine load address */
Gabe Black1cf51212011-12-05 12:09:23 +0000219 if (big_image)
Simon Glassd98a5bd2014-10-10 08:21:56 -0600220 *load_addressp = BZIMAGE_LOAD_ADDR;
Gabe Black1cf51212011-12-05 12:09:23 +0000221 else
Simon Glassd98a5bd2014-10-10 08:21:56 -0600222 *load_addressp = ZIMAGE_LOAD_ADDR;
wdenk57b2d802003-06-27 21:31:46 +0000223
Gabe Blackc67a9482011-12-05 12:09:24 +0000224 printf("Building boot_params at 0x%8.8lx\n", (ulong)setup_base);
225 memset(setup_base, 0, sizeof(*setup_base));
226 setup_base->hdr = params->hdr;
wdenk57b2d802003-06-27 21:31:46 +0000227
Gabe Black540c2622011-12-05 12:09:26 +0000228 if (bootproto >= 0x0204)
229 kernel_size = hdr->syssize * 16;
230 else
231 kernel_size -= setup_size;
wdenk57b2d802003-06-27 21:31:46 +0000232
wdenk57b2d802003-06-27 21:31:46 +0000233 if (bootproto == 0x0100) {
Graeme Russ883c6032011-11-08 02:33:15 +0000234 /*
235 * A very old kernel MUST have its real-mode code
236 * loaded at 0x90000
237 */
Simon Glassca37a392017-01-16 07:03:35 -0700238 if ((ulong)setup_base != 0x90000) {
wdenk591dda52002-11-18 00:14:45 +0000239 /* Copy the real-mode kernel */
Graeme Russ883c6032011-11-08 02:33:15 +0000240 memmove((void *)0x90000, setup_base, setup_size);
241
wdenk591dda52002-11-18 00:14:45 +0000242 /* Copy the command line */
Graeme Russ883c6032011-11-08 02:33:15 +0000243 memmove((void *)0x99000,
Gabe Black1cf51212011-12-05 12:09:23 +0000244 (u8 *)setup_base + COMMAND_LINE_OFFSET,
Graeme Russ883c6032011-11-08 02:33:15 +0000245 COMMAND_LINE_SIZE);
wdenk57b2d802003-06-27 21:31:46 +0000246
Graeme Russ883c6032011-11-08 02:33:15 +0000247 /* Relocated */
Gabe Black1cf51212011-12-05 12:09:23 +0000248 setup_base = (struct boot_params *)0x90000;
wdenk591dda52002-11-18 00:14:45 +0000249 }
wdenk57b2d802003-06-27 21:31:46 +0000250
wdenk591dda52002-11-18 00:14:45 +0000251 /* It is recommended to clear memory up to the 32K mark */
Gabe Black1cf51212011-12-05 12:09:23 +0000252 memset((u8 *)0x90000 + setup_size, 0,
253 SETUP_MAX_SIZE - setup_size);
wdenk591dda52002-11-18 00:14:45 +0000254 }
wdenk57b2d802003-06-27 21:31:46 +0000255
Gabe Black540c2622011-12-05 12:09:26 +0000256 if (big_image) {
257 if (kernel_size > BZIMAGE_MAX_SIZE) {
258 printf("Error: bzImage kernel too big! "
259 "(size: %ld, max: %d)\n",
260 kernel_size, BZIMAGE_MAX_SIZE);
261 return 0;
262 }
263 } else if ((kernel_size) > ZIMAGE_MAX_SIZE) {
264 printf("Error: zImage kernel too big! (size: %ld, max: %d)\n",
265 kernel_size, ZIMAGE_MAX_SIZE);
266 return 0;
267 }
268
Simon Glassd98a5bd2014-10-10 08:21:56 -0600269 printf("Loading %s at address %lx (%ld bytes)\n",
270 big_image ? "bzImage" : "zImage", *load_addressp, kernel_size);
Gabe Black540c2622011-12-05 12:09:26 +0000271
Simon Glassd98a5bd2014-10-10 08:21:56 -0600272 memmove((void *)*load_addressp, image + setup_size, kernel_size);
Gabe Black540c2622011-12-05 12:09:26 +0000273
274 return setup_base;
275}
276
277int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
278 unsigned long initrd_addr, unsigned long initrd_size)
279{
280 struct setup_header *hdr = &setup_base->hdr;
Simon Glassdf30d412020-09-05 14:50:40 -0600281 int bootproto = get_boot_protocol(hdr, false);
Gabe Black540c2622011-12-05 12:09:26 +0000282
Gabe Black540c2622011-12-05 12:09:26 +0000283 setup_base->e820_entries = install_e820_map(
284 ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map);
Graeme Russ1bab1042010-04-24 00:05:49 +1000285
Gabe Black540c2622011-12-05 12:09:26 +0000286 if (bootproto == 0x0100) {
287 setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC;
288 setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET;
289 }
wdenk591dda52002-11-18 00:14:45 +0000290 if (bootproto >= 0x0200) {
Simon Glassd67ff032020-09-05 14:50:41 -0600291 hdr->type_of_loader = 0x80; /* U-Boot version 0 */
wdenk591dda52002-11-18 00:14:45 +0000292 if (initrd_addr) {
Gabe Black1cf51212011-12-05 12:09:23 +0000293 printf("Initial RAM disk at linear address "
294 "0x%08lx, size %ld bytes\n",
wdenk591dda52002-11-18 00:14:45 +0000295 initrd_addr, initrd_size);
wdenk57b2d802003-06-27 21:31:46 +0000296
Graeme Russ1bab1042010-04-24 00:05:49 +1000297 hdr->ramdisk_image = initrd_addr;
298 hdr->ramdisk_size = initrd_size;
wdenk591dda52002-11-18 00:14:45 +0000299 }
300 }
wdenk57b2d802003-06-27 21:31:46 +0000301
wdenk591dda52002-11-18 00:14:45 +0000302 if (bootproto >= 0x0201) {
Graeme Russ1bab1042010-04-24 00:05:49 +1000303 hdr->heap_end_ptr = HEAP_END_OFFSET;
304 hdr->loadflags |= HEAP_FLAG;
wdenk591dda52002-11-18 00:14:45 +0000305 }
wdenk57b2d802003-06-27 21:31:46 +0000306
Simon Glass4b4f2732014-10-19 21:11:21 -0600307 if (cmd_line) {
308 if (bootproto >= 0x0202) {
309 hdr->cmd_line_ptr = (uintptr_t)cmd_line;
310 } else if (bootproto >= 0x0200) {
311 setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC;
312 setup_base->screen_info.cl_offset =
313 (uintptr_t)cmd_line - (uintptr_t)setup_base;
Graeme Russ1bab1042010-04-24 00:05:49 +1000314
Simon Glass4b4f2732014-10-19 21:11:21 -0600315 hdr->setup_move_size = 0x9100;
316 }
317
318 /* build command line at COMMAND_LINE_OFFSET */
319 build_command_line(cmd_line, auto_boot);
wdenk591dda52002-11-18 00:14:45 +0000320 }
wdenk591dda52002-11-18 00:14:45 +0000321
Simon Glass3a177172020-09-05 14:50:39 -0600322 if (IS_ENABLED(CONFIG_INTEL_MID) && bootproto >= 0x0207)
Andy Shevchenko8b7adf82018-01-10 19:40:14 +0200323 hdr->hardware_subarch = X86_SUBARCH_INTEL_MID;
Andy Shevchenko8b7adf82018-01-10 19:40:14 +0200324
Simon Glass3a177172020-09-05 14:50:39 -0600325 if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE))
326 setup_base->acpi_rsdp_addr = acpi_get_rsdp_addr();
Andy Shevchenkod87a21d2019-09-13 18:42:00 +0300327
Ivan Gorinov901bb0b2018-03-26 18:06:54 -0700328 setup_device_tree(hdr, (const void *)env_get_hex("fdtaddr", 0));
Bin Mengf6d504f2015-07-06 16:31:36 +0800329 setup_video(&setup_base->screen_info);
330
Simon Glass3a177172020-09-05 14:50:39 -0600331 if (IS_ENABLED(CONFIG_EFI_STUB))
332 setup_efi_info(&setup_base->efi_info);
Bin Meng106dcfc2018-08-23 08:24:10 -0700333
Gabe Black540c2622011-12-05 12:09:26 +0000334 return 0;
wdenk591dda52002-11-18 00:14:45 +0000335}
336
Simon Glassd9b3c982020-09-05 14:50:43 -0600337static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
338 char *const argv[])
Graeme Russ1bab1042010-04-24 00:05:49 +1000339{
Gabe Black540c2622011-12-05 12:09:26 +0000340 struct boot_params *base_ptr;
Simon Glassd9b3c982020-09-05 14:50:43 -0600341 const char *s;
Graeme Russ1bab1042010-04-24 00:05:49 +1000342
Simon Glass48800f42020-09-05 14:50:38 -0600343 memset(&state, '\0', sizeof(state));
Gabe Black1cf51212011-12-05 12:09:23 +0000344 if (argc >= 2) {
Graeme Russ3134be22010-10-07 20:03:19 +1100345 /* argv[1] holds the address of the bzImage */
346 s = argv[1];
Gabe Black1cf51212011-12-05 12:09:23 +0000347 } else {
Simon Glass64b723f2017-08-03 12:22:12 -0600348 s = env_get("fileaddr");
Gabe Black1cf51212011-12-05 12:09:23 +0000349 }
Graeme Russ1bab1042010-04-24 00:05:49 +1000350
Graeme Russ3134be22010-10-07 20:03:19 +1100351 if (s)
Simon Glass48800f42020-09-05 14:50:38 -0600352 state.bzimage_addr = simple_strtoul(s, NULL, 16);
Graeme Russ3134be22010-10-07 20:03:19 +1100353
Gabe Black69b49ee2011-12-05 12:09:27 +0000354 if (argc >= 3) {
Graeme Russ3134be22010-10-07 20:03:19 +1100355 /* argv[2] holds the size of the bzImage */
Simon Glass48800f42020-09-05 14:50:38 -0600356 state.bzimage_size = simple_strtoul(argv[2], NULL, 16);
Gabe Black69b49ee2011-12-05 12:09:27 +0000357 }
358
359 if (argc >= 4)
Simon Glass48800f42020-09-05 14:50:38 -0600360 state.initrd_addr = simple_strtoul(argv[3], NULL, 16);
Gabe Black69b49ee2011-12-05 12:09:27 +0000361 if (argc >= 5)
Simon Glass48800f42020-09-05 14:50:38 -0600362 state.initrd_size = simple_strtoul(argv[4], NULL, 16);
Graeme Russ1bab1042010-04-24 00:05:49 +1000363
Gabe Black1cf51212011-12-05 12:09:23 +0000364 /* Lets look for */
Simon Glass48800f42020-09-05 14:50:38 -0600365 base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
366 &state.load_address);
Graeme Russ883c6032011-11-08 02:33:15 +0000367 if (!base_ptr) {
Simon Glassddf446b2014-10-10 08:21:59 -0600368 puts("## Kernel loading failed ...\n");
Gabe Black540c2622011-12-05 12:09:26 +0000369 return -1;
Graeme Russ1bab1042010-04-24 00:05:49 +1000370 }
Simon Glass48800f42020-09-05 14:50:38 -0600371
372 if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, 0,
373 state.initrd_addr, state.initrd_size)) {
Simon Glassddf446b2014-10-10 08:21:59 -0600374 puts("Setting up boot parameters failed ...\n");
Gabe Black540c2622011-12-05 12:09:26 +0000375 return -1;
376 }
377
Simon Glass0db800c2020-09-05 14:50:42 -0600378 disable_interrupts();
Gabe Black540c2622011-12-05 12:09:26 +0000379 /* we assume that the kernel is in place */
Simon Glass48800f42020-09-05 14:50:38 -0600380 return boot_linux_kernel((ulong)base_ptr, state.load_address, false);
Graeme Russ1bab1042010-04-24 00:05:49 +1000381}
382
Simon Glassd9b3c982020-09-05 14:50:43 -0600383/* Note: This defines the complete_zboot() function */
384U_BOOT_SUBCMDS(zboot,
385 U_BOOT_CMD_MKENT(start, 6, 1, do_zboot_start, "", ""),
386)
387
388int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
389 char *const argv[], int state_mask)
390{
391 int i;
392
393 for (i = 0; i < ZBOOT_STATE_COUNT; i++) {
394 struct cmd_tbl *cmd = &zboot_subcmds[i];
395 int mask = 1 << i;
396 int ret;
397
398 if (mask & state_mask) {
399 ret = cmd->cmd(cmd, flag, argc, argv);
400 if (ret)
401 return ret;
402 }
403 }
404
405 return 0;
406}
407
408int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
409 char *const argv[], int *repeatable)
410{
411 /* determine if we have a sub command */
412 if (argc > 1) {
413 char *endp;
414
415 simple_strtoul(argv[1], &endp, 16);
416 /*
417 * endp pointing to nul means that argv[1] was just a valid
418 * number, so pass it along to the normal processing
419 */
420 if (*endp)
421 return do_zboot(cmdtp, flag, argc, argv, repeatable);
422 }
423
424 do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START);
425
426 return CMD_RET_FAILURE;
427}
428
429U_BOOT_CMDREP_COMPLETE(
430 zboot, 6, do_zboot_parent, "Boot bzImage",
Gabe Black69b49ee2011-12-05 12:09:27 +0000431 "[addr] [size] [initrd addr] [initrd size]\n"
432 " addr - The optional starting address of the bzimage.\n"
433 " If not set it defaults to the environment\n"
434 " variable \"fileaddr\".\n"
435 " size - The optional size of the bzimage. Defaults to\n"
436 " zero.\n"
437 " initrd addr - The address of the initrd image to use, if any.\n"
438 " initrd size - The size of the initrd image to use, if any.\n"
Simon Glassd9b3c982020-09-05 14:50:43 -0600439 "\n"
440 "Sub-commands to do part of the zboot sequence:\n"
441 "\tstart [addr [arg ...]] - specify arguments\n",
442 complete_zboot
Graeme Russ1bab1042010-04-24 00:05:49 +1000443);