wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1 | /* |
Detlev Zundel | 7709447 | 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 | d79de1d | 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 | 3b5866d | 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 | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 14 | #include <environment.h> |
Simon Glass | 0129b52 | 2014-10-19 21:11:24 -0600 | [diff] [blame] | 15 | #include <errno.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 16 | #include <image.h> |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 17 | #include <lmb.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 18 | #include <malloc.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 19 | #include <mapmem.h> |
Simon Glass | 3b5866d | 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 | 18e73d9 | 2011-11-19 13:12:18 +0000 | [diff] [blame] | 22 | #include <linux/compiler.h> |
Simon Glass | 3b5866d | 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 | f7440cd | 2009-11-19 11:37:51 +0100 | [diff] [blame] | 26 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 28 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 29 | #if defined(CONFIG_CMD_IMI) |
Stephen Warren | 6904b6e | 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 | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 32 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 33 | #if defined(CONFIG_CMD_IMLS) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 34 | #include <flash.h> |
Stefan Roese | fb9a730 | 2010-08-31 10:00:10 +0200 | [diff] [blame] | 35 | #include <mtd/cfi_flash.h> |
Marian Balakowicz | 513b4a1 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 36 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
Vipin Kumar | 3df41b1 | 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 | 6904b6e | 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 | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 41 | #endif |
Kumar Gala | bf3954f | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 42 | |
Simon Schwarz | 6519bbf | 2011-09-02 00:50:31 +0000 | [diff] [blame] | 43 | bootm_headers_t images; /* pointers to os/initrd/fdt images */ |
Stefan Roese | 5d5ce29 | 2006-03-13 11:16:36 +0100 | [diff] [blame] | 44 | |
Kumar Gala | 18178bc | 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 | 6b419fb | 2010-02-25 10:12:13 +0100 | [diff] [blame] | 47 | static cmd_tbl_t cmd_bootm_sub[] = { |
Kumar Gala | 18178bc | 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 | eea8e69 | 2010-10-13 13:57:35 -0600 | [diff] [blame] | 50 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
Kumar Gala | 18178bc | 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 | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 56 | U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""), |
Peter Tyser | 694a393 | 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 | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 58 | U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""), |
Simon Glass | 0013488 | 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 | 18178bc | 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 | dc00a68 | 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 | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 64 | char * const argv[]) |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 65 | { |
| 66 | int ret = 0; |
Simon Glass | 81afc3d | 2011-10-07 13:53:40 +0000 | [diff] [blame] | 67 | long state; |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 68 | cmd_tbl_t *c; |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 69 | |
Simon Glass | 794a921 | 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 | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 72 | |
| 73 | if (c) { |
Simon Glass | 81afc3d | 2011-10-07 13:53:40 +0000 | [diff] [blame] | 74 | state = (long)c->cmd; |
Simon Glass | 794a921 | 2013-06-11 11:14:46 -0700 | [diff] [blame] | 75 | if (state == BOOTM_STATE_START) |
Simon Glass | 3081e2e | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 76 | state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER; |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 77 | } else { |
| 78 | /* Unrecognized command */ |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 79 | return CMD_RET_USAGE; |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 80 | } |
| 81 | |
Heiko Schocher | f31a566 | 2015-02-24 07:04:38 +0100 | [diff] [blame] | 82 | if (((state & BOOTM_STATE_START) != BOOTM_STATE_START) && |
| 83 | images.state >= state) { |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 84 | printf("Trying to execute a command out of order\n"); |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 85 | return CMD_RET_USAGE; |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 86 | } |
| 87 | |
Simon Glass | 3081e2e | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 88 | ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0); |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 89 | |
| 90 | return ret; |
| 91 | } |
| 92 | |
Kumar Gala | bd70bbe | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 93 | /*******************************************************************/ |
| 94 | /* bootm - boot application image from image in memory */ |
| 95 | /*******************************************************************/ |
Kumar Gala | bf3954f | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 96 | |
Stephen Warren | 6904b6e | 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 | bd70bbe | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 98 | { |
Wolfgang Denk | d0813e5 | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 99 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Peter Tyser | 9057cbf | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 100 | static int relocated = 0; |
Kumar Gala | bf3954f | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 101 | |
Kumar Gala | bf3954f | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 102 | if (!relocated) { |
| 103 | int i; |
Daniel Schwierzeck | a218709 | 2013-01-07 06:54:52 +0000 | [diff] [blame] | 104 | |
Daniel Schwierzeck | a218709 | 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 | bf3954f | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 109 | relocated = 1; |
| 110 | } |
Peter Tyser | 9057cbf | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 111 | #endif |
Kumar Gala | bd70bbe | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 112 | |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 113 | /* determine if we have a sub command */ |
Simon Glass | 794a921 | 2013-06-11 11:14:46 -0700 | [diff] [blame] | 114 | argc--; argv++; |
| 115 | if (argc > 0) { |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 116 | char *endp; |
| 117 | |
Simon Glass | 794a921 | 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 | 18178bc | 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 | 3081e2e | 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 | 1008dc2 | 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 | 8a39e8d | 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 | 194c2e8 | 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 | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 156 | #ifdef CONFIG_SYS_LONGHELP |
| 157 | static char bootm_help_text[] = |
Marian Balakowicz | 2df645e | 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 | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 161 | #if defined(CONFIG_OF_LIBFDT) |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 162 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
Detlev Zundel | e609916 | 2007-10-19 16:47:26 +0200 | [diff] [blame] | 163 | "\ta third argument is required which is the address of the\n" |
Matthew McClintock | 6fb7c81 | 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 | 9f8e4aa | 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 | 18178bc | 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 | f2f2ec9 | 2013-02-26 04:54:19 +0000 | [diff] [blame] | 181 | #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH) |
Kumar Gala | 18178bc | 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 | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 187 | "\tcmdline - OS specific command line processing/setup\n" |
Peter Tyser | 694a393 | 2009-11-18 19:08:59 -0600 | [diff] [blame] | 188 | "\tbdt - OS specific bd_t processing\n" |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 189 | "\tprep - OS specific prep before relocation or go\n" |
Michal Simek | 5ce8e42 | 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 | dc00a68 | 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 | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 199 | ); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 200 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 201 | /*******************************************************************/ |
| 202 | /* bootd - boot default image */ |
| 203 | /*******************************************************************/ |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 204 | #if defined(CONFIG_CMD_BOOTD) |
Stephen Warren | 6904b6e | 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 | 5ac0026 | 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 | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 209 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 210 | U_BOOT_CMD( |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 211 | boot, 1, 1, do_bootd, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 212 | "boot default, i.e., run 'bootcmd'", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 213 | "" |
wdenk | 3086a97 | 2003-06-28 23:11:04 +0000 | [diff] [blame] | 214 | ); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 215 | |
wdenk | 3086a97 | 2003-06-28 23:11:04 +0000 | [diff] [blame] | 216 | /* keep old command name "bootd" for backward compatibility */ |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 217 | U_BOOT_CMD( |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 218 | bootd, 1, 1, do_bootd, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 219 | "boot default, i.e., run 'bootcmd'", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 220 | "" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 221 | ); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 222 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 223 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 224 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 225 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 226 | /*******************************************************************/ |
| 227 | /* iminfo - print header info for a requested image */ |
| 228 | /*******************************************************************/ |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 229 | #if defined(CONFIG_CMD_IMI) |
Kim Phillips | dc00a68 | 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 | 2df645e | 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 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 236 | if (argc < 2) { |
Stephen Warren | 6904b6e | 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 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 239 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 240 | for (arg = 1; arg < argc; ++arg) { |
Stephen Warren | 6904b6e | 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 | 2df645e | 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 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 247 | |
Stephen Warren | 6904b6e | 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 | dbdd16a | 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 | 6904b6e | 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 | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 254 | switch (genimg_get_format(hdr)) { |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 255 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 256 | case IMAGE_FORMAT_LEGACY: |
Stephen Warren | 6904b6e | 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 | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 260 | return 1; |
| 261 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 262 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 263 | if (!image_check_hcrc(hdr)) { |
| 264 | puts(" Bad Header Checksum\n"); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 265 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 268 | image_print_contents(hdr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 269 | |
Stephen Warren | 6904b6e | 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 | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 273 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 274 | } |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 275 | puts("OK\n"); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 276 | return 0; |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 277 | #endif |
Michael Trimarchi | 44af20b | 2016-06-10 19:54:37 +0200 | [diff] [blame] | 278 | #if defined(CONFIG_ANDROID_BOOT_IMAGE) |
| 279 | case IMAGE_FORMAT_ANDROID: |
| 280 | puts(" Android image found\n"); |
| 281 | android_print_contents(hdr); |
| 282 | return 0; |
| 283 | #endif |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 284 | #if defined(CONFIG_FIT) |
| 285 | case IMAGE_FORMAT_FIT: |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 286 | puts(" FIT image found\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 287 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 288 | if (!fit_check_format(hdr)) { |
| 289 | puts("Bad FIT image format!\n"); |
Marian Balakowicz | cc1fd91 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 290 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 293 | fit_print_contents(hdr); |
Bartlomiej Sieka | 03797f5 | 2008-09-09 12:58:16 +0200 | [diff] [blame] | 294 | |
Simon Glass | 7428ad1 | 2013-05-07 06:11:57 +0000 | [diff] [blame] | 295 | if (!fit_all_image_verify(hdr)) { |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 296 | puts("Bad hash in FIT image!\n"); |
Bartlomiej Sieka | 03797f5 | 2008-09-09 12:58:16 +0200 | [diff] [blame] | 297 | return 1; |
| 298 | } |
| 299 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 300 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 301 | #endif |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 302 | default: |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 303 | puts("Unknown image format!\n"); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 304 | break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 305 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 306 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 307 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 308 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 309 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 310 | U_BOOT_CMD( |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 311 | iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 312 | "print header information for application image", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 313 | "addr [addr ...]\n" |
| 314 | " - print header information for application image starting at\n" |
| 315 | " address 'addr' in memory; this includes verification of the\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 316 | " image contents (magic number, header and payload checksums)" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 317 | ); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 318 | #endif |
| 319 | |
| 320 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 321 | /*******************************************************************/ |
| 322 | /* imls - list all images found in flash */ |
| 323 | /*******************************************************************/ |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 324 | #if defined(CONFIG_CMD_IMLS) |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 325 | static int do_imls_nor(void) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 326 | { |
| 327 | flash_info_t *info; |
| 328 | int i, j; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 329 | void *hdr; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 330 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 331 | for (i = 0, info = &flash_info[0]; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 332 | i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 333 | |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 334 | if (info->flash_id == FLASH_UNKNOWN) |
| 335 | goto next_bank; |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 336 | for (j = 0; j < info->sector_count; ++j) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 337 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 338 | hdr = (void *)info->start[j]; |
| 339 | if (!hdr) |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 340 | goto next_sector; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 341 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 342 | switch (genimg_get_format(hdr)) { |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 343 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 344 | case IMAGE_FORMAT_LEGACY: |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 345 | if (!image_check_hcrc(hdr)) |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 346 | goto next_sector; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 347 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 348 | printf("Legacy Image at %08lX:\n", (ulong)hdr); |
| 349 | image_print_contents(hdr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 350 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 351 | puts(" Verifying Checksum ... "); |
| 352 | if (!image_check_dcrc(hdr)) { |
| 353 | puts("Bad Data CRC\n"); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 354 | } else { |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 355 | puts("OK\n"); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 356 | } |
| 357 | break; |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 358 | #endif |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 359 | #if defined(CONFIG_FIT) |
| 360 | case IMAGE_FORMAT_FIT: |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 361 | if (!fit_check_format(hdr)) |
Marian Balakowicz | cc1fd91 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 362 | goto next_sector; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 363 | |
Stephen Warren | 6904b6e | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 364 | printf("FIT Image at %08lX:\n", (ulong)hdr); |
| 365 | fit_print_contents(hdr); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 366 | break; |
| 367 | #endif |
| 368 | default: |
| 369 | goto next_sector; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 370 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 371 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 372 | next_sector: ; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 373 | } |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 374 | next_bank: ; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 375 | } |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 376 | return 0; |
| 377 | } |
| 378 | #endif |
| 379 | |
| 380 | #if defined(CONFIG_CMD_IMLS_NAND) |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 381 | static int nand_imls_legacyimage(struct mtd_info *mtd, int nand_dev, |
| 382 | loff_t off, size_t len) |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 383 | { |
| 384 | void *imgdata; |
| 385 | int ret; |
| 386 | |
| 387 | imgdata = malloc(len); |
| 388 | if (!imgdata) { |
| 389 | printf("May be a Legacy Image at NAND device %d offset %08llX:\n", |
| 390 | nand_dev, off); |
| 391 | printf(" Low memory(cannot allocate memory for image)\n"); |
| 392 | return -ENOMEM; |
| 393 | } |
| 394 | |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 395 | ret = nand_read_skip_bad(mtd, off, &len, imgdata); |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 396 | if (ret < 0 && ret != -EUCLEAN) { |
| 397 | free(imgdata); |
| 398 | return ret; |
| 399 | } |
| 400 | |
| 401 | if (!image_check_hcrc(imgdata)) { |
| 402 | free(imgdata); |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | printf("Legacy Image at NAND device %d offset %08llX:\n", |
| 407 | nand_dev, off); |
| 408 | image_print_contents(imgdata); |
| 409 | |
| 410 | puts(" Verifying Checksum ... "); |
| 411 | if (!image_check_dcrc(imgdata)) |
| 412 | puts("Bad Data CRC\n"); |
| 413 | else |
| 414 | puts("OK\n"); |
| 415 | |
| 416 | free(imgdata); |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 421 | static int nand_imls_fitimage(struct mtd_info *mtd, int nand_dev, loff_t off, |
| 422 | size_t len) |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 423 | { |
| 424 | void *imgdata; |
| 425 | int ret; |
| 426 | |
| 427 | imgdata = malloc(len); |
| 428 | if (!imgdata) { |
| 429 | printf("May be a FIT Image at NAND device %d offset %08llX:\n", |
| 430 | nand_dev, off); |
| 431 | printf(" Low memory(cannot allocate memory for image)\n"); |
| 432 | return -ENOMEM; |
| 433 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 434 | |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 435 | ret = nand_read_skip_bad(mtd, off, &len, imgdata); |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 436 | if (ret < 0 && ret != -EUCLEAN) { |
| 437 | free(imgdata); |
| 438 | return ret; |
| 439 | } |
| 440 | |
| 441 | if (!fit_check_format(imgdata)) { |
| 442 | free(imgdata); |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off); |
| 447 | |
| 448 | fit_print_contents(imgdata); |
| 449 | free(imgdata); |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | static int do_imls_nand(void) |
| 455 | { |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 456 | struct mtd_info *mtd; |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 457 | int nand_dev = nand_curr_device; |
| 458 | size_t len; |
| 459 | loff_t off; |
| 460 | u32 buffer[16]; |
| 461 | |
| 462 | if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) { |
| 463 | puts("\nNo NAND devices available\n"); |
| 464 | return -ENODEV; |
| 465 | } |
| 466 | |
| 467 | printf("\n"); |
| 468 | |
| 469 | for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) { |
Scott Wood | 2c1b7e1 | 2016-05-30 13:57:55 -0500 | [diff] [blame] | 470 | mtd = nand_info[nand_dev]; |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 471 | if (!mtd->name || !mtd->size) |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 472 | continue; |
| 473 | |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 474 | for (off = 0; off < mtd->size; off += mtd->erasesize) { |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 475 | const image_header_t *header; |
| 476 | int ret; |
| 477 | |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 478 | if (nand_block_isbad(mtd, off)) |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 479 | continue; |
| 480 | |
| 481 | len = sizeof(buffer); |
| 482 | |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 483 | ret = nand_read(mtd, off, &len, (u8 *)buffer); |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 484 | if (ret < 0 && ret != -EUCLEAN) { |
| 485 | printf("NAND read error %d at offset %08llX\n", |
| 486 | ret, off); |
| 487 | continue; |
| 488 | } |
| 489 | |
| 490 | switch (genimg_get_format(buffer)) { |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 491 | #if defined(CONFIG_IMAGE_FORMAT_LEGACY) |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 492 | case IMAGE_FORMAT_LEGACY: |
| 493 | header = (const image_header_t *)buffer; |
| 494 | |
| 495 | len = image_get_image_size(header); |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 496 | nand_imls_legacyimage(mtd, nand_dev, off, len); |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 497 | break; |
Heiko Schocher | 515eb12 | 2014-05-28 11:33:33 +0200 | [diff] [blame] | 498 | #endif |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 499 | #if defined(CONFIG_FIT) |
| 500 | case IMAGE_FORMAT_FIT: |
| 501 | len = fit_get_size(buffer); |
Scott Wood | 08364d9 | 2016-05-30 13:57:54 -0500 | [diff] [blame] | 502 | nand_imls_fitimage(mtd, nand_dev, off, len); |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 503 | break; |
| 504 | #endif |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | #endif |
| 512 | |
| 513 | #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) |
| 514 | static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 515 | { |
| 516 | int ret_nor = 0, ret_nand = 0; |
| 517 | |
| 518 | #if defined(CONFIG_CMD_IMLS) |
| 519 | ret_nor = do_imls_nor(); |
| 520 | #endif |
| 521 | |
| 522 | #if defined(CONFIG_CMD_IMLS_NAND) |
| 523 | ret_nand = do_imls_nand(); |
| 524 | #endif |
| 525 | |
| 526 | if (ret_nor) |
| 527 | return ret_nor; |
| 528 | |
| 529 | if (ret_nand) |
| 530 | return ret_nand; |
| 531 | |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 532 | return (0); |
| 533 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 534 | |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 535 | U_BOOT_CMD( |
| 536 | imls, 1, 1, do_imls, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 537 | "list all images found in flash", |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 538 | "\n" |
Vipin Kumar | 3df41b1 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 539 | " - Prints information about all images found at sector/block\n" |
| 540 | " boundaries in nor/nand flash." |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 541 | ); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 542 | #endif |
| 543 | |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 544 | #ifdef CONFIG_CMD_BOOTZ |
| 545 | |
Simon Glass | 5f1afdd | 2013-07-04 13:26:10 -0700 | [diff] [blame] | 546 | int __weak bootz_setup(ulong image, ulong *start, ulong *end) |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 547 | { |
| 548 | /* Please define bootz_setup() for your platform */ |
| 549 | |
| 550 | puts("Your platform's zImage format isn't supported yet!\n"); |
| 551 | return -1; |
| 552 | } |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 553 | |
| 554 | /* |
| 555 | * zImage booting support |
| 556 | */ |
| 557 | static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc, |
| 558 | char * const argv[], bootm_headers_t *images) |
| 559 | { |
| 560 | int ret; |
Simon Glass | 5f1afdd | 2013-07-04 13:26:10 -0700 | [diff] [blame] | 561 | ulong zi_start, zi_end; |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 562 | |
Simon Glass | 3081e2e | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 563 | ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, |
| 564 | images, 1); |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 565 | |
| 566 | /* Setup Linux kernel zImage entry point */ |
Tom Rini | 6e5dac4 | 2013-07-09 15:32:34 -0400 | [diff] [blame] | 567 | if (!argc) { |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 568 | images->ep = load_addr; |
| 569 | debug("* kernel: default image load address = 0x%08lx\n", |
| 570 | load_addr); |
| 571 | } else { |
Tom Rini | 6e5dac4 | 2013-07-09 15:32:34 -0400 | [diff] [blame] | 572 | images->ep = simple_strtoul(argv[0], NULL, 16); |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 573 | debug("* kernel: cmdline image address = 0x%08lx\n", |
| 574 | images->ep); |
| 575 | } |
| 576 | |
Simon Glass | 5f1afdd | 2013-07-04 13:26:10 -0700 | [diff] [blame] | 577 | ret = bootz_setup(images->ep, &zi_start, &zi_end); |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 578 | if (ret != 0) |
| 579 | return 1; |
| 580 | |
| 581 | lmb_reserve(&images->lmb, images->ep, zi_end - zi_start); |
| 582 | |
Tom Rini | 1ab6147 | 2013-07-09 15:33:25 -0400 | [diff] [blame] | 583 | /* |
| 584 | * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not |
| 585 | * have a header that provide this informaiton. |
| 586 | */ |
Karl Apsite | d686ce9 | 2015-05-21 09:52:49 -0400 | [diff] [blame] | 587 | if (bootm_find_images(flag, argc, argv)) |
Tom Rini | 6e5dac4 | 2013-07-09 15:32:34 -0400 | [diff] [blame] | 588 | return 1; |
| 589 | |
Tom Rini | 6e5dac4 | 2013-07-09 15:32:34 -0400 | [diff] [blame] | 590 | return 0; |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Rob Herring | c88e1bf | 2012-12-02 21:00:23 -0600 | [diff] [blame] | 593 | int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 594 | { |
Simon Glass | 3081e2e | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 595 | int ret; |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 596 | |
Tom Rini | 6e5dac4 | 2013-07-09 15:32:34 -0400 | [diff] [blame] | 597 | /* Consume 'bootz' */ |
| 598 | argc--; argv++; |
| 599 | |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 600 | if (bootz_start(cmdtp, flag, argc, argv, &images)) |
| 601 | return 1; |
| 602 | |
Simon Glass | 917f684 | 2013-07-04 13:26:08 -0700 | [diff] [blame] | 603 | /* |
| 604 | * We are doing the BOOTM_STATE_LOADOS state ourselves, so must |
| 605 | * disable interrupts ourselves |
| 606 | */ |
| 607 | bootm_disable_interrupts(); |
| 608 | |
Simon Glass | 42bca36 | 2013-07-04 13:26:11 -0700 | [diff] [blame] | 609 | images.os.os = IH_OS_LINUX; |
Simon Glass | 3081e2e | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 610 | ret = do_bootm_states(cmdtp, flag, argc, argv, |
Simon Glass | 42bca36 | 2013-07-04 13:26:11 -0700 | [diff] [blame] | 611 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
| 612 | BOOTM_STATE_OS_GO, |
Simon Glass | 0013488 | 2013-06-11 11:14:48 -0700 | [diff] [blame] | 613 | &images, 1); |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 614 | |
Simon Glass | 3081e2e | 2013-06-11 11:14:47 -0700 | [diff] [blame] | 615 | return ret; |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 618 | #ifdef CONFIG_SYS_LONGHELP |
| 619 | static char bootz_help_text[] = |
Marek Vasut | 28850d0 | 2012-03-18 11:47:58 +0000 | [diff] [blame] | 620 | "[addr [initrd[:size]] [fdt]]\n" |
| 621 | " - boot Linux zImage stored in memory\n" |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 622 | "\tThe argument 'initrd' is optional and specifies the address\n" |
Marek Vasut | 28850d0 | 2012-03-18 11:47:58 +0000 | [diff] [blame] | 623 | "\tof the initrd in memory. The optional argument ':size' allows\n" |
| 624 | "\tspecifying the size of RAW initrd.\n" |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 625 | #if defined(CONFIG_OF_LIBFDT) |
| 626 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
| 627 | "\ta third argument is required which is the address of the\n" |
| 628 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 629 | "\tuse a '-' for the second argument. If you do not pass a third\n" |
| 630 | "\ta bd_info struct will be passed instead\n" |
| 631 | #endif |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 632 | ""; |
| 633 | #endif |
| 634 | |
| 635 | U_BOOT_CMD( |
| 636 | bootz, CONFIG_SYS_MAXARGS, 1, do_bootz, |
| 637 | "boot Linux zImage image from memory", bootz_help_text |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 638 | ); |
| 639 | #endif /* CONFIG_CMD_BOOTZ */ |
Tom Rini | 5ce62cd | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 640 | |
| 641 | #ifdef CONFIG_CMD_BOOTI |
| 642 | /* See Documentation/arm64/booting.txt in the Linux kernel */ |
| 643 | struct Image_header { |
| 644 | uint32_t code0; /* Executable code */ |
| 645 | uint32_t code1; /* Executable code */ |
| 646 | uint64_t text_offset; /* Image load offset, LE */ |
| 647 | uint64_t image_size; /* Effective Image size, LE */ |
| 648 | uint64_t res1; /* reserved */ |
| 649 | uint64_t res2; /* reserved */ |
| 650 | uint64_t res3; /* reserved */ |
| 651 | uint64_t res4; /* reserved */ |
| 652 | uint32_t magic; /* Magic number */ |
| 653 | uint32_t res5; |
| 654 | }; |
| 655 | |
| 656 | #define LINUX_ARM64_IMAGE_MAGIC 0x644d5241 |
| 657 | |
| 658 | static int booti_setup(bootm_headers_t *images) |
| 659 | { |
| 660 | struct Image_header *ih; |
| 661 | uint64_t dst; |
Andre Przywara | 92d5301 | 2016-05-25 09:48:14 +0100 | [diff] [blame] | 662 | uint64_t image_size; |
Tom Rini | 5ce62cd | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 663 | |
| 664 | ih = (struct Image_header *)map_sysmem(images->ep, 0); |
| 665 | |
| 666 | if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) { |
| 667 | puts("Bad Linux ARM64 Image magic!\n"); |
| 668 | return 1; |
| 669 | } |
| 670 | |
| 671 | if (ih->image_size == 0) { |
| 672 | puts("Image lacks image_size field, assuming 16MiB\n"); |
Andre Przywara | 92d5301 | 2016-05-25 09:48:14 +0100 | [diff] [blame] | 673 | image_size = 16 << 20; |
| 674 | } else { |
| 675 | image_size = le64_to_cpu(ih->image_size); |
Tom Rini | 5ce62cd | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /* |
| 679 | * If we are not at the correct run-time location, set the new |
| 680 | * correct location and then move the image there. |
| 681 | */ |
Andre Przywara | 92d5301 | 2016-05-25 09:48:14 +0100 | [diff] [blame] | 682 | dst = gd->bd->bi_dram[0].start + le64_to_cpu(ih->text_offset); |
Masahiro Yamada | 729e677 | 2016-03-29 19:51:57 +0900 | [diff] [blame] | 683 | |
| 684 | unmap_sysmem(ih); |
| 685 | |
Tom Rini | 5ce62cd | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 686 | if (images->ep != dst) { |
| 687 | void *src; |
| 688 | |
| 689 | debug("Moving Image from 0x%lx to 0x%llx\n", images->ep, dst); |
| 690 | |
| 691 | src = (void *)images->ep; |
| 692 | images->ep = dst; |
Andre Przywara | 92d5301 | 2016-05-25 09:48:14 +0100 | [diff] [blame] | 693 | memmove((void *)dst, src, image_size); |
Tom Rini | 5ce62cd | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | /* |
| 700 | * Image booting support |
| 701 | */ |
| 702 | static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, |
| 703 | char * const argv[], bootm_headers_t *images) |
| 704 | { |
| 705 | int ret; |
| 706 | struct Image_header *ih; |
| 707 | |
| 708 | ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, |
| 709 | images, 1); |
| 710 | |
| 711 | /* Setup Linux kernel Image entry point */ |
| 712 | if (!argc) { |
| 713 | images->ep = load_addr; |
| 714 | debug("* kernel: default image load address = 0x%08lx\n", |
| 715 | load_addr); |
| 716 | } else { |
| 717 | images->ep = simple_strtoul(argv[0], NULL, 16); |
| 718 | debug("* kernel: cmdline image address = 0x%08lx\n", |
| 719 | images->ep); |
| 720 | } |
| 721 | |
| 722 | ret = booti_setup(images); |
| 723 | if (ret != 0) |
| 724 | return 1; |
| 725 | |
| 726 | ih = (struct Image_header *)map_sysmem(images->ep, 0); |
| 727 | |
| 728 | lmb_reserve(&images->lmb, images->ep, le32_to_cpu(ih->image_size)); |
| 729 | |
Masahiro Yamada | 729e677 | 2016-03-29 19:51:57 +0900 | [diff] [blame] | 730 | unmap_sysmem(ih); |
| 731 | |
Tom Rini | 5ce62cd | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 732 | /* |
| 733 | * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not |
| 734 | * have a header that provide this informaiton. |
| 735 | */ |
Karl Apsite | d686ce9 | 2015-05-21 09:52:49 -0400 | [diff] [blame] | 736 | if (bootm_find_images(flag, argc, argv)) |
Tom Rini | 5ce62cd | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 737 | return 1; |
| 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 743 | { |
| 744 | int ret; |
| 745 | |
| 746 | /* Consume 'booti' */ |
| 747 | argc--; argv++; |
| 748 | |
| 749 | if (booti_start(cmdtp, flag, argc, argv, &images)) |
| 750 | return 1; |
| 751 | |
| 752 | /* |
| 753 | * We are doing the BOOTM_STATE_LOADOS state ourselves, so must |
| 754 | * disable interrupts ourselves |
| 755 | */ |
| 756 | bootm_disable_interrupts(); |
| 757 | |
| 758 | images.os.os = IH_OS_LINUX; |
| 759 | ret = do_bootm_states(cmdtp, flag, argc, argv, |
| 760 | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | |
| 761 | BOOTM_STATE_OS_GO, |
| 762 | &images, 1); |
| 763 | |
| 764 | return ret; |
| 765 | } |
| 766 | |
| 767 | #ifdef CONFIG_SYS_LONGHELP |
| 768 | static char booti_help_text[] = |
| 769 | "[addr [initrd[:size]] [fdt]]\n" |
Karsten Merker | e90e021 | 2016-02-22 20:59:08 +0100 | [diff] [blame] | 770 | " - boot arm64 Linux Image stored in memory\n" |
Tom Rini | 5ce62cd | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 771 | "\tThe argument 'initrd' is optional and specifies the address\n" |
Karsten Merker | e90e021 | 2016-02-22 20:59:08 +0100 | [diff] [blame] | 772 | "\tof an initrd in memory. The optional parameter ':size' allows\n" |
| 773 | "\tspecifying the size of a RAW initrd.\n" |
Tom Rini | 5ce62cd | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 774 | #if defined(CONFIG_OF_LIBFDT) |
Karsten Merker | e90e021 | 2016-02-22 20:59:08 +0100 | [diff] [blame] | 775 | "\tSince booting a Linux kernel requires a flat device-tree, a\n" |
| 776 | "\tthird argument providing the address of the device-tree blob\n" |
| 777 | "\tis required. To boot a kernel with a device-tree blob but\n" |
| 778 | "\twithout an initrd image, use a '-' for the initrd argument.\n" |
Tom Rini | 5ce62cd | 2014-08-14 06:42:36 -0400 | [diff] [blame] | 779 | #endif |
| 780 | ""; |
| 781 | #endif |
| 782 | |
| 783 | U_BOOT_CMD( |
| 784 | booti, CONFIG_SYS_MAXARGS, 1, do_booti, |
| 785 | "boot arm64 Linux Image image from memory", booti_help_text |
| 786 | ); |
| 787 | #endif /* CONFIG_CMD_BOOTI */ |