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