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