Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2009 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <bootm.h> |
| 9 | #include <command.h> |
Simon Glass | 85f1378 | 2019-12-28 10:45:03 -0700 | [diff] [blame] | 10 | #include <image.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 11 | #include <irq_func.h> |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 12 | #include <lmb.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 14 | #include <linux/compiler.h> |
| 15 | |
| 16 | int __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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 27 | static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc, |
| 28 | char *const argv[], bootm_headers_t *images) |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 29 | { |
| 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 Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 38 | images->ep = image_load_addr; |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 39 | debug("* kernel: default image load address = 0x%08lx\n", |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 40 | image_load_addr); |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 41 | } else { |
| 42 | images->ep = simple_strtoul(argv[0], NULL, 16); |
| 43 | 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 | */ |
Baruch Siach | 51cc1f9 | 2020-07-28 17:57:48 +0300 | [diff] [blame] | 57 | if (bootm_find_images(flag, argc, argv, images->ep, zi_end - zi_start)) |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 58 | return 1; |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 63 | int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 64 | { |
| 65 | int ret; |
| 66 | |
| 67 | /* Consume 'bootz' */ |
| 68 | argc--; argv++; |
| 69 | |
| 70 | if (bootz_start(cmdtp, flag, argc, argv, &images)) |
| 71 | return 1; |
| 72 | |
| 73 | /* |
| 74 | * We are doing the BOOTM_STATE_LOADOS state ourselves, so must |
| 75 | * disable interrupts ourselves |
| 76 | */ |
| 77 | bootm_disable_interrupts(); |
| 78 | |
| 79 | images.os.os = IH_OS_LINUX; |
| 80 | ret = do_bootm_states(cmdtp, flag, argc, argv, |
Cédric Schieli | 80d5e6b | 2017-01-23 16:51:45 +0100 | [diff] [blame] | 81 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
| 82 | BOOTM_STATE_RAMDISK | |
| 83 | #endif |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 84 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
| 85 | BOOTM_STATE_OS_GO, |
| 86 | &images, 1); |
| 87 | |
| 88 | return ret; |
| 89 | } |
| 90 | |
| 91 | #ifdef CONFIG_SYS_LONGHELP |
| 92 | static char bootz_help_text[] = |
| 93 | "[addr [initrd[:size]] [fdt]]\n" |
| 94 | " - boot Linux zImage stored in memory\n" |
| 95 | "\tThe argument 'initrd' is optional and specifies the address\n" |
| 96 | "\tof the initrd in memory. The optional argument ':size' allows\n" |
| 97 | "\tspecifying the size of RAW initrd.\n" |
| 98 | #if defined(CONFIG_OF_LIBFDT) |
| 99 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
| 100 | "\ta third argument is required which is the address of the\n" |
| 101 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 102 | "\tuse a '-' for the second argument. If you do not pass a third\n" |
| 103 | "\ta bd_info struct will be passed instead\n" |
| 104 | #endif |
| 105 | ""; |
| 106 | #endif |
| 107 | |
| 108 | U_BOOT_CMD( |
| 109 | bootz, CONFIG_SYS_MAXARGS, 1, do_bootz, |
| 110 | "boot Linux zImage image from memory", bootz_help_text |
| 111 | ); |