wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1 | /* |
Stefan Roese | 15940c9 | 2006-03-13 11:16:36 +0100 | [diff] [blame] | 2 | * (C) Copyright 2000-2006 |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 24 | #define DEBUG |
| 25 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 26 | /* |
| 27 | * Boot support |
| 28 | */ |
| 29 | #include <common.h> |
| 30 | #include <watchdog.h> |
| 31 | #include <command.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 32 | #include <image.h> |
| 33 | #include <malloc.h> |
| 34 | #include <zlib.h> |
wdenk | c29fdfc | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 35 | #include <bzlib.h> |
wdenk | 7f70e85 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 36 | #include <environment.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 37 | #include <asm/byteorder.h> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 38 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 39 | #ifdef CFG_HUSH_PARSER |
| 40 | #include <hush.h> |
| 41 | #endif |
| 42 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 43 | DECLARE_GLOBAL_DATA_PTR; |
| 44 | |
| 45 | extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp); |
| 46 | #ifndef CFG_BOOTM_LEN |
| 47 | #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */ |
| 48 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 49 | |
Marian Balakowicz | 321359f | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 50 | #ifdef CONFIG_BZIP2 |
| 51 | extern void bz_internal_error(int); |
| 52 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 53 | |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 54 | #if defined(CONFIG_CMD_IMI) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 55 | static int image_info (unsigned long addr); |
| 56 | #endif |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 57 | |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 58 | #if defined(CONFIG_CMD_IMLS) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 59 | #include <flash.h> |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 60 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 61 | static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 62 | #endif |
| 63 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 64 | #ifdef CONFIG_SILENT_CONSOLE |
| 65 | static void fixup_silent_linux (void); |
| 66 | #endif |
| 67 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 68 | static void *get_kernel (cmd_tbl_t *cmdtp, int flag, |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 69 | int argc, char *argv[], int verify, |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 70 | bootm_headers_t *images, |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 71 | ulong *os_data, ulong *os_len); |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 72 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * Continue booting an OS image; caller already has: |
| 76 | * - copied image header to global variable `header' |
| 77 | * - checked header magic number, checksums (both header & image), |
| 78 | * - verified image architecture (PPC) and type (KERNEL or MULTI), |
| 79 | * - loaded (first part of) image to header load address, |
| 80 | * - disabled interrupts. |
| 81 | */ |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 82 | typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag, |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 83 | int argc, char *argv[], |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 84 | bootm_headers_t *images,/* pointers to os/initrd/fdt */ |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 85 | int verify); /* getenv("verify")[0] != 'n' */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 86 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 87 | extern boot_os_fn do_bootm_linux; |
| 88 | static boot_os_fn do_bootm_netbsd; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 89 | #if defined(CONFIG_LYNXKDI) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 90 | static boot_os_fn do_bootm_lynxkdi; |
| 91 | extern void lynxkdi_boot (image_header_t *); |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 92 | #endif |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 93 | static boot_os_fn do_bootm_rtems; |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 94 | #if defined(CONFIG_CMD_ELF) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 95 | static boot_os_fn do_bootm_vxworks; |
| 96 | static boot_os_fn do_bootm_qnxelf; |
| 97 | int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 98 | int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 99 | #endif |
wdenk | 7f70e85 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 100 | #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 101 | extern uchar (*env_get_char)(int); /* Returns a character from the environment */ |
| 102 | static boot_os_fn do_bootm_artos; |
Stefan Roese | 15940c9 | 2006-03-13 11:16:36 +0100 | [diff] [blame] | 103 | #endif |
| 104 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 105 | ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 106 | static bootm_headers_t images; /* pointers to os/initrd/fdt images */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 107 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 108 | |
| 109 | /*******************************************************************/ |
| 110 | /* bootm - boot application image from image in memory */ |
| 111 | /*******************************************************************/ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 112 | int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 113 | { |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 114 | ulong iflag; |
Marian Balakowicz | 42b73e8 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 115 | const char *type_name; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 116 | uint unc_len = CFG_BOOTM_LEN; |
| 117 | int verify = getenv_verify(); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 118 | uint8_t comp, type, os; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 119 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 120 | void *os_hdr; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 121 | ulong os_data, os_len; |
Marian Balakowicz | 7582438 | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 122 | ulong image_start, image_end; |
| 123 | ulong load_start, load_end; |
| 124 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 125 | memset ((void *)&images, 0, sizeof (images)); |
| 126 | |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 127 | /* get kernel image header, start address and length */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 128 | os_hdr = get_kernel (cmdtp, flag, argc, argv, verify, |
| 129 | &images, &os_data, &os_len); |
| 130 | if (os_len == 0) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 131 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 132 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 133 | show_boot_progress (6); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 134 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 135 | /* get image parameters */ |
| 136 | switch (gen_image_get_format (os_hdr)) { |
| 137 | case IMAGE_FORMAT_LEGACY: |
| 138 | type = image_get_type (os_hdr); |
| 139 | comp = image_get_comp (os_hdr); |
| 140 | os = image_get_os (os_hdr); |
| 141 | |
| 142 | image_end = image_get_image_end (os_hdr); |
| 143 | load_start = image_get_load (os_hdr); |
| 144 | break; |
| 145 | #if defined(CONFIG_FIT) |
| 146 | case IMAGE_FORMAT_FIT: |
| 147 | fit_unsupported ("bootm"); |
| 148 | return 1; |
| 149 | #endif |
| 150 | default: |
| 151 | puts ("ERROR: unknown image format type!\n"); |
| 152 | return 1; |
| 153 | } |
| 154 | |
| 155 | image_start = (ulong)os_hdr; |
| 156 | load_end = 0; |
| 157 | type_name = image_get_type_name (type); |
| 158 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 159 | /* |
| 160 | * We have reached the point of no return: we are going to |
| 161 | * overwrite all exception vector code, so we cannot easily |
| 162 | * recover from any failures any more... |
| 163 | */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 164 | iflag = disable_interrupts(); |
| 165 | |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 166 | #ifdef CONFIG_AMIGAONEG3SE |
| 167 | /* |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 168 | * We've possible left the caches enabled during |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 169 | * bios emulation, so turn them off again |
| 170 | */ |
| 171 | icache_disable(); |
| 172 | invalidate_l1_instruction_cache(); |
| 173 | flush_data_cache(); |
| 174 | dcache_disable(); |
| 175 | #endif |
| 176 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 177 | switch (comp) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 178 | case IH_COMP_NONE: |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 179 | if (load_start == (ulong)os_hdr) { |
Marian Balakowicz | 42b73e8 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 180 | printf (" XIP %s ... ", type_name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 181 | } else { |
Marian Balakowicz | 42b73e8 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 182 | printf (" Loading %s ... ", type_name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 183 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 184 | memmove_wd ((void *)load_start, |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 185 | (void *)os_data, os_len, CHUNKSZ); |
Marian Balakowicz | af13cdb | 2008-01-08 18:11:45 +0100 | [diff] [blame] | 186 | |
Marian Balakowicz | 7582438 | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 187 | load_end = load_start + os_len; |
Marian Balakowicz | af13cdb | 2008-01-08 18:11:45 +0100 | [diff] [blame] | 188 | puts("OK\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 189 | } |
| 190 | break; |
| 191 | case IH_COMP_GZIP: |
Marian Balakowicz | 42b73e8 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 192 | printf (" Uncompressing %s ... ", type_name); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 193 | if (gunzip ((void *)load_start, unc_len, |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 194 | (uchar *)os_data, &os_len) != 0) { |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 195 | puts ("GUNZIP ERROR - must RESET board to recover\n"); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 196 | show_boot_progress (-6); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 197 | do_reset (cmdtp, flag, argc, argv); |
| 198 | } |
Marian Balakowicz | 7582438 | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 199 | |
| 200 | load_end = load_start + os_len; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 201 | break; |
wdenk | c29fdfc | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 202 | #ifdef CONFIG_BZIP2 |
| 203 | case IH_COMP_BZIP2: |
Marian Balakowicz | 42b73e8 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 204 | printf (" Uncompressing %s ... ", type_name); |
wdenk | 5653fc3 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 205 | /* |
| 206 | * If we've got less than 4 MB of malloc() space, |
| 207 | * use slower decompression algorithm which requires |
| 208 | * at most 2300 KB of memory. |
| 209 | */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 210 | int i = BZ2_bzBuffToBuffDecompress ((char*)load_start, |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 211 | &unc_len, (char *)os_data, os_len, |
| 212 | CFG_MALLOC_LEN < (4096 * 1024), 0); |
wdenk | c29fdfc | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 213 | if (i != BZ_OK) { |
| 214 | printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 215 | show_boot_progress (-6); |
wdenk | c29fdfc | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 216 | do_reset (cmdtp, flag, argc, argv); |
| 217 | } |
Marian Balakowicz | 7582438 | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 218 | |
| 219 | load_end = load_start + unc_len; |
wdenk | c29fdfc | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 220 | break; |
| 221 | #endif /* CONFIG_BZIP2 */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 222 | default: |
| 223 | if (iflag) |
| 224 | enable_interrupts(); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 225 | printf ("Unimplemented compression type %d\n", comp); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 226 | show_boot_progress (-7); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 227 | return 1; |
| 228 | } |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 229 | puts ("OK\n"); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 230 | debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 231 | show_boot_progress (7); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 232 | |
Marian Balakowicz | 7582438 | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 233 | if ((load_start < image_end) && (load_end > image_start)) { |
| 234 | debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end); |
| 235 | debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end); |
| 236 | |
| 237 | puts ("ERROR: image overwritten - must RESET the board to recover.\n"); |
| 238 | do_reset (cmdtp, flag, argc, argv); |
| 239 | } |
| 240 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 241 | show_boot_progress (8); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 242 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 243 | switch (os) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 244 | default: /* handled by (original) Linux case */ |
| 245 | case IH_OS_LINUX: |
wdenk | f72da34 | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 246 | #ifdef CONFIG_SILENT_CONSOLE |
| 247 | fixup_silent_linux(); |
| 248 | #endif |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 249 | do_bootm_linux (cmdtp, flag, argc, argv, &images, verify); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 250 | break; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 251 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 252 | case IH_OS_NETBSD: |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 253 | do_bootm_netbsd (cmdtp, flag, argc, argv, &images, verify); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 254 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 255 | |
wdenk | 1f4bb37 | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 256 | #ifdef CONFIG_LYNXKDI |
| 257 | case IH_OS_LYNXOS: |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 258 | do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images, verify); |
wdenk | 1f4bb37 | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 259 | break; |
| 260 | #endif |
| 261 | |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 262 | case IH_OS_RTEMS: |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 263 | do_bootm_rtems (cmdtp, flag, argc, argv, &images, verify); |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 264 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 265 | |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 266 | #if defined(CONFIG_CMD_ELF) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 267 | case IH_OS_VXWORKS: |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 268 | do_bootm_vxworks (cmdtp, flag, argc, argv, &images, verify); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 269 | break; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 270 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 271 | case IH_OS_QNX: |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 272 | do_bootm_qnxelf (cmdtp, flag, argc, argv, &images, verify); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 273 | break; |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 274 | #endif |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 275 | |
wdenk | 7f70e85 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 276 | #ifdef CONFIG_ARTOS |
| 277 | case IH_OS_ARTOS: |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 278 | do_bootm_artos (cmdtp, flag, argc, argv, &images, verify); |
wdenk | 7f70e85 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 279 | break; |
| 280 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 283 | show_boot_progress (-9); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 284 | #ifdef DEBUG |
wdenk | 4b9206e | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 285 | puts ("\n## Control returned to monitor - resetting...\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 286 | do_reset (cmdtp, flag, argc, argv); |
| 287 | #endif |
| 288 | return 1; |
| 289 | } |
| 290 | |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 291 | /** |
| 292 | * get_kernel - find kernel image |
| 293 | * @os_data: pointer to a ulong variable, will hold os data start address |
| 294 | * @os_len: pointer to a ulong variable, will hold os data length |
| 295 | * |
| 296 | * get_kernel() tries to find a kernel image, verifies its integrity |
| 297 | * and locates kernel data. |
| 298 | * |
| 299 | * returns: |
| 300 | * pointer to image header if valid image was found, plus kernel start |
| 301 | * address and length, otherwise NULL |
| 302 | */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 303 | static void *get_kernel (cmd_tbl_t *cmdtp, int flag, |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 304 | int argc, char *argv[], int verify, |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 305 | bootm_headers_t *images, |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 306 | ulong *os_data, ulong *os_len) |
| 307 | { |
| 308 | image_header_t *hdr; |
| 309 | ulong img_addr; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 310 | #if defined(CONFIG_FIT) |
| 311 | void *fit_hdr; |
| 312 | const char *fit_uname_config = NULL; |
| 313 | const char *fit_uname_kernel = NULL; |
| 314 | #endif |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 315 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 316 | /* find out kernel image address */ |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 317 | if (argc < 2) { |
| 318 | img_addr = load_addr; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 319 | debug ("* kernel: default image load address = 0x%08lx\n", |
| 320 | load_addr); |
| 321 | #if defined(CONFIG_FIT) |
| 322 | } else if (fit_parse_conf (argv[1], load_addr, &img_addr, |
| 323 | &fit_uname_config)) { |
| 324 | debug ("* kernel: config '%s' from image at 0x%08lx\n", |
| 325 | fit_uname_config, img_addr); |
| 326 | } else if (fit_parse_subimage (argv[1], load_addr, &img_addr, |
| 327 | &fit_uname_kernel)) { |
| 328 | debug ("* kernel: subimage '%s' from image at 0x%08lx\n", |
| 329 | fit_uname_kernel, img_addr); |
| 330 | #endif |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 331 | } else { |
| 332 | img_addr = simple_strtoul(argv[1], NULL, 16); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 333 | debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | show_boot_progress (1); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 337 | printf ("## Booting kernel image at %08lx ...\n", img_addr); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 338 | |
Marian Balakowicz | fff888a1 | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 339 | /* copy from dataflash if needed */ |
| 340 | img_addr = gen_get_image (img_addr); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 341 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 342 | /* check image type, for FIT images get FIT kernel node */ |
| 343 | switch (gen_image_get_format ((void *)img_addr)) { |
| 344 | case IMAGE_FORMAT_LEGACY: |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 345 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 346 | debug ("* kernel: legacy format image\n"); |
| 347 | hdr = (image_header_t *)img_addr; |
Marian Balakowicz | fff888a1 | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 348 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 349 | if (!image_check_magic(hdr)) { |
| 350 | puts ("Bad Magic Number\n"); |
| 351 | show_boot_progress (-1); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 352 | return NULL; |
| 353 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 354 | show_boot_progress (2); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 355 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 356 | if (!image_check_hcrc (hdr)) { |
| 357 | puts ("Bad Header Checksum\n"); |
| 358 | show_boot_progress (-2); |
| 359 | return NULL; |
| 360 | } |
| 361 | |
| 362 | show_boot_progress (3); |
| 363 | image_print_contents (hdr); |
| 364 | |
| 365 | if (verify) { |
| 366 | puts (" Verifying Checksum ... "); |
| 367 | if (!image_check_dcrc (hdr)) { |
| 368 | printf ("Bad Data CRC\n"); |
| 369 | show_boot_progress (-3); |
| 370 | return NULL; |
| 371 | } |
| 372 | puts ("OK\n"); |
| 373 | } |
| 374 | show_boot_progress (4); |
| 375 | |
| 376 | if (!image_check_target_arch (hdr)) { |
| 377 | printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr)); |
| 378 | show_boot_progress (-4); |
| 379 | return NULL; |
| 380 | } |
| 381 | show_boot_progress (5); |
| 382 | |
| 383 | switch (image_get_type (hdr)) { |
| 384 | case IH_TYPE_KERNEL: |
| 385 | *os_data = image_get_data (hdr); |
| 386 | *os_len = image_get_data_size (hdr); |
| 387 | break; |
| 388 | case IH_TYPE_MULTI: |
| 389 | image_multi_getimg (hdr, 0, os_data, os_len); |
| 390 | break; |
| 391 | default: |
| 392 | printf ("Wrong Image Type for %s command\n", cmdtp->name); |
| 393 | show_boot_progress (-5); |
| 394 | return NULL; |
| 395 | } |
| 396 | images->legacy_hdr_os = hdr; |
| 397 | images->legacy_hdr_valid = 1; |
| 398 | |
| 399 | break; |
| 400 | #if defined(CONFIG_FIT) |
| 401 | case IMAGE_FORMAT_FIT: |
| 402 | fit_hdr = (void *)img_addr; |
| 403 | debug ("* kernel: FIT format image\n"); |
| 404 | fit_unsupported ("kernel"); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 405 | return NULL; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 406 | #endif |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 407 | default: |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 408 | printf ("Wrong Image Format for %s command\n", cmdtp->name); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 409 | return NULL; |
| 410 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 411 | |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 412 | debug (" kernel data at 0x%08lx, end = 0x%08lx\n", |
| 413 | *os_data, *os_data + *os_len); |
| 414 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 415 | return (void *)img_addr; |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 416 | } |
| 417 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 418 | U_BOOT_CMD( |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 419 | bootm, CFG_MAXARGS, 1, do_bootm, |
| 420 | "bootm - boot application image from memory\n", |
| 421 | "[addr [arg ...]]\n - boot application image stored in memory\n" |
| 422 | "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n" |
| 423 | "\t'arg' can be the address of an initrd image\n" |
Marian Balakowicz | 4a2ad5f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 424 | #if defined(CONFIG_OF_LIBFDT) |
Matthew McClintock | 98a9c4d | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 425 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
Detlev Zundel | 5441f61 | 2007-10-19 16:47:26 +0200 | [diff] [blame] | 426 | "\ta third argument is required which is the address of the\n" |
Matthew McClintock | 98a9c4d | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 427 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 428 | "\tuse a '-' for the second argument. If you do not pass a third\n" |
| 429 | "\ta bd_info struct will be passed instead\n" |
| 430 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 431 | ); |
| 432 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 433 | /*******************************************************************/ |
| 434 | /* bootd - boot default image */ |
| 435 | /*******************************************************************/ |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 436 | #if defined(CONFIG_CMD_BOOTD) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 437 | int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 438 | { |
| 439 | int rcode = 0; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 440 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 441 | #ifndef CFG_HUSH_PARSER |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 442 | if (run_command (getenv ("bootcmd"), flag) < 0) |
| 443 | rcode = 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 444 | #else |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 445 | if (parse_string_outer (getenv ("bootcmd"), |
| 446 | FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0) |
| 447 | rcode = 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 448 | #endif |
| 449 | return rcode; |
| 450 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 451 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 452 | U_BOOT_CMD( |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 453 | boot, 1, 1, do_bootd, |
| 454 | "boot - boot default, i.e., run 'bootcmd'\n", |
wdenk | 9d2b18a | 2003-06-28 23:11:04 +0000 | [diff] [blame] | 455 | NULL |
| 456 | ); |
| 457 | |
| 458 | /* keep old command name "bootd" for backward compatibility */ |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 459 | U_BOOT_CMD( |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 460 | bootd, 1, 1, do_bootd, |
| 461 | "bootd - boot default, i.e., run 'bootcmd'\n", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 462 | NULL |
| 463 | ); |
| 464 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 465 | #endif |
| 466 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 467 | |
| 468 | /*******************************************************************/ |
| 469 | /* iminfo - print header info for a requested image */ |
| 470 | /*******************************************************************/ |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 471 | #if defined(CONFIG_CMD_IMI) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 472 | int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 473 | { |
| 474 | int arg; |
| 475 | ulong addr; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 476 | int rcode = 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 477 | |
| 478 | if (argc < 2) { |
| 479 | return image_info (load_addr); |
| 480 | } |
| 481 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 482 | for (arg = 1; arg < argc; ++arg) { |
| 483 | addr = simple_strtoul (argv[arg], NULL, 16); |
| 484 | if (image_info (addr) != 0) |
| 485 | rcode = 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 486 | } |
| 487 | return rcode; |
| 488 | } |
| 489 | |
| 490 | static int image_info (ulong addr) |
| 491 | { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 492 | void *hdr = (void *)addr; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 493 | |
| 494 | printf ("\n## Checking Image at %08lx ...\n", addr); |
| 495 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 496 | switch (gen_image_get_format (hdr)) { |
| 497 | case IMAGE_FORMAT_LEGACY: |
| 498 | puts (" Legacy image found\n"); |
| 499 | if (!image_check_magic (hdr)) { |
| 500 | puts (" Bad Magic Number\n"); |
| 501 | return 1; |
| 502 | } |
| 503 | |
| 504 | if (!image_check_hcrc (hdr)) { |
| 505 | puts (" Bad Header Checksum\n"); |
| 506 | return 1; |
| 507 | } |
| 508 | |
| 509 | image_print_contents (hdr); |
| 510 | |
| 511 | puts (" Verifying Checksum ... "); |
| 512 | if (!image_check_dcrc (hdr)) { |
| 513 | puts (" Bad Data CRC\n"); |
| 514 | return 1; |
| 515 | } |
| 516 | puts ("OK\n"); |
| 517 | return 0; |
| 518 | #if defined(CONFIG_FIT) |
| 519 | case IMAGE_FORMAT_FIT: |
| 520 | puts (" FIT image found\n"); |
| 521 | fit_unsupported ("iminfo"); |
| 522 | return 0; |
| 523 | #endif |
| 524 | default: |
| 525 | puts ("Unknown image format!\n"); |
| 526 | break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 529 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 530 | } |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 531 | |
| 532 | U_BOOT_CMD( |
| 533 | iminfo, CFG_MAXARGS, 1, do_iminfo, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 534 | "iminfo - print header information for application image\n", |
| 535 | "addr [addr ...]\n" |
| 536 | " - print header information for application image starting at\n" |
| 537 | " address 'addr' in memory; this includes verification of the\n" |
| 538 | " image contents (magic number, header and payload checksums)\n" |
| 539 | ); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 540 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 541 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 542 | |
| 543 | /*******************************************************************/ |
| 544 | /* imls - list all images found in flash */ |
| 545 | /*******************************************************************/ |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 546 | #if defined(CONFIG_CMD_IMLS) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 547 | int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 548 | { |
| 549 | flash_info_t *info; |
| 550 | int i, j; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 551 | void *hdr; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 552 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 553 | for (i = 0, info = &flash_info[0]; |
| 554 | i < CFG_MAX_FLASH_BANKS; ++i, ++info) { |
| 555 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 556 | if (info->flash_id == FLASH_UNKNOWN) |
| 557 | goto next_bank; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 558 | for (j = 0; j < info->sector_count; ++j) { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 559 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 560 | hdr = (void *)info->start[j]; |
| 561 | if (!hdr) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 562 | goto next_sector; |
| 563 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 564 | switch (gen_image_get_format (hdr)) { |
| 565 | case IMAGE_FORMAT_LEGACY: |
| 566 | if (!image_check_magic (hdr)) |
| 567 | goto next_sector; |
| 568 | |
| 569 | if (!image_check_hcrc (hdr)) |
| 570 | goto next_sector; |
| 571 | |
| 572 | printf ("Legacy Image at %08lX:\n", (ulong)hdr); |
| 573 | image_print_contents (hdr); |
| 574 | |
| 575 | puts (" Verifying Checksum ... "); |
| 576 | if (!image_check_dcrc (hdr)) { |
| 577 | puts ("Bad Data CRC\n"); |
| 578 | } else { |
| 579 | puts ("OK\n"); |
| 580 | } |
| 581 | break; |
| 582 | #if defined(CONFIG_FIT) |
| 583 | case IMAGE_FORMAT_FIT: |
| 584 | printf ("FIT Image at %08lX:\n", (ulong)hdr); |
| 585 | fit_unsupported ("imls"); |
| 586 | break; |
| 587 | #endif |
| 588 | default: |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 589 | goto next_sector; |
wdenk | 5bb226e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 590 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 591 | |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 592 | next_sector: ; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 593 | } |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 594 | next_bank: ; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | return (0); |
| 598 | } |
| 599 | |
| 600 | U_BOOT_CMD( |
| 601 | imls, 1, 1, do_imls, |
| 602 | "imls - list all images found in flash\n", |
| 603 | "\n" |
| 604 | " - Prints information about all images found at sector\n" |
| 605 | " boundaries in flash.\n" |
| 606 | ); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 607 | #endif |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 608 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 609 | /*******************************************************************/ |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 610 | /* helper routines */ |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 611 | /*******************************************************************/ |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 612 | #ifdef CONFIG_SILENT_CONSOLE |
| 613 | static void fixup_silent_linux () |
| 614 | { |
| 615 | char buf[256], *start, *end; |
| 616 | char *cmdline = getenv ("bootargs"); |
| 617 | |
| 618 | /* Only fix cmdline when requested */ |
| 619 | if (!(gd->flags & GD_FLG_SILENT)) |
| 620 | return; |
| 621 | |
| 622 | debug ("before silent fix-up: %s\n", cmdline); |
| 623 | if (cmdline) { |
| 624 | if ((start = strstr (cmdline, "console=")) != NULL) { |
| 625 | end = strchr (start, ' '); |
| 626 | strncpy (buf, cmdline, (start - cmdline + 8)); |
| 627 | if (end) |
| 628 | strcpy (buf + (start - cmdline + 8), end); |
| 629 | else |
| 630 | buf[start - cmdline + 8] = '\0'; |
| 631 | } else { |
| 632 | strcpy (buf, cmdline); |
| 633 | strcat (buf, " console="); |
| 634 | } |
| 635 | } else { |
| 636 | strcpy (buf, "console="); |
| 637 | } |
| 638 | |
| 639 | setenv ("bootargs", buf); |
| 640 | debug ("after silent fix-up: %s\n", buf); |
| 641 | } |
| 642 | #endif /* CONFIG_SILENT_CONSOLE */ |
| 643 | |
| 644 | |
| 645 | /*******************************************************************/ |
| 646 | /* OS booting routines */ |
| 647 | /*******************************************************************/ |
| 648 | |
| 649 | static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag, |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 650 | int argc, char *argv[], |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 651 | bootm_headers_t *images, int verify) |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 652 | { |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 653 | void (*loader)(bd_t *, image_header_t *, char *, char *); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 654 | image_header_t *os_hdr, *hdr; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 655 | ulong kernel_data, kernel_len; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 656 | char *consdev; |
| 657 | char *cmdline; |
| 658 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 659 | #if defined(CONFIG_FIT) |
| 660 | if (!images->legacy_hdr_valid) { |
| 661 | fit_unsupported_reset ("NetBSD"); |
| 662 | do_reset (cmdtp, flag, argc, argv); |
| 663 | } |
| 664 | #endif |
| 665 | hdr = images->legacy_hdr_os; |
| 666 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 667 | /* |
| 668 | * Booting a (NetBSD) kernel image |
| 669 | * |
| 670 | * This process is pretty similar to a standalone application: |
| 671 | * The (first part of an multi-) image must be a stage-2 loader, |
| 672 | * which in turn is responsible for loading & invoking the actual |
| 673 | * kernel. The only differences are the parameters being passed: |
| 674 | * besides the board info strucure, the loader expects a command |
| 675 | * line, the name of the console device, and (optionally) the |
| 676 | * address of the original image header. |
| 677 | */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 678 | os_hdr = NULL; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 679 | if (image_check_type (hdr, IH_TYPE_MULTI)) { |
| 680 | image_multi_getimg (hdr, 1, &kernel_data, &kernel_len); |
| 681 | if (kernel_len) |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 682 | os_hdr = hdr; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 683 | } |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 684 | |
| 685 | consdev = ""; |
| 686 | #if defined (CONFIG_8xx_CONS_SMC1) |
| 687 | consdev = "smc1"; |
| 688 | #elif defined (CONFIG_8xx_CONS_SMC2) |
| 689 | consdev = "smc2"; |
| 690 | #elif defined (CONFIG_8xx_CONS_SCC2) |
| 691 | consdev = "scc2"; |
| 692 | #elif defined (CONFIG_8xx_CONS_SCC3) |
| 693 | consdev = "scc3"; |
| 694 | #endif |
| 695 | |
| 696 | if (argc > 2) { |
| 697 | ulong len; |
| 698 | int i; |
| 699 | |
| 700 | for (i = 2, len = 0; i < argc; i += 1) |
| 701 | len += strlen (argv[i]) + 1; |
| 702 | cmdline = malloc (len); |
| 703 | |
| 704 | for (i = 2, len = 0; i < argc; i += 1) { |
| 705 | if (i > 2) |
| 706 | cmdline[len++] = ' '; |
| 707 | strcpy (&cmdline[len], argv[i]); |
| 708 | len += strlen (argv[i]); |
| 709 | } |
| 710 | } else if ((cmdline = getenv ("bootargs")) == NULL) { |
| 711 | cmdline = ""; |
| 712 | } |
| 713 | |
| 714 | loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr); |
| 715 | |
| 716 | printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n", |
| 717 | (ulong)loader); |
| 718 | |
| 719 | show_boot_progress (15); |
| 720 | |
| 721 | /* |
| 722 | * NetBSD Stage-2 Loader Parameters: |
| 723 | * r3: ptr to board info data |
| 724 | * r4: image address |
| 725 | * r5: console device |
| 726 | * r6: boot args string |
| 727 | */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 728 | (*loader) (gd->bd, os_hdr, consdev, cmdline); |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | #ifdef CONFIG_LYNXKDI |
| 732 | static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag, |
| 733 | int argc, char *argv[], |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 734 | bootm_headers_t *images, int verify) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 735 | { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 736 | image_header_t *hdr = images->legacy_hdr_os; |
| 737 | |
| 738 | #if defined(CONFIG_FIT) |
| 739 | if (!images->legacy_hdr_valid) { |
| 740 | fit_unsupported_reset ("Lynx"); |
| 741 | do_reset (cmdtp, flag, argc, argv); |
| 742 | } |
| 743 | #endif |
| 744 | |
| 745 | lynxkdi_boot ((image_header_t *)hdr); |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 746 | } |
| 747 | #endif /* CONFIG_LYNXKDI */ |
| 748 | |
| 749 | static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, |
| 750 | int argc, char *argv[], |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 751 | bootm_headers_t *images, int verify) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 752 | { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 753 | image_header_t *hdr = images->legacy_hdr_os; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 754 | void (*entry_point)(bd_t *); |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 755 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 756 | #if defined(CONFIG_FIT) |
| 757 | if (!images->legacy_hdr_valid) { |
| 758 | fit_unsupported_reset ("RTEMS"); |
| 759 | do_reset (cmdtp, flag, argc, argv); |
| 760 | } |
| 761 | #endif |
| 762 | |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 763 | entry_point = (void (*)(bd_t *))image_get_ep (hdr); |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 764 | |
| 765 | printf ("## Transferring control to RTEMS (at address %08lx) ...\n", |
| 766 | (ulong)entry_point); |
| 767 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 768 | show_boot_progress (15); |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 769 | |
| 770 | /* |
| 771 | * RTEMS Parameters: |
| 772 | * r3: ptr to board info data |
| 773 | */ |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 774 | (*entry_point)(gd->bd); |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 775 | } |
| 776 | |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 777 | #if defined(CONFIG_CMD_ELF) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 778 | static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, |
| 779 | int argc, char *argv[], |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 780 | bootm_headers_t *images, int verify) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 781 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 782 | char str[80]; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 783 | image_header_t *hdr = images->legacy_hdr_os; |
| 784 | |
| 785 | #if defined(CONFIG_FIT) |
| 786 | if (hdr == NULL) { |
| 787 | fit_unsupported_reset ("VxWorks"); |
| 788 | do_reset (cmdtp, flag, argc, argv); |
| 789 | } |
| 790 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 791 | |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 792 | sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 793 | setenv("loadaddr", str); |
| 794 | do_bootvx(cmdtp, 0, 0, NULL); |
| 795 | } |
| 796 | |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 797 | static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag, |
| 798 | int argc, char *argv[], |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 799 | bootm_headers_t *images, int verify) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 800 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 801 | char *local_args[2]; |
| 802 | char str[16]; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 803 | image_header_t *hdr = images->legacy_hdr_os; |
| 804 | |
| 805 | #if defined(CONFIG_FIT) |
| 806 | if (!images->legacy_hdr_valid) { |
| 807 | fit_unsupported_reset ("QNX"); |
| 808 | do_reset (cmdtp, flag, argc, argv); |
| 809 | } |
| 810 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 811 | |
Marian Balakowicz | b97a2a0 | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 812 | sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 813 | local_args[0] = argv[0]; |
| 814 | local_args[1] = str; /* and provide it via the arguments */ |
| 815 | do_bootelf(cmdtp, 0, 2, local_args); |
| 816 | } |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 817 | #endif |
wdenk | 1f4bb37 | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 818 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 819 | #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) |
| 820 | static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag, |
| 821 | int argc, char *argv[], |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 822 | bootm_headers_t *images, int verify) |
wdenk | 1f4bb37 | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 823 | { |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 824 | ulong top; |
| 825 | char *s, *cmdline; |
| 826 | char **fwenv, **ss; |
| 827 | int i, j, nxt, len, envno, envsz; |
| 828 | bd_t *kbd; |
| 829 | void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame^] | 830 | image_header_t *hdr = images->legacy_hdr_os; |
| 831 | |
| 832 | #if defined(CONFIG_FIT) |
| 833 | if (!images->legacy_hdr_valid) { |
| 834 | fit_unsupported_reset ("ARTOS"); |
| 835 | do_reset (cmdtp, flag, argc, argv); |
| 836 | } |
| 837 | #endif |
wdenk | 1f4bb37 | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 838 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 839 | /* |
| 840 | * Booting an ARTOS kernel image + application |
| 841 | */ |
| 842 | |
| 843 | /* this used to be the top of memory, but was wrong... */ |
| 844 | #ifdef CONFIG_PPC |
| 845 | /* get stack pointer */ |
| 846 | asm volatile ("mr %0,1" : "=r"(top) ); |
| 847 | #endif |
| 848 | debug ("## Current stack ends at 0x%08lX ", top); |
| 849 | |
| 850 | top -= 2048; /* just to be sure */ |
| 851 | if (top > CFG_BOOTMAPSZ) |
| 852 | top = CFG_BOOTMAPSZ; |
| 853 | top &= ~0xF; |
| 854 | |
| 855 | debug ("=> set upper limit to 0x%08lX\n", top); |
| 856 | |
| 857 | /* first check the artos specific boot args, then the linux args*/ |
| 858 | if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL) |
| 859 | s = ""; |
| 860 | |
| 861 | /* get length of cmdline, and place it */ |
| 862 | len = strlen (s); |
| 863 | top = (top - (len + 1)) & ~0xF; |
| 864 | cmdline = (char *)top; |
| 865 | debug ("## cmdline at 0x%08lX ", top); |
| 866 | strcpy (cmdline, s); |
| 867 | |
| 868 | /* copy bdinfo */ |
| 869 | top = (top - sizeof (bd_t)) & ~0xF; |
| 870 | debug ("## bd at 0x%08lX ", top); |
| 871 | kbd = (bd_t *)top; |
| 872 | memcpy (kbd, gd->bd, sizeof (bd_t)); |
| 873 | |
| 874 | /* first find number of env entries, and their size */ |
| 875 | envno = 0; |
| 876 | envsz = 0; |
| 877 | for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) { |
| 878 | for (nxt = i; env_get_char (nxt) != '\0'; ++nxt) |
| 879 | ; |
| 880 | envno++; |
| 881 | envsz += (nxt - i) + 1; /* plus trailing zero */ |
| 882 | } |
| 883 | envno++; /* plus the terminating zero */ |
| 884 | debug ("## %u envvars total size %u ", envno, envsz); |
| 885 | |
| 886 | top = (top - sizeof (char **) * envno) & ~0xF; |
| 887 | fwenv = (char **)top; |
| 888 | debug ("## fwenv at 0x%08lX ", top); |
| 889 | |
| 890 | top = (top - envsz) & ~0xF; |
| 891 | s = (char *)top; |
| 892 | ss = fwenv; |
| 893 | |
| 894 | /* now copy them */ |
| 895 | for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) { |
| 896 | for (nxt = i; env_get_char (nxt) != '\0'; ++nxt) |
| 897 | ; |
| 898 | *ss++ = s; |
| 899 | for (j = i; j < nxt; ++j) |
| 900 | *s++ = env_get_char (j); |
| 901 | *s++ = '\0'; |
| 902 | } |
| 903 | *ss++ = NULL; /* terminate */ |
| 904 | |
| 905 | entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr); |
| 906 | (*entry) (kbd, cmdline, fwenv, top); |
| 907 | } |
| 908 | #endif |