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