wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1 | /* |
Detlev Zundel | ca95c9d | 2009-07-13 16:01:18 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2009 |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Boot support |
| 10 | */ |
| 11 | #include <common.h> |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 12 | #include <bootm.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 13 | #include <command.h> |
wdenk | 7f70e85 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 14 | #include <environment.h> |
Simon Glass | 90268b8 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 15 | #include <errno.h> |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 16 | #include <image.h> |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 17 | #include <lmb.h> |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 18 | #include <malloc.h> |
| 19 | #include <nand.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 20 | #include <asm/byteorder.h> |
Anatolij Gustschin | 5bf2766 | 2011-11-19 13:12:18 +0000 | [diff] [blame] | 21 | #include <linux/compiler.h> |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 22 | #include <linux/ctype.h> |
| 23 | #include <linux/err.h> |
| 24 | #include <u-boot/zlib.h> |
Peter Korsgaard | 20dde48 | 2009-11-19 11:37:51 +0100 | [diff] [blame] | 25 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 28 | #if defined(CONFIG_CMD_IMI) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 29 | static int image_info(unsigned long addr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 30 | #endif |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 31 | |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 32 | #if defined(CONFIG_CMD_IMLS) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 33 | #include <flash.h> |
Stefan Roese | ca5def3 | 2010-08-31 10:00:10 +0200 | [diff] [blame] | 34 | #include <mtd/cfi_flash.h> |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 35 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 36 | #endif |
| 37 | |
| 38 | #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 39 | static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 40 | #endif |
| 41 | |
Simon Schwarz | dee1776 | 2011-09-02 00:50:31 +0000 | [diff] [blame] | 42 | bootm_headers_t images; /* pointers to os/initrd/fdt images */ |
Stefan Roese | 15940c9 | 2006-03-13 11:16:36 +0100 | [diff] [blame] | 43 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 44 | /* we overload the cmd field with our state machine info instead of a |
| 45 | * function pointer */ |
Frans Meulenbroeks | f74d9bd | 2010-02-25 10:12:13 +0100 | [diff] [blame] | 46 | static cmd_tbl_t cmd_bootm_sub[] = { |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 47 | U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""), |
| 48 | U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""), |
John Rigby | fca43cc | 2010-10-13 13:57:35 -0600 | [diff] [blame] | 49 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 50 | U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""), |
| 51 | #endif |
| 52 | #ifdef CONFIG_OF_LIBFDT |
| 53 | U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""), |
| 54 | #endif |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 55 | U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""), |
Peter Tyser | 224c90d | 2009-11-18 19:08:59 -0600 | [diff] [blame] | 56 | U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""), |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 57 | U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""), |
Simon Glass | d0ae31e | 2013-06-11 11:14:48 -0700 | [diff] [blame] | 58 | U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""), |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 59 | U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""), |
| 60 | }; |
| 61 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 62 | static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc, |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 63 | char * const argv[]) |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 64 | { |
| 65 | int ret = 0; |
Simon Glass | 6d6f123 | 2011-10-07 13:53:40 +0000 | [diff] [blame] | 66 | long state; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 67 | cmd_tbl_t *c; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 68 | |
Simon Glass | 983c72f | 2013-06-11 11:14:46 -0700 | [diff] [blame] | 69 | c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub)); |
| 70 | argc--; argv++; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 71 | |
| 72 | if (c) { |
Simon Glass | 6d6f123 | 2011-10-07 13:53:40 +0000 | [diff] [blame] | 73 | state = (long)c->cmd; |
Simon Glass | 983c72f | 2013-06-11 11:14:46 -0700 | [diff] [blame] | 74 | if (state == BOOTM_STATE_START) |
Simon Glass | 35fc84f | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 75 | state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER; |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 76 | } else { |
| 77 | /* Unrecognized command */ |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 78 | return CMD_RET_USAGE; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 79 | } |
| 80 | |
Heiko Schocher | ff6c032 | 2015-02-24 07:04:38 +0100 | [diff] [blame^] | 81 | if (((state & BOOTM_STATE_START) != BOOTM_STATE_START) && |
| 82 | images.state >= state) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 83 | printf("Trying to execute a command out of order\n"); |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 84 | return CMD_RET_USAGE; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 85 | } |
| 86 | |
Simon Glass | 35fc84f | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 87 | ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0); |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 92 | /*******************************************************************/ |
| 93 | /* bootm - boot application image from image in memory */ |
| 94 | /*******************************************************************/ |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 95 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 96 | int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 97 | { |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 98 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 99 | static int relocated = 0; |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 100 | |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 101 | if (!relocated) { |
| 102 | int i; |
Daniel Schwierzeck | 58bd77d | 2013-01-07 06:54:52 +0000 | [diff] [blame] | 103 | |
Daniel Schwierzeck | 58bd77d | 2013-01-07 06:54:52 +0000 | [diff] [blame] | 104 | /* relocate names of sub-command table */ |
| 105 | for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++) |
| 106 | cmd_bootm_sub[i].name += gd->reloc_off; |
| 107 | |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 108 | relocated = 1; |
| 109 | } |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 110 | #endif |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 111 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 112 | /* determine if we have a sub command */ |
Simon Glass | 983c72f | 2013-06-11 11:14:46 -0700 | [diff] [blame] | 113 | argc--; argv++; |
| 114 | if (argc > 0) { |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 115 | char *endp; |
| 116 | |
Simon Glass | 983c72f | 2013-06-11 11:14:46 -0700 | [diff] [blame] | 117 | simple_strtoul(argv[0], &endp, 16); |
| 118 | /* endp pointing to NULL means that argv[0] was just a |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 119 | * valid number, pass it along to the normal bootm processing |
| 120 | * |
| 121 | * If endp is ':' or '#' assume a FIT identifier so pass |
| 122 | * along for normal processing. |
| 123 | * |
| 124 | * Right now we assume the first arg should never be '-' |
| 125 | */ |
| 126 | if ((*endp != 0) && (*endp != ':') && (*endp != '#')) |
| 127 | return do_bootm_subcommand(cmdtp, flag, argc, argv); |
| 128 | } |
| 129 | |
Simon Glass | 35fc84f | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 130 | return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START | |
| 131 | BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER | |
Tom Rini | 3d187b3 | 2013-09-23 14:20:37 -0400 | [diff] [blame] | 132 | BOOTM_STATE_LOADOS | |
| 133 | #if defined(CONFIG_PPC) || defined(CONFIG_MIPS) |
| 134 | BOOTM_STATE_OS_CMDLINE | |
| 135 | #endif |
Paul Burton | 5c427e4 | 2013-09-06 11:23:55 +0100 | [diff] [blame] | 136 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
| 137 | BOOTM_STATE_OS_GO, &images, 1); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Mike Frysinger | 67d668b | 2011-06-05 13:43:02 +0000 | [diff] [blame] | 140 | int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) |
| 141 | { |
| 142 | const char *ep = getenv("autostart"); |
| 143 | |
| 144 | if (ep && !strcmp(ep, "yes")) { |
| 145 | char *local_args[2]; |
| 146 | local_args[0] = (char *)cmd; |
| 147 | local_args[1] = NULL; |
| 148 | printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr); |
| 149 | return do_bootm(cmdtp, 0, 1, local_args); |
| 150 | } |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 155 | #ifdef CONFIG_SYS_LONGHELP |
| 156 | static char bootm_help_text[] = |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 157 | "[addr [arg ...]]\n - boot application image stored in memory\n" |
| 158 | "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n" |
| 159 | "\t'arg' can be the address of an initrd image\n" |
Marian Balakowicz | 4a2ad5f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 160 | #if defined(CONFIG_OF_LIBFDT) |
Matthew McClintock | 98a9c4d | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 161 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
Detlev Zundel | 5441f61 | 2007-10-19 16:47:26 +0200 | [diff] [blame] | 162 | "\ta third argument is required which is the address of the\n" |
Matthew McClintock | 98a9c4d | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 163 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 164 | "\tuse a '-' for the second argument. If you do not pass a third\n" |
| 165 | "\ta bd_info struct will be passed instead\n" |
| 166 | #endif |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 167 | #if defined(CONFIG_FIT) |
| 168 | "\t\nFor the new multi component uImage format (FIT) addresses\n" |
| 169 | "\tmust be extened to include component or configuration unit name:\n" |
| 170 | "\taddr:<subimg_uname> - direct component image specification\n" |
| 171 | "\taddr#<conf_uname> - configuration specification\n" |
| 172 | "\tUse iminfo command to get the list of existing component\n" |
| 173 | "\timages and configurations.\n" |
| 174 | #endif |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 175 | "\nSub-commands to do part of the bootm sequence. The sub-commands " |
| 176 | "must be\n" |
| 177 | "issued in the order below (it's ok to not issue all sub-commands):\n" |
| 178 | "\tstart [addr [arg ...]]\n" |
| 179 | "\tloados - load OS image\n" |
Daniel Schwierzeck | 59af76d | 2013-02-26 04:54:19 +0000 | [diff] [blame] | 180 | #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH) |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 181 | "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n" |
| 182 | #endif |
| 183 | #if defined(CONFIG_OF_LIBFDT) |
| 184 | "\tfdt - relocate flat device tree\n" |
| 185 | #endif |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 186 | "\tcmdline - OS specific command line processing/setup\n" |
Peter Tyser | 224c90d | 2009-11-18 19:08:59 -0600 | [diff] [blame] | 187 | "\tbdt - OS specific bd_t processing\n" |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 188 | "\tprep - OS specific prep before relocation or go\n" |
Michal Simek | e3046ba | 2015-01-15 09:53:13 +0100 | [diff] [blame] | 189 | #if defined(CONFIG_TRACE) |
| 190 | "\tfake - OS specific fake start without go\n" |
| 191 | #endif |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 192 | "\tgo - start OS"; |
| 193 | #endif |
| 194 | |
| 195 | U_BOOT_CMD( |
| 196 | bootm, CONFIG_SYS_MAXARGS, 1, do_bootm, |
| 197 | "boot application image from memory", bootm_help_text |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 198 | ); |
| 199 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 200 | /*******************************************************************/ |
| 201 | /* bootd - boot default image */ |
| 202 | /*******************************************************************/ |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 203 | #if defined(CONFIG_CMD_BOOTD) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 204 | int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 205 | { |
Thomas Betker | 73671da | 2014-06-05 20:07:56 +0200 | [diff] [blame] | 206 | return run_command(getenv("bootcmd"), flag); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 207 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 208 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 209 | U_BOOT_CMD( |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 210 | boot, 1, 1, do_bootd, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 211 | "boot default, i.e., run 'bootcmd'", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 212 | "" |
wdenk | 9d2b18a | 2003-06-28 23:11:04 +0000 | [diff] [blame] | 213 | ); |
| 214 | |
| 215 | /* keep old command name "bootd" for backward compatibility */ |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 216 | U_BOOT_CMD( |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 217 | bootd, 1, 1, do_bootd, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 218 | "boot default, i.e., run 'bootcmd'", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 219 | "" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 220 | ); |
| 221 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 222 | #endif |
| 223 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 224 | |
| 225 | /*******************************************************************/ |
| 226 | /* iminfo - print header info for a requested image */ |
| 227 | /*******************************************************************/ |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 228 | #if defined(CONFIG_CMD_IMI) |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 229 | static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 230 | { |
| 231 | int arg; |
| 232 | ulong addr; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 233 | int rcode = 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 234 | |
| 235 | if (argc < 2) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 236 | return image_info(load_addr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 239 | for (arg = 1; arg < argc; ++arg) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 240 | addr = simple_strtoul(argv[arg], NULL, 16); |
| 241 | if (image_info(addr) != 0) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 242 | rcode = 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 243 | } |
| 244 | return rcode; |
| 245 | } |
| 246 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 247 | static int image_info(ulong addr) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 248 | { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 249 | void *hdr = (void *)addr; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 250 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 251 | printf("\n## Checking Image at %08lx ...\n", addr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 252 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 253 | switch (genimg_get_format(hdr)) { |
Heiko Schocher | 21d29f7 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 254 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 255 | case IMAGE_FORMAT_LEGACY: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 256 | puts(" Legacy image found\n"); |
| 257 | if (!image_check_magic(hdr)) { |
| 258 | puts(" Bad Magic Number\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 259 | return 1; |
| 260 | } |
| 261 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 262 | if (!image_check_hcrc(hdr)) { |
| 263 | puts(" Bad Header Checksum\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 264 | return 1; |
| 265 | } |
| 266 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 267 | image_print_contents(hdr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 268 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 269 | puts(" Verifying Checksum ... "); |
| 270 | if (!image_check_dcrc(hdr)) { |
| 271 | puts(" Bad Data CRC\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 272 | return 1; |
| 273 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 274 | puts("OK\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 275 | return 0; |
Heiko Schocher | 21d29f7 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 276 | #endif |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 277 | #if defined(CONFIG_FIT) |
| 278 | case IMAGE_FORMAT_FIT: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 279 | puts(" FIT image found\n"); |
Marian Balakowicz | e32fea6 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 280 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 281 | if (!fit_check_format(hdr)) { |
| 282 | puts("Bad FIT image format!\n"); |
Marian Balakowicz | e32fea6 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 283 | return 1; |
| 284 | } |
| 285 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 286 | fit_print_contents(hdr); |
Bartlomiej Sieka | a4f2434 | 2008-09-09 12:58:16 +0200 | [diff] [blame] | 287 | |
Simon Glass | b8da836 | 2013-05-07 06:11:57 +0000 | [diff] [blame] | 288 | if (!fit_all_image_verify(hdr)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 289 | puts("Bad hash in FIT image!\n"); |
Bartlomiej Sieka | a4f2434 | 2008-09-09 12:58:16 +0200 | [diff] [blame] | 290 | return 1; |
| 291 | } |
| 292 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 293 | return 0; |
| 294 | #endif |
| 295 | default: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 296 | puts("Unknown image format!\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 297 | break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 300 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 301 | } |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 302 | |
| 303 | U_BOOT_CMD( |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 304 | iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 305 | "print header information for application image", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 306 | "addr [addr ...]\n" |
| 307 | " - print header information for application image starting at\n" |
| 308 | " address 'addr' in memory; this includes verification of the\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 309 | " image contents (magic number, header and payload checksums)" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 310 | ); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 311 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 312 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 313 | |
| 314 | /*******************************************************************/ |
| 315 | /* imls - list all images found in flash */ |
| 316 | /*******************************************************************/ |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 317 | #if defined(CONFIG_CMD_IMLS) |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 318 | static int do_imls_nor(void) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 319 | { |
| 320 | flash_info_t *info; |
| 321 | int i, j; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 322 | void *hdr; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 323 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 324 | for (i = 0, info = &flash_info[0]; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 325 | i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) { |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 326 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 327 | if (info->flash_id == FLASH_UNKNOWN) |
| 328 | goto next_bank; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 329 | for (j = 0; j < info->sector_count; ++j) { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 330 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 331 | hdr = (void *)info->start[j]; |
| 332 | if (!hdr) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 333 | goto next_sector; |
| 334 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 335 | switch (genimg_get_format(hdr)) { |
Heiko Schocher | 21d29f7 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 336 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 337 | case IMAGE_FORMAT_LEGACY: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 338 | if (!image_check_hcrc(hdr)) |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 339 | goto next_sector; |
| 340 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 341 | printf("Legacy Image at %08lX:\n", (ulong)hdr); |
| 342 | image_print_contents(hdr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 343 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 344 | puts(" Verifying Checksum ... "); |
| 345 | if (!image_check_dcrc(hdr)) { |
| 346 | puts("Bad Data CRC\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 347 | } else { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 348 | puts("OK\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 349 | } |
| 350 | break; |
Heiko Schocher | 21d29f7 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 351 | #endif |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 352 | #if defined(CONFIG_FIT) |
| 353 | case IMAGE_FORMAT_FIT: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 354 | if (!fit_check_format(hdr)) |
Marian Balakowicz | e32fea6 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 355 | goto next_sector; |
| 356 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 357 | printf("FIT Image at %08lX:\n", (ulong)hdr); |
| 358 | fit_print_contents(hdr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 359 | break; |
| 360 | #endif |
| 361 | default: |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 362 | goto next_sector; |
wdenk | 5bb226e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 363 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 364 | |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 365 | next_sector: ; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 366 | } |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 367 | next_bank: ; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 368 | } |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | #endif |
| 372 | |
| 373 | #if defined(CONFIG_CMD_IMLS_NAND) |
| 374 | static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off, |
| 375 | size_t len) |
| 376 | { |
| 377 | void *imgdata; |
| 378 | int ret; |
| 379 | |
| 380 | imgdata = malloc(len); |
| 381 | if (!imgdata) { |
| 382 | printf("May be a Legacy Image at NAND device %d offset %08llX:\n", |
| 383 | nand_dev, off); |
| 384 | printf(" Low memory(cannot allocate memory for image)\n"); |
| 385 | return -ENOMEM; |
| 386 | } |
| 387 | |
| 388 | ret = nand_read_skip_bad(nand, off, &len, |
| 389 | imgdata); |
| 390 | if (ret < 0 && ret != -EUCLEAN) { |
| 391 | free(imgdata); |
| 392 | return ret; |
| 393 | } |
| 394 | |
| 395 | if (!image_check_hcrc(imgdata)) { |
| 396 | free(imgdata); |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | printf("Legacy Image at NAND device %d offset %08llX:\n", |
| 401 | nand_dev, off); |
| 402 | image_print_contents(imgdata); |
| 403 | |
| 404 | puts(" Verifying Checksum ... "); |
| 405 | if (!image_check_dcrc(imgdata)) |
| 406 | puts("Bad Data CRC\n"); |
| 407 | else |
| 408 | puts("OK\n"); |
| 409 | |
| 410 | free(imgdata); |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off, |
| 416 | size_t len) |
| 417 | { |
| 418 | void *imgdata; |
| 419 | int ret; |
| 420 | |
| 421 | imgdata = malloc(len); |
| 422 | if (!imgdata) { |
| 423 | printf("May be a FIT Image at NAND device %d offset %08llX:\n", |
| 424 | nand_dev, off); |
| 425 | printf(" Low memory(cannot allocate memory for image)\n"); |
| 426 | return -ENOMEM; |
| 427 | } |
| 428 | |
| 429 | ret = nand_read_skip_bad(nand, off, &len, |
| 430 | imgdata); |
| 431 | if (ret < 0 && ret != -EUCLEAN) { |
| 432 | free(imgdata); |
| 433 | return ret; |
| 434 | } |
| 435 | |
| 436 | if (!fit_check_format(imgdata)) { |
| 437 | free(imgdata); |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off); |
| 442 | |
| 443 | fit_print_contents(imgdata); |
| 444 | free(imgdata); |
| 445 | |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | static int do_imls_nand(void) |
| 450 | { |
| 451 | nand_info_t *nand; |
| 452 | int nand_dev = nand_curr_device; |
| 453 | size_t len; |
| 454 | loff_t off; |
| 455 | u32 buffer[16]; |
| 456 | |
| 457 | if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) { |
| 458 | puts("\nNo NAND devices available\n"); |
| 459 | return -ENODEV; |
| 460 | } |
| 461 | |
| 462 | printf("\n"); |
| 463 | |
| 464 | for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) { |
| 465 | nand = &nand_info[nand_dev]; |
| 466 | if (!nand->name || !nand->size) |
| 467 | continue; |
| 468 | |
| 469 | for (off = 0; off < nand->size; off += nand->erasesize) { |
| 470 | const image_header_t *header; |
| 471 | int ret; |
| 472 | |
| 473 | if (nand_block_isbad(nand, off)) |
| 474 | continue; |
| 475 | |
| 476 | len = sizeof(buffer); |
| 477 | |
| 478 | ret = nand_read(nand, off, &len, (u8 *)buffer); |
| 479 | if (ret < 0 && ret != -EUCLEAN) { |
| 480 | printf("NAND read error %d at offset %08llX\n", |
| 481 | ret, off); |
| 482 | continue; |
| 483 | } |
| 484 | |
| 485 | switch (genimg_get_format(buffer)) { |
Heiko Schocher | 21d29f7 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 486 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 487 | case IMAGE_FORMAT_LEGACY: |
| 488 | header = (const image_header_t *)buffer; |
| 489 | |
| 490 | len = image_get_image_size(header); |
| 491 | nand_imls_legacyimage(nand, nand_dev, off, len); |
| 492 | break; |
Heiko Schocher | 21d29f7 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 493 | #endif |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 494 | #if defined(CONFIG_FIT) |
| 495 | case IMAGE_FORMAT_FIT: |
| 496 | len = fit_get_size(buffer); |
| 497 | nand_imls_fitimage(nand, nand_dev, off, len); |
| 498 | break; |
| 499 | #endif |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | #endif |
| 507 | |
| 508 | #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) |
| 509 | static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 510 | { |
| 511 | int ret_nor = 0, ret_nand = 0; |
| 512 | |
| 513 | #if defined(CONFIG_CMD_IMLS) |
| 514 | ret_nor = do_imls_nor(); |
| 515 | #endif |
| 516 | |
| 517 | #if defined(CONFIG_CMD_IMLS_NAND) |
| 518 | ret_nand = do_imls_nand(); |
| 519 | #endif |
| 520 | |
| 521 | if (ret_nor) |
| 522 | return ret_nor; |
| 523 | |
| 524 | if (ret_nand) |
| 525 | return ret_nand; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 526 | |
| 527 | return (0); |
| 528 | } |
| 529 | |
| 530 | U_BOOT_CMD( |
| 531 | imls, 1, 1, do_imls, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 532 | "list all images found in flash", |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 533 | "\n" |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 534 | " - Prints information about all images found at sector/block\n" |
| 535 | " boundaries in nor/nand flash." |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 536 | ); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 537 | #endif |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 538 | |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 539 | #ifdef CONFIG_CMD_BOOTZ |
| 540 | |
Simon Glass | a5266d6 | 2013-07-04 13:26:10 -0700 | [diff] [blame] | 541 | int __weak bootz_setup(ulong image, ulong *start, ulong *end) |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 542 | { |
| 543 | /* Please define bootz_setup() for your platform */ |
| 544 | |
| 545 | puts("Your platform's zImage format isn't supported yet!\n"); |
| 546 | return -1; |
| 547 | } |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 548 | |
| 549 | /* |
| 550 | * zImage booting support |
| 551 | */ |
| 552 | static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc, |
| 553 | char * const argv[], bootm_headers_t *images) |
| 554 | { |
| 555 | int ret; |
Simon Glass | a5266d6 | 2013-07-04 13:26:10 -0700 | [diff] [blame] | 556 | ulong zi_start, zi_end; |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 557 | |
Simon Glass | 35fc84f | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 558 | ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, |
| 559 | images, 1); |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 560 | |
| 561 | /* Setup Linux kernel zImage entry point */ |
Tom Rini | 2b9599e | 2013-07-09 15:32:34 -0400 | [diff] [blame] | 562 | if (!argc) { |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 563 | images->ep = load_addr; |
| 564 | debug("* kernel: default image load address = 0x%08lx\n", |
| 565 | load_addr); |
| 566 | } else { |
Tom Rini | 2b9599e | 2013-07-09 15:32:34 -0400 | [diff] [blame] | 567 | images->ep = simple_strtoul(argv[0], NULL, 16); |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 568 | debug("* kernel: cmdline image address = 0x%08lx\n", |
| 569 | images->ep); |
| 570 | } |
| 571 | |
Simon Glass | a5266d6 | 2013-07-04 13:26:10 -0700 | [diff] [blame] | 572 | ret = bootz_setup(images->ep, &zi_start, &zi_end); |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 573 | if (ret != 0) |
| 574 | return 1; |
| 575 | |
| 576 | lmb_reserve(&images->lmb, images->ep, zi_end - zi_start); |
| 577 | |
Tom Rini | 225fd8c | 2013-07-09 15:33:25 -0400 | [diff] [blame] | 578 | /* |
| 579 | * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not |
| 580 | * have a header that provide this informaiton. |
| 581 | */ |
Simon Glass | b639640 | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 582 | if (bootm_find_ramdisk_fdt(flag, argc, argv)) |
Tom Rini | 2b9599e | 2013-07-09 15:32:34 -0400 | [diff] [blame] | 583 | return 1; |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 584 | |
Tom Rini | 2b9599e | 2013-07-09 15:32:34 -0400 | [diff] [blame] | 585 | return 0; |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Rob Herring | da62022 | 2012-12-02 21:00:23 -0600 | [diff] [blame] | 588 | int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 589 | { |
Simon Glass | 35fc84f | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 590 | int ret; |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 591 | |
Tom Rini | 2b9599e | 2013-07-09 15:32:34 -0400 | [diff] [blame] | 592 | /* Consume 'bootz' */ |
| 593 | argc--; argv++; |
| 594 | |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 595 | if (bootz_start(cmdtp, flag, argc, argv, &images)) |
| 596 | return 1; |
| 597 | |
Simon Glass | 385501d | 2013-07-04 13:26:08 -0700 | [diff] [blame] | 598 | /* |
| 599 | * We are doing the BOOTM_STATE_LOADOS state ourselves, so must |
| 600 | * disable interrupts ourselves |
| 601 | */ |
| 602 | bootm_disable_interrupts(); |
| 603 | |
Simon Glass | fb1b139 | 2013-07-04 13:26:11 -0700 | [diff] [blame] | 604 | images.os.os = IH_OS_LINUX; |
Simon Glass | 35fc84f | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 605 | ret = do_bootm_states(cmdtp, flag, argc, argv, |
Simon Glass | fb1b139 | 2013-07-04 13:26:11 -0700 | [diff] [blame] | 606 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
| 607 | BOOTM_STATE_OS_GO, |
Simon Glass | d0ae31e | 2013-06-11 11:14:48 -0700 | [diff] [blame] | 608 | &images, 1); |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 609 | |
Simon Glass | 35fc84f | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 610 | return ret; |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 613 | #ifdef CONFIG_SYS_LONGHELP |
| 614 | static char bootz_help_text[] = |
Marek Vasut | 017e1f3 | 2012-03-18 11:47:58 +0000 | [diff] [blame] | 615 | "[addr [initrd[:size]] [fdt]]\n" |
| 616 | " - boot Linux zImage stored in memory\n" |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 617 | "\tThe argument 'initrd' is optional and specifies the address\n" |
Marek Vasut | 017e1f3 | 2012-03-18 11:47:58 +0000 | [diff] [blame] | 618 | "\tof the initrd in memory. The optional argument ':size' allows\n" |
| 619 | "\tspecifying the size of RAW initrd.\n" |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 620 | #if defined(CONFIG_OF_LIBFDT) |
| 621 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
| 622 | "\ta third argument is required which is the address of the\n" |
| 623 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 624 | "\tuse a '-' for the second argument. If you do not pass a third\n" |
| 625 | "\ta bd_info struct will be passed instead\n" |
| 626 | #endif |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 627 | ""; |
| 628 | #endif |
| 629 | |
| 630 | U_BOOT_CMD( |
| 631 | bootz, CONFIG_SYS_MAXARGS, 1, do_bootz, |
| 632 | "boot Linux zImage image from memory", bootz_help_text |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 633 | ); |
| 634 | #endif /* CONFIG_CMD_BOOTZ */ |
Tom Rini | d2b2ffe | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 635 | |
| 636 | #ifdef CONFIG_CMD_BOOTI |
| 637 | /* See Documentation/arm64/booting.txt in the Linux kernel */ |
| 638 | struct Image_header { |
| 639 | uint32_t code0; /* Executable code */ |
| 640 | uint32_t code1; /* Executable code */ |
| 641 | uint64_t text_offset; /* Image load offset, LE */ |
| 642 | uint64_t image_size; /* Effective Image size, LE */ |
| 643 | uint64_t res1; /* reserved */ |
| 644 | uint64_t res2; /* reserved */ |
| 645 | uint64_t res3; /* reserved */ |
| 646 | uint64_t res4; /* reserved */ |
| 647 | uint32_t magic; /* Magic number */ |
| 648 | uint32_t res5; |
| 649 | }; |
| 650 | |
| 651 | #define LINUX_ARM64_IMAGE_MAGIC 0x644d5241 |
| 652 | |
| 653 | static int booti_setup(bootm_headers_t *images) |
| 654 | { |
| 655 | struct Image_header *ih; |
| 656 | uint64_t dst; |
| 657 | |
| 658 | ih = (struct Image_header *)map_sysmem(images->ep, 0); |
| 659 | |
| 660 | if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) { |
| 661 | puts("Bad Linux ARM64 Image magic!\n"); |
| 662 | return 1; |
| 663 | } |
| 664 | |
| 665 | if (ih->image_size == 0) { |
| 666 | puts("Image lacks image_size field, assuming 16MiB\n"); |
| 667 | ih->image_size = (16 << 20); |
| 668 | } |
| 669 | |
| 670 | /* |
| 671 | * If we are not at the correct run-time location, set the new |
| 672 | * correct location and then move the image there. |
| 673 | */ |
| 674 | dst = gd->bd->bi_dram[0].start + le32_to_cpu(ih->text_offset); |
| 675 | if (images->ep != dst) { |
| 676 | void *src; |
| 677 | |
| 678 | debug("Moving Image from 0x%lx to 0x%llx\n", images->ep, dst); |
| 679 | |
| 680 | src = (void *)images->ep; |
| 681 | images->ep = dst; |
| 682 | memmove((void *)dst, src, le32_to_cpu(ih->image_size)); |
| 683 | } |
| 684 | |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | /* |
| 689 | * Image booting support |
| 690 | */ |
| 691 | static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, |
| 692 | char * const argv[], bootm_headers_t *images) |
| 693 | { |
| 694 | int ret; |
| 695 | struct Image_header *ih; |
| 696 | |
| 697 | ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, |
| 698 | images, 1); |
| 699 | |
| 700 | /* Setup Linux kernel Image entry point */ |
| 701 | if (!argc) { |
| 702 | images->ep = load_addr; |
| 703 | debug("* kernel: default image load address = 0x%08lx\n", |
| 704 | load_addr); |
| 705 | } else { |
| 706 | images->ep = simple_strtoul(argv[0], NULL, 16); |
| 707 | debug("* kernel: cmdline image address = 0x%08lx\n", |
| 708 | images->ep); |
| 709 | } |
| 710 | |
| 711 | ret = booti_setup(images); |
| 712 | if (ret != 0) |
| 713 | return 1; |
| 714 | |
| 715 | ih = (struct Image_header *)map_sysmem(images->ep, 0); |
| 716 | |
| 717 | lmb_reserve(&images->lmb, images->ep, le32_to_cpu(ih->image_size)); |
| 718 | |
| 719 | /* |
| 720 | * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not |
| 721 | * have a header that provide this informaiton. |
| 722 | */ |
| 723 | if (bootm_find_ramdisk_fdt(flag, argc, argv)) |
| 724 | return 1; |
| 725 | |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 730 | { |
| 731 | int ret; |
| 732 | |
| 733 | /* Consume 'booti' */ |
| 734 | argc--; argv++; |
| 735 | |
| 736 | if (booti_start(cmdtp, flag, argc, argv, &images)) |
| 737 | return 1; |
| 738 | |
| 739 | /* |
| 740 | * We are doing the BOOTM_STATE_LOADOS state ourselves, so must |
| 741 | * disable interrupts ourselves |
| 742 | */ |
| 743 | bootm_disable_interrupts(); |
| 744 | |
| 745 | images.os.os = IH_OS_LINUX; |
| 746 | ret = do_bootm_states(cmdtp, flag, argc, argv, |
| 747 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
| 748 | BOOTM_STATE_OS_GO, |
| 749 | &images, 1); |
| 750 | |
| 751 | return ret; |
| 752 | } |
| 753 | |
| 754 | #ifdef CONFIG_SYS_LONGHELP |
| 755 | static char booti_help_text[] = |
| 756 | "[addr [initrd[:size]] [fdt]]\n" |
| 757 | " - boot Linux Image stored in memory\n" |
| 758 | "\tThe argument 'initrd' is optional and specifies the address\n" |
| 759 | "\tof the initrd in memory. The optional argument ':size' allows\n" |
| 760 | "\tspecifying the size of RAW initrd.\n" |
| 761 | #if defined(CONFIG_OF_LIBFDT) |
| 762 | "\tSince booting a Linux kernelrequires a flat device-tree\n" |
| 763 | "\ta third argument is required which is the address of the\n" |
| 764 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 765 | "\tuse a '-' for the second argument.\n" |
| 766 | #endif |
| 767 | ""; |
| 768 | #endif |
| 769 | |
| 770 | U_BOOT_CMD( |
| 771 | booti, CONFIG_SYS_MAXARGS, 1, do_booti, |
| 772 | "boot arm64 Linux Image image from memory", booti_help_text |
| 773 | ); |
| 774 | #endif /* CONFIG_CMD_BOOTI */ |