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 | |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 7 | #include <bootm.h> |
| 8 | #include <command.h> |
Simon Glass | 85f1378 | 2019-12-28 10:45:03 -0700 | [diff] [blame] | 9 | #include <image.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 10 | #include <irq_func.h> |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 11 | #include <lmb.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 13 | #include <linux/compiler.h> |
| 14 | |
| 15 | int __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 Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 26 | static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc, |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 27 | char *const argv[], struct bootm_headers *images) |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 28 | { |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 29 | ulong zi_start, zi_end; |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 30 | struct bootm_info bmi; |
| 31 | int ret; |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 32 | |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 33 | bootm_init(&bmi); |
| 34 | if (argc) |
| 35 | bmi.addr_img = argv[0]; |
| 36 | if (argc > 1) |
| 37 | bmi.conf_ramdisk = argv[1]; |
| 38 | if (argc > 2) |
| 39 | bmi.conf_fdt = argv[2]; |
| 40 | /* do not set up argc and argv[] since nothing uses them */ |
| 41 | |
Simon Glass | d90f94f | 2023-12-15 20:14:19 -0700 | [diff] [blame] | 42 | ret = bootm_run_states(&bmi, BOOTM_STATE_START); |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 43 | |
| 44 | /* Setup Linux kernel zImage entry point */ |
| 45 | if (!argc) { |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 46 | images->ep = image_load_addr; |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 47 | debug("* kernel: default image load address = 0x%08lx\n", |
Simon Glass | 892265d | 2019-12-28 10:45:02 -0700 | [diff] [blame] | 48 | image_load_addr); |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 49 | } else { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 50 | images->ep = hextoul(argv[0], NULL); |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 51 | debug("* kernel: cmdline image address = 0x%08lx\n", |
| 52 | images->ep); |
| 53 | } |
| 54 | |
| 55 | ret = bootz_setup(images->ep, &zi_start, &zi_end); |
| 56 | if (ret != 0) |
| 57 | return 1; |
| 58 | |
| 59 | lmb_reserve(&images->lmb, images->ep, zi_end - zi_start); |
| 60 | |
| 61 | /* |
| 62 | * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not |
| 63 | * have a header that provide this informaiton. |
| 64 | */ |
Simon Glass | 793a98e | 2023-11-18 14:05:20 -0700 | [diff] [blame] | 65 | if (bootm_find_images(image_load_addr, cmd_arg1(argc, argv), |
| 66 | cmd_arg2(argc, argv), images->ep, |
Simon Glass | d46c81e | 2023-11-18 14:05:16 -0700 | [diff] [blame] | 67 | zi_end - zi_start)) |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 68 | return 1; |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 73 | 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] | 74 | { |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 75 | struct bootm_info bmi; |
Simon Glass | e176bb1 | 2023-12-15 20:14:23 -0700 | [diff] [blame] | 76 | int ret; |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 77 | |
| 78 | /* Consume 'bootz' */ |
| 79 | argc--; argv++; |
| 80 | |
| 81 | if (bootz_start(cmdtp, flag, argc, argv, &images)) |
| 82 | return 1; |
| 83 | |
| 84 | /* |
| 85 | * We are doing the BOOTM_STATE_LOADOS state ourselves, so must |
| 86 | * disable interrupts ourselves |
| 87 | */ |
| 88 | bootm_disable_interrupts(); |
| 89 | |
| 90 | images.os.os = IH_OS_LINUX; |
Simon Glass | 5fb0d14 | 2023-12-15 20:14:17 -0700 | [diff] [blame] | 91 | |
Simon Glass | 50fa2fe | 2023-12-15 20:14:18 -0700 | [diff] [blame] | 92 | bootm_init(&bmi); |
| 93 | if (argc) |
| 94 | bmi.addr_img = argv[0]; |
| 95 | if (argc > 1) |
| 96 | bmi.conf_ramdisk = argv[1]; |
| 97 | if (argc > 2) |
| 98 | bmi.conf_fdt = argv[2]; |
| 99 | bmi.cmd_name = "bootz"; |
| 100 | |
Simon Glass | e176bb1 | 2023-12-15 20:14:23 -0700 | [diff] [blame] | 101 | ret = bootz_run(&bmi); |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 102 | |
| 103 | return ret; |
| 104 | } |
| 105 | |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 106 | U_BOOT_LONGHELP(bootz, |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 107 | "[addr [initrd[:size]] [fdt]]\n" |
| 108 | " - boot Linux zImage stored in memory\n" |
| 109 | "\tThe argument 'initrd' is optional and specifies the address\n" |
| 110 | "\tof the initrd in memory. The optional argument ':size' allows\n" |
| 111 | "\tspecifying the size of RAW initrd.\n" |
| 112 | #if defined(CONFIG_OF_LIBFDT) |
| 113 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
| 114 | "\ta third argument is required which is the address of the\n" |
| 115 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 116 | "\tuse a '-' for the second argument. If you do not pass a third\n" |
| 117 | "\ta bd_info struct will be passed instead\n" |
| 118 | #endif |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 119 | ); |
Tom Rini | 36f067f | 2016-08-12 08:31:15 -0400 | [diff] [blame] | 120 | |
| 121 | U_BOOT_CMD( |
| 122 | bootz, CONFIG_SYS_MAXARGS, 1, do_bootz, |
| 123 | "boot Linux zImage image from memory", bootz_help_text |
| 124 | ); |