wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1 | /* |
Stefan Roese | 5d5ce29 | 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 | |
| 24 | /* |
| 25 | * Boot support |
| 26 | */ |
| 27 | #include <common.h> |
| 28 | #include <watchdog.h> |
| 29 | #include <command.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 30 | #include <image.h> |
| 31 | #include <malloc.h> |
| 32 | #include <zlib.h> |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 33 | #include <bzlib.h> |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 34 | #include <environment.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 35 | #include <asm/byteorder.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 36 | |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 37 | #if defined(CONFIG_OF_LIBFDT) |
| 38 | #include <fdt.h> |
| 39 | #include <libfdt.h> |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 40 | #include <fdt_support.h> |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 41 | #endif |
Gerald Van Baren | 3248089 | 2007-03-31 14:30:53 -0400 | [diff] [blame] | 42 | #if defined(CONFIG_OF_FLAT_TREE) |
Wolfgang Denk | 27a5b0b | 2005-10-13 01:45:54 +0200 | [diff] [blame] | 43 | #include <ft_build.h> |
| 44 | #endif |
| 45 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 46 | DECLARE_GLOBAL_DATA_PTR; |
| 47 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 48 | /*cmd_boot.c*/ |
| 49 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 50 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 51 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 52 | #include <rtc.h> |
| 53 | #endif |
| 54 | |
| 55 | #ifdef CFG_HUSH_PARSER |
| 56 | #include <hush.h> |
| 57 | #endif |
| 58 | |
| 59 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 60 | # include <status_led.h> |
| 61 | # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg) |
| 62 | #else |
| 63 | # define SHOW_BOOT_PROGRESS(arg) |
| 64 | #endif |
| 65 | |
| 66 | #ifdef CFG_INIT_RAM_LOCK |
| 67 | #include <asm/cache.h> |
| 68 | #endif |
| 69 | |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 70 | #ifdef CONFIG_LOGBUFFER |
| 71 | #include <logbuff.h> |
| 72 | #endif |
| 73 | |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 74 | #ifdef CONFIG_HAS_DATAFLASH |
| 75 | #include <dataflash.h> |
| 76 | #endif |
| 77 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 78 | /* |
| 79 | * Some systems (for example LWMON) have very short watchdog periods; |
| 80 | * we must make sure to split long operations like memmove() or |
| 81 | * crc32() into reasonable chunks. |
| 82 | */ |
| 83 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
| 84 | # define CHUNKSZ (64 * 1024) |
| 85 | #endif |
| 86 | |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 87 | int gunzip (void *, int, unsigned char *, unsigned long *); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 88 | |
| 89 | static void *zalloc(void *, unsigned, unsigned); |
| 90 | static void zfree(void *, void *, unsigned); |
| 91 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 92 | #if defined(CONFIG_CMD_IMI) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 93 | static int image_info (unsigned long addr); |
| 94 | #endif |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 95 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 96 | #if defined(CONFIG_CMD_IMLS) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 97 | #include <flash.h> |
Marian Balakowicz | 513b4a1 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 98 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 99 | static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 100 | #endif |
| 101 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 102 | static void print_type (image_header_t *hdr); |
| 103 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 104 | #ifdef __I386__ |
| 105 | image_header_t *fake_header(image_header_t *hdr, void *ptr, int size); |
| 106 | #endif |
| 107 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 108 | /* |
| 109 | * Continue booting an OS image; caller already has: |
| 110 | * - copied image header to global variable `header' |
| 111 | * - checked header magic number, checksums (both header & image), |
| 112 | * - verified image architecture (PPC) and type (KERNEL or MULTI), |
| 113 | * - loaded (first part of) image to header load address, |
| 114 | * - disabled interrupts. |
| 115 | */ |
| 116 | typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag, |
| 117 | int argc, char *argv[], |
| 118 | ulong addr, /* of image to boot */ |
| 119 | ulong *len_ptr, /* multi-file image length table */ |
| 120 | int verify); /* getenv("verify")[0] != 'n' */ |
| 121 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 122 | #ifdef DEBUG |
| 123 | extern int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 124 | #endif |
| 125 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 126 | #ifdef CONFIG_PPC |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 127 | static boot_os_Fcn do_bootm_linux; |
| 128 | #else |
| 129 | extern boot_os_Fcn do_bootm_linux; |
| 130 | #endif |
wdenk | 808532a | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 131 | #ifdef CONFIG_SILENT_CONSOLE |
| 132 | static void fixup_silent_linux (void); |
| 133 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 134 | static boot_os_Fcn do_bootm_netbsd; |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 135 | static boot_os_Fcn do_bootm_rtems; |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 136 | #if defined(CONFIG_CMD_ELF) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 137 | static boot_os_Fcn do_bootm_vxworks; |
| 138 | static boot_os_Fcn do_bootm_qnxelf; |
| 139 | int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] ); |
| 140 | int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame^] | 141 | #endif |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 142 | #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) |
| 143 | static boot_os_Fcn do_bootm_artos; |
| 144 | #endif |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 145 | #ifdef CONFIG_LYNXKDI |
| 146 | static boot_os_Fcn do_bootm_lynxkdi; |
| 147 | extern void lynxkdi_boot( image_header_t * ); |
| 148 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 149 | |
Stefan Roese | 5d5ce29 | 2006-03-13 11:16:36 +0100 | [diff] [blame] | 150 | #ifndef CFG_BOOTM_LEN |
| 151 | #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */ |
| 152 | #endif |
| 153 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 154 | image_header_t header; |
| 155 | |
| 156 | ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */ |
| 157 | |
| 158 | int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 159 | { |
| 160 | ulong iflag; |
| 161 | ulong addr; |
| 162 | ulong data, len, checksum; |
| 163 | ulong *len_ptr; |
Stefan Roese | 5d5ce29 | 2006-03-13 11:16:36 +0100 | [diff] [blame] | 164 | uint unc_len = CFG_BOOTM_LEN; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 165 | int i, verify; |
| 166 | char *name, *s; |
wdenk | 655a0f9 | 2003-10-30 21:49:38 +0000 | [diff] [blame] | 167 | int (*appl)(int, char *[]); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 168 | image_header_t *hdr = &header; |
| 169 | |
| 170 | s = getenv ("verify"); |
| 171 | verify = (s && (*s == 'n')) ? 0 : 1; |
| 172 | |
| 173 | if (argc < 2) { |
| 174 | addr = load_addr; |
| 175 | } else { |
| 176 | addr = simple_strtoul(argv[1], NULL, 16); |
| 177 | } |
| 178 | |
| 179 | SHOW_BOOT_PROGRESS (1); |
| 180 | printf ("## Booting image at %08lx ...\n", addr); |
| 181 | |
| 182 | /* Copy header so we can blank CRC field for re-calculation */ |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 183 | #ifdef CONFIG_HAS_DATAFLASH |
| 184 | if (addr_dataflash(addr)){ |
| 185 | read_dataflash(addr, sizeof(image_header_t), (char *)&header); |
| 186 | } else |
| 187 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 188 | memmove (&header, (char *)addr, sizeof(image_header_t)); |
| 189 | |
| 190 | if (ntohl(hdr->ih_magic) != IH_MAGIC) { |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 191 | #ifdef __I386__ /* correct image format not implemented yet - fake it */ |
| 192 | if (fake_header(hdr, (void*)addr, -1) != NULL) { |
| 193 | /* to compensate for the addition below */ |
| 194 | addr -= sizeof(image_header_t); |
| 195 | /* turnof verify, |
| 196 | * fake_header() does not fake the data crc |
| 197 | */ |
| 198 | verify = 0; |
| 199 | } else |
| 200 | #endif /* __I386__ */ |
| 201 | { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 202 | puts ("Bad Magic Number\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 203 | SHOW_BOOT_PROGRESS (-1); |
| 204 | return 1; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 205 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 206 | } |
| 207 | SHOW_BOOT_PROGRESS (2); |
| 208 | |
| 209 | data = (ulong)&header; |
| 210 | len = sizeof(image_header_t); |
| 211 | |
| 212 | checksum = ntohl(hdr->ih_hcrc); |
| 213 | hdr->ih_hcrc = 0; |
| 214 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 215 | if (crc32 (0, (uchar *)data, len) != checksum) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 216 | puts ("Bad Header Checksum\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 217 | SHOW_BOOT_PROGRESS (-2); |
| 218 | return 1; |
| 219 | } |
| 220 | SHOW_BOOT_PROGRESS (3); |
| 221 | |
Wolfgang Denk | 63e44ff | 2005-10-06 01:50:50 +0200 | [diff] [blame] | 222 | #ifdef CONFIG_HAS_DATAFLASH |
| 223 | if (addr_dataflash(addr)){ |
| 224 | len = ntohl(hdr->ih_size) + sizeof(image_header_t); |
| 225 | read_dataflash(addr, len, (char *)CFG_LOAD_ADDR); |
| 226 | addr = CFG_LOAD_ADDR; |
| 227 | } |
| 228 | #endif |
| 229 | |
| 230 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 231 | /* for multi-file images we need the data part, too */ |
wdenk | a983cc2 | 2003-10-26 22:52:58 +0000 | [diff] [blame] | 232 | print_image_hdr ((image_header_t *)addr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 233 | |
| 234 | data = addr + sizeof(image_header_t); |
| 235 | len = ntohl(hdr->ih_size); |
| 236 | |
| 237 | if (verify) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 238 | puts (" Verifying Checksum ... "); |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 239 | if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 240 | printf ("Bad Data CRC\n"); |
| 241 | SHOW_BOOT_PROGRESS (-3); |
| 242 | return 1; |
| 243 | } |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 244 | puts ("OK\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 245 | } |
| 246 | SHOW_BOOT_PROGRESS (4); |
| 247 | |
| 248 | len_ptr = (ulong *)data; |
| 249 | |
Wolfgang Denk | b284679 | 2007-03-22 00:13:12 +0100 | [diff] [blame] | 250 | #if defined(__ARM__) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 251 | if (hdr->ih_arch != IH_CPU_ARM) |
Wolfgang Denk | b284679 | 2007-03-22 00:13:12 +0100 | [diff] [blame] | 252 | #elif defined(__avr32__) |
| 253 | if (hdr->ih_arch != IH_CPU_AVR32) |
| 254 | #elif defined(__bfin__) |
| 255 | if (hdr->ih_arch != IH_CPU_BLACKFIN) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 256 | #elif defined(__I386__) |
| 257 | if (hdr->ih_arch != IH_CPU_I386) |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 258 | #elif defined(__M68K__) |
| 259 | if (hdr->ih_arch != IH_CPU_M68K) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 260 | #elif defined(__microblaze__) |
| 261 | if (hdr->ih_arch != IH_CPU_MICROBLAZE) |
Wolfgang Denk | b284679 | 2007-03-22 00:13:12 +0100 | [diff] [blame] | 262 | #elif defined(__mips__) |
| 263 | if (hdr->ih_arch != IH_CPU_MIPS) |
| 264 | #elif defined(__nios__) |
| 265 | if (hdr->ih_arch != IH_CPU_NIOS) |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 266 | #elif defined(__nios2__) |
| 267 | if (hdr->ih_arch != IH_CPU_NIOS2) |
Wolfgang Denk | b284679 | 2007-03-22 00:13:12 +0100 | [diff] [blame] | 268 | #elif defined(__PPC__) |
| 269 | if (hdr->ih_arch != IH_CPU_PPC) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 270 | #else |
| 271 | # error Unknown CPU type |
| 272 | #endif |
| 273 | { |
| 274 | printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 275 | SHOW_BOOT_PROGRESS (-4); |
| 276 | return 1; |
| 277 | } |
| 278 | SHOW_BOOT_PROGRESS (5); |
| 279 | |
| 280 | switch (hdr->ih_type) { |
wdenk | 655a0f9 | 2003-10-30 21:49:38 +0000 | [diff] [blame] | 281 | case IH_TYPE_STANDALONE: |
| 282 | name = "Standalone Application"; |
| 283 | /* A second argument overwrites the load address */ |
| 284 | if (argc > 2) { |
wdenk | d1894de | 2005-06-20 10:17:34 +0000 | [diff] [blame] | 285 | hdr->ih_load = htonl(simple_strtoul(argv[2], NULL, 16)); |
wdenk | 655a0f9 | 2003-10-30 21:49:38 +0000 | [diff] [blame] | 286 | } |
| 287 | break; |
| 288 | case IH_TYPE_KERNEL: |
| 289 | name = "Kernel Image"; |
| 290 | break; |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 291 | case IH_TYPE_MULTI: |
wdenk | 655a0f9 | 2003-10-30 21:49:38 +0000 | [diff] [blame] | 292 | name = "Multi-File Image"; |
| 293 | len = ntohl(len_ptr[0]); |
| 294 | /* OS kernel is always the first image */ |
| 295 | data += 8; /* kernel_len + terminator */ |
| 296 | for (i=1; len_ptr[i]; ++i) |
| 297 | data += 4; |
| 298 | break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 299 | default: printf ("Wrong Image Type for %s command\n", cmdtp->name); |
| 300 | SHOW_BOOT_PROGRESS (-5); |
| 301 | return 1; |
| 302 | } |
| 303 | SHOW_BOOT_PROGRESS (6); |
| 304 | |
| 305 | /* |
| 306 | * We have reached the point of no return: we are going to |
| 307 | * overwrite all exception vector code, so we cannot easily |
| 308 | * recover from any failures any more... |
| 309 | */ |
| 310 | |
| 311 | iflag = disable_interrupts(); |
| 312 | |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 313 | #ifdef CONFIG_AMIGAONEG3SE |
| 314 | /* |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 315 | * We've possible left the caches enabled during |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 316 | * bios emulation, so turn them off again |
| 317 | */ |
| 318 | icache_disable(); |
| 319 | invalidate_l1_instruction_cache(); |
| 320 | flush_data_cache(); |
| 321 | dcache_disable(); |
| 322 | #endif |
| 323 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 324 | switch (hdr->ih_comp) { |
| 325 | case IH_COMP_NONE: |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 326 | if(ntohl(hdr->ih_load) == addr) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 327 | printf (" XIP %s ... ", name); |
| 328 | } else { |
| 329 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
| 330 | size_t l = len; |
| 331 | void *to = (void *)ntohl(hdr->ih_load); |
| 332 | void *from = (void *)data; |
| 333 | |
| 334 | printf (" Loading %s ... ", name); |
| 335 | |
| 336 | while (l > 0) { |
| 337 | size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l; |
| 338 | WATCHDOG_RESET(); |
| 339 | memmove (to, from, tail); |
| 340 | to += tail; |
| 341 | from += tail; |
| 342 | l -= tail; |
| 343 | } |
| 344 | #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ |
| 345 | memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len); |
| 346 | #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ |
| 347 | } |
| 348 | break; |
| 349 | case IH_COMP_GZIP: |
| 350 | printf (" Uncompressing %s ... ", name); |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 351 | if (gunzip ((void *)ntohl(hdr->ih_load), unc_len, |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 352 | (uchar *)data, &len) != 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 353 | puts ("GUNZIP ERROR - must RESET board to recover\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 354 | SHOW_BOOT_PROGRESS (-6); |
| 355 | do_reset (cmdtp, flag, argc, argv); |
| 356 | } |
| 357 | break; |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 358 | #ifdef CONFIG_BZIP2 |
| 359 | case IH_COMP_BZIP2: |
| 360 | printf (" Uncompressing %s ... ", name); |
wdenk | 2cefd15 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 361 | /* |
| 362 | * If we've got less than 4 MB of malloc() space, |
| 363 | * use slower decompression algorithm which requires |
| 364 | * at most 2300 KB of memory. |
| 365 | */ |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 366 | i = BZ2_bzBuffToBuffDecompress ((char*)ntohl(hdr->ih_load), |
wdenk | 2cefd15 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 367 | &unc_len, (char *)data, len, |
| 368 | CFG_MALLOC_LEN < (4096 * 1024), 0); |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 369 | if (i != BZ_OK) { |
| 370 | printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i); |
| 371 | SHOW_BOOT_PROGRESS (-6); |
| 372 | udelay(100000); |
| 373 | do_reset (cmdtp, flag, argc, argv); |
| 374 | } |
| 375 | break; |
| 376 | #endif /* CONFIG_BZIP2 */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 377 | default: |
| 378 | if (iflag) |
| 379 | enable_interrupts(); |
| 380 | printf ("Unimplemented compression type %d\n", hdr->ih_comp); |
| 381 | SHOW_BOOT_PROGRESS (-7); |
| 382 | return 1; |
| 383 | } |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 384 | puts ("OK\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 385 | SHOW_BOOT_PROGRESS (7); |
| 386 | |
| 387 | switch (hdr->ih_type) { |
| 388 | case IH_TYPE_STANDALONE: |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 389 | if (iflag) |
| 390 | enable_interrupts(); |
| 391 | |
wdenk | 3f9ab98 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 392 | /* load (and uncompress), but don't start if "autostart" |
| 393 | * is set to "no" |
| 394 | */ |
wdenk | 60164a8 | 2003-10-08 23:26:14 +0000 | [diff] [blame] | 395 | if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) { |
| 396 | char buf[32]; |
| 397 | sprintf(buf, "%lX", len); |
| 398 | setenv("filesize", buf); |
wdenk | 3f9ab98 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 399 | return 0; |
wdenk | 60164a8 | 2003-10-08 23:26:14 +0000 | [diff] [blame] | 400 | } |
wdenk | 655a0f9 | 2003-10-30 21:49:38 +0000 | [diff] [blame] | 401 | appl = (int (*)(int, char *[]))ntohl(hdr->ih_ep); |
| 402 | (*appl)(argc-1, &argv[1]); |
wdenk | 3f9ab98 | 2003-04-12 23:38:12 +0000 | [diff] [blame] | 403 | return 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 404 | case IH_TYPE_KERNEL: |
| 405 | case IH_TYPE_MULTI: |
| 406 | /* handled below */ |
| 407 | break; |
| 408 | default: |
| 409 | if (iflag) |
| 410 | enable_interrupts(); |
| 411 | printf ("Can't boot image type %d\n", hdr->ih_type); |
| 412 | SHOW_BOOT_PROGRESS (-8); |
| 413 | return 1; |
| 414 | } |
| 415 | SHOW_BOOT_PROGRESS (8); |
| 416 | |
| 417 | switch (hdr->ih_os) { |
| 418 | default: /* handled by (original) Linux case */ |
| 419 | case IH_OS_LINUX: |
wdenk | 808532a | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 420 | #ifdef CONFIG_SILENT_CONSOLE |
| 421 | fixup_silent_linux(); |
| 422 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 423 | do_bootm_linux (cmdtp, flag, argc, argv, |
| 424 | addr, len_ptr, verify); |
| 425 | break; |
| 426 | case IH_OS_NETBSD: |
| 427 | do_bootm_netbsd (cmdtp, flag, argc, argv, |
| 428 | addr, len_ptr, verify); |
| 429 | break; |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 430 | |
| 431 | #ifdef CONFIG_LYNXKDI |
| 432 | case IH_OS_LYNXOS: |
| 433 | do_bootm_lynxkdi (cmdtp, flag, argc, argv, |
| 434 | addr, len_ptr, verify); |
| 435 | break; |
| 436 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 437 | |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 438 | case IH_OS_RTEMS: |
| 439 | do_bootm_rtems (cmdtp, flag, argc, argv, |
| 440 | addr, len_ptr, verify); |
| 441 | break; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 442 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 443 | #if defined(CONFIG_CMD_ELF) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 444 | case IH_OS_VXWORKS: |
| 445 | do_bootm_vxworks (cmdtp, flag, argc, argv, |
| 446 | addr, len_ptr, verify); |
| 447 | break; |
| 448 | case IH_OS_QNX: |
| 449 | do_bootm_qnxelf (cmdtp, flag, argc, argv, |
| 450 | addr, len_ptr, verify); |
| 451 | break; |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame^] | 452 | #endif |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 453 | #ifdef CONFIG_ARTOS |
| 454 | case IH_OS_ARTOS: |
| 455 | do_bootm_artos (cmdtp, flag, argc, argv, |
| 456 | addr, len_ptr, verify); |
| 457 | break; |
| 458 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | SHOW_BOOT_PROGRESS (-9); |
| 462 | #ifdef DEBUG |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 463 | puts ("\n## Control returned to monitor - resetting...\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 464 | do_reset (cmdtp, flag, argc, argv); |
| 465 | #endif |
| 466 | return 1; |
| 467 | } |
| 468 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 469 | U_BOOT_CMD( |
| 470 | bootm, CFG_MAXARGS, 1, do_bootm, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 471 | "bootm - boot application image from memory\n", |
| 472 | "[addr [arg ...]]\n - boot application image stored in memory\n" |
wdenk | 20dd2fa | 2004-11-21 00:06:33 +0000 | [diff] [blame] | 473 | "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n" |
| 474 | "\t'arg' can be the address of an initrd image\n" |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 475 | #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 476 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
| 477 | "\ta third argument is required which is the address of the of the\n" |
| 478 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 479 | "\tuse a '-' for the second argument. If you do not pass a third\n" |
| 480 | "\ta bd_info struct will be passed instead\n" |
| 481 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 482 | ); |
| 483 | |
wdenk | 808532a | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 484 | #ifdef CONFIG_SILENT_CONSOLE |
| 485 | static void |
| 486 | fixup_silent_linux () |
| 487 | { |
wdenk | 808532a | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 488 | char buf[256], *start, *end; |
| 489 | char *cmdline = getenv ("bootargs"); |
| 490 | |
| 491 | /* Only fix cmdline when requested */ |
| 492 | if (!(gd->flags & GD_FLG_SILENT)) |
| 493 | return; |
| 494 | |
| 495 | debug ("before silent fix-up: %s\n", cmdline); |
| 496 | if (cmdline) { |
| 497 | if ((start = strstr (cmdline, "console=")) != NULL) { |
| 498 | end = strchr (start, ' '); |
| 499 | strncpy (buf, cmdline, (start - cmdline + 8)); |
| 500 | if (end) |
| 501 | strcpy (buf + (start - cmdline + 8), end); |
| 502 | else |
| 503 | buf[start - cmdline + 8] = '\0'; |
| 504 | } else { |
| 505 | strcpy (buf, cmdline); |
| 506 | strcat (buf, " console="); |
| 507 | } |
| 508 | } else { |
| 509 | strcpy (buf, "console="); |
| 510 | } |
| 511 | |
| 512 | setenv ("bootargs", buf); |
| 513 | debug ("after silent fix-up: %s\n", buf); |
| 514 | } |
| 515 | #endif /* CONFIG_SILENT_CONSOLE */ |
| 516 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 517 | #ifdef CONFIG_PPC |
Matthew McClintock | 4db6937 | 2006-08-23 13:32:45 -0500 | [diff] [blame] | 518 | static void __attribute__((noinline)) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 519 | do_bootm_linux (cmd_tbl_t *cmdtp, int flag, |
| 520 | int argc, char *argv[], |
| 521 | ulong addr, |
| 522 | ulong *len_ptr, |
| 523 | int verify) |
| 524 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 525 | ulong sp; |
| 526 | ulong len, checksum; |
| 527 | ulong initrd_start, initrd_end; |
| 528 | ulong cmd_start, cmd_end; |
| 529 | ulong initrd_high; |
| 530 | ulong data; |
wdenk | 6f770ed | 2003-05-23 23:18:21 +0000 | [diff] [blame] | 531 | int initrd_copy_to_ram = 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 532 | char *cmdline; |
| 533 | char *s; |
| 534 | bd_t *kbd; |
| 535 | void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); |
| 536 | image_header_t *hdr = &header; |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 537 | #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 538 | char *of_flat_tree = NULL; |
Kumar Gala | 665915b | 2006-10-24 23:47:37 -0500 | [diff] [blame] | 539 | ulong of_data = 0; |
Wolfgang Denk | 27a5b0b | 2005-10-13 01:45:54 +0200 | [diff] [blame] | 540 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 541 | |
| 542 | if ((s = getenv ("initrd_high")) != NULL) { |
| 543 | /* a value of "no" or a similar string will act like 0, |
| 544 | * turning the "load high" feature off. This is intentional. |
| 545 | */ |
| 546 | initrd_high = simple_strtoul(s, NULL, 16); |
wdenk | 6f770ed | 2003-05-23 23:18:21 +0000 | [diff] [blame] | 547 | if (initrd_high == ~0) |
| 548 | initrd_copy_to_ram = 0; |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 549 | } else { /* not set, no restrictions to load high */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 550 | initrd_high = ~0; |
| 551 | } |
| 552 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 553 | #ifdef CONFIG_LOGBUFFER |
wdenk | 34b613e | 2002-12-17 01:51:00 +0000 | [diff] [blame] | 554 | kbd=gd->bd; |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 555 | /* Prevent initrd from overwriting logbuffer */ |
| 556 | if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD)) |
| 557 | initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD; |
| 558 | debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 559 | #endif |
| 560 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 561 | /* |
| 562 | * Booting a (Linux) kernel image |
| 563 | * |
| 564 | * Allocate space for command line and board info - the |
| 565 | * address should be as high as possible within the reach of |
| 566 | * the kernel (see CFG_BOOTMAPSZ settings), but in unused |
| 567 | * memory, which means far enough below the current stack |
| 568 | * pointer. |
| 569 | */ |
| 570 | |
| 571 | asm( "mr %0,1": "=r"(sp) : ); |
| 572 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 573 | debug ("## Current stack ends at 0x%08lX ", sp); |
| 574 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 575 | sp -= 2048; /* just to be sure */ |
| 576 | if (sp > CFG_BOOTMAPSZ) |
| 577 | sp = CFG_BOOTMAPSZ; |
| 578 | sp &= ~0xF; |
| 579 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 580 | debug ("=> set upper limit to 0x%08lX\n", sp); |
| 581 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 582 | cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF); |
| 583 | kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF); |
| 584 | |
| 585 | if ((s = getenv("bootargs")) == NULL) |
| 586 | s = ""; |
| 587 | |
| 588 | strcpy (cmdline, s); |
| 589 | |
| 590 | cmd_start = (ulong)&cmdline[0]; |
| 591 | cmd_end = cmd_start + strlen(cmdline); |
| 592 | |
| 593 | *kbd = *(gd->bd); |
| 594 | |
| 595 | #ifdef DEBUG |
| 596 | printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end); |
| 597 | |
| 598 | do_bdinfo (NULL, 0, 0, NULL); |
| 599 | #endif |
| 600 | |
| 601 | if ((s = getenv ("clocks_in_mhz")) != NULL) { |
| 602 | /* convert all clock information to MHz */ |
| 603 | kbd->bi_intfreq /= 1000000L; |
| 604 | kbd->bi_busfreq /= 1000000L; |
wdenk | 337f565 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 605 | #if defined(CONFIG_MPC8220) |
wdenk | 20dd2fa | 2004-11-21 00:06:33 +0000 | [diff] [blame] | 606 | kbd->bi_inpfreq /= 1000000L; |
| 607 | kbd->bi_pcifreq /= 1000000L; |
| 608 | kbd->bi_pevfreq /= 1000000L; |
| 609 | kbd->bi_flbfreq /= 1000000L; |
| 610 | kbd->bi_vcofreq /= 1000000L; |
wdenk | 337f565 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 611 | #endif |
Jon Loeliger | f5ad378 | 2005-07-23 10:37:35 -0500 | [diff] [blame] | 612 | #if defined(CONFIG_CPM2) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 613 | kbd->bi_cpmfreq /= 1000000L; |
| 614 | kbd->bi_brgfreq /= 1000000L; |
| 615 | kbd->bi_sccfreq /= 1000000L; |
| 616 | kbd->bi_vco /= 1000000L; |
Jon Loeliger | f5ad378 | 2005-07-23 10:37:35 -0500 | [diff] [blame] | 617 | #endif |
wdenk | be9c1cb | 2004-02-24 02:00:03 +0000 | [diff] [blame] | 618 | #if defined(CONFIG_MPC5xxx) |
wdenk | 21136db | 2003-07-16 21:53:01 +0000 | [diff] [blame] | 619 | kbd->bi_ipbfreq /= 1000000L; |
| 620 | kbd->bi_pcifreq /= 1000000L; |
wdenk | be9c1cb | 2004-02-24 02:00:03 +0000 | [diff] [blame] | 621 | #endif /* CONFIG_MPC5xxx */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Wolfgang Denk | b6929f9 | 2006-03-12 01:59:35 +0100 | [diff] [blame] | 624 | kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong)) ntohl(hdr->ih_ep); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 625 | |
| 626 | /* |
| 627 | * Check if there is an initrd image |
| 628 | */ |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 629 | |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 630 | #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 631 | /* Look for a '-' which indicates to ignore the ramdisk argument */ |
| 632 | if (argc >= 3 && strcmp(argv[2], "-") == 0) { |
| 633 | debug ("Skipping initrd\n"); |
Matthew McClintock | 5b94882 | 2006-10-11 15:13:01 -0500 | [diff] [blame] | 634 | len = data = 0; |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 635 | } |
| 636 | else |
| 637 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 638 | if (argc >= 3) { |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 639 | debug ("Not skipping initrd\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 640 | SHOW_BOOT_PROGRESS (9); |
| 641 | |
| 642 | addr = simple_strtoul(argv[2], NULL, 16); |
| 643 | |
| 644 | printf ("## Loading RAMDisk Image at %08lx ...\n", addr); |
| 645 | |
| 646 | /* Copy header so we can blank CRC field for re-calculation */ |
| 647 | memmove (&header, (char *)addr, sizeof(image_header_t)); |
| 648 | |
Wolfgang Denk | b6929f9 | 2006-03-12 01:59:35 +0100 | [diff] [blame] | 649 | if (ntohl(hdr->ih_magic) != IH_MAGIC) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 650 | puts ("Bad Magic Number\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 651 | SHOW_BOOT_PROGRESS (-10); |
| 652 | do_reset (cmdtp, flag, argc, argv); |
| 653 | } |
| 654 | |
| 655 | data = (ulong)&header; |
| 656 | len = sizeof(image_header_t); |
| 657 | |
Wolfgang Denk | b6929f9 | 2006-03-12 01:59:35 +0100 | [diff] [blame] | 658 | checksum = ntohl(hdr->ih_hcrc); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 659 | hdr->ih_hcrc = 0; |
| 660 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 661 | if (crc32 (0, (uchar *)data, len) != checksum) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 662 | puts ("Bad Header Checksum\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 663 | SHOW_BOOT_PROGRESS (-11); |
| 664 | do_reset (cmdtp, flag, argc, argv); |
| 665 | } |
| 666 | |
| 667 | SHOW_BOOT_PROGRESS (10); |
| 668 | |
| 669 | print_image_hdr (hdr); |
| 670 | |
| 671 | data = addr + sizeof(image_header_t); |
Wolfgang Denk | b6929f9 | 2006-03-12 01:59:35 +0100 | [diff] [blame] | 672 | len = ntohl(hdr->ih_size); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 673 | |
| 674 | if (verify) { |
| 675 | ulong csum = 0; |
| 676 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
| 677 | ulong cdata = data, edata = cdata + len; |
| 678 | #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ |
| 679 | |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 680 | puts (" Verifying Checksum ... "); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 681 | |
| 682 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
| 683 | |
| 684 | while (cdata < edata) { |
| 685 | ulong chunk = edata - cdata; |
| 686 | |
| 687 | if (chunk > CHUNKSZ) |
| 688 | chunk = CHUNKSZ; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 689 | csum = crc32 (csum, (uchar *)cdata, chunk); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 690 | cdata += chunk; |
| 691 | |
| 692 | WATCHDOG_RESET(); |
| 693 | } |
| 694 | #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 695 | csum = crc32 (0, (uchar *)data, len); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 696 | #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ |
| 697 | |
Wolfgang Denk | b6929f9 | 2006-03-12 01:59:35 +0100 | [diff] [blame] | 698 | if (csum != ntohl(hdr->ih_dcrc)) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 699 | puts ("Bad Data CRC\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 700 | SHOW_BOOT_PROGRESS (-12); |
| 701 | do_reset (cmdtp, flag, argc, argv); |
| 702 | } |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 703 | puts ("OK\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | SHOW_BOOT_PROGRESS (11); |
| 707 | |
| 708 | if ((hdr->ih_os != IH_OS_LINUX) || |
| 709 | (hdr->ih_arch != IH_CPU_PPC) || |
| 710 | (hdr->ih_type != IH_TYPE_RAMDISK) ) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 711 | puts ("No Linux PPC Ramdisk Image\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 712 | SHOW_BOOT_PROGRESS (-13); |
| 713 | do_reset (cmdtp, flag, argc, argv); |
| 714 | } |
| 715 | |
| 716 | /* |
| 717 | * Now check if we have a multifile image |
| 718 | */ |
| 719 | } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) { |
| 720 | u_long tail = ntohl(len_ptr[0]) % 4; |
| 721 | int i; |
| 722 | |
| 723 | SHOW_BOOT_PROGRESS (13); |
| 724 | |
| 725 | /* skip kernel length and terminator */ |
| 726 | data = (ulong)(&len_ptr[2]); |
| 727 | /* skip any additional image length fields */ |
| 728 | for (i=1; len_ptr[i]; ++i) |
| 729 | data += 4; |
| 730 | /* add kernel length, and align */ |
| 731 | data += ntohl(len_ptr[0]); |
| 732 | if (tail) { |
| 733 | data += 4 - tail; |
| 734 | } |
| 735 | |
| 736 | len = ntohl(len_ptr[1]); |
| 737 | |
| 738 | } else { |
| 739 | /* |
| 740 | * no initrd image |
| 741 | */ |
| 742 | SHOW_BOOT_PROGRESS (14); |
| 743 | |
| 744 | len = data = 0; |
| 745 | } |
| 746 | |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 747 | #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) |
Matthew McClintock | 20453d6 | 2006-08-22 09:31:59 -0500 | [diff] [blame] | 748 | if(argc > 3) { |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 749 | of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16); |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 750 | hdr = (image_header_t *)of_flat_tree; |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 751 | #if defined(CONFIG_OF_LIBFDT) |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 752 | if (fdt_check_header(of_flat_tree) == 0) { |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 753 | #else |
| 754 | if (*(ulong *)of_flat_tree == OF_DT_HEADER) { |
| 755 | #endif |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 756 | #ifndef CFG_NO_FLASH |
Kumar Gala | 665915b | 2006-10-24 23:47:37 -0500 | [diff] [blame] | 757 | if (addr2info((ulong)of_flat_tree) != NULL) |
| 758 | of_data = (ulong)of_flat_tree; |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 759 | #endif |
| 760 | } else if (ntohl(hdr->ih_magic) == IH_MAGIC) { |
| 761 | printf("## Flat Device Tree Image at %08lX\n", hdr); |
| 762 | print_image_hdr(hdr); |
| 763 | |
| 764 | if ((ntohl(hdr->ih_load) < ((unsigned long)hdr + ntohl(hdr->ih_size) + sizeof(hdr))) && |
| 765 | ((ntohl(hdr->ih_load) + ntohl(hdr->ih_size)) > (unsigned long)hdr)) { |
| 766 | printf ("ERROR: Load address overwrites Flat Device Tree uImage\n"); |
| 767 | return; |
| 768 | } |
Matthew McClintock | 27ec206 | 2006-08-22 09:23:55 -0500 | [diff] [blame] | 769 | |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 770 | printf(" Verifying Checksum ... "); |
| 771 | memmove (&header, (char *)hdr, sizeof(image_header_t)); |
| 772 | checksum = ntohl(header.ih_hcrc); |
| 773 | header.ih_hcrc = 0; |
| 774 | |
| 775 | if(checksum != crc32(0, (uchar *)&header, sizeof(image_header_t))) { |
| 776 | printf("ERROR: Flat Device Tree header checksum is invalid\n"); |
| 777 | return; |
| 778 | } |
| 779 | |
| 780 | checksum = ntohl(hdr->ih_dcrc); |
| 781 | addr = (ulong)((uchar *)(hdr) + sizeof(image_header_t)); |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 782 | |
Wolfgang Denk | fce39ff | 2007-05-04 10:02:33 +0200 | [diff] [blame] | 783 | if(checksum != crc32(0, (uchar *)addr, ntohl(hdr->ih_size))) { |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 784 | printf("ERROR: Flat Device Tree checksum is invalid\n"); |
| 785 | return; |
| 786 | } |
| 787 | printf("OK\n"); |
| 788 | |
| 789 | if (ntohl(hdr->ih_type) != IH_TYPE_FLATDT) { |
| 790 | printf ("ERROR: uImage not Flat Device Tree type\n"); |
| 791 | return; |
| 792 | } |
| 793 | if (ntohl(hdr->ih_comp) != IH_COMP_NONE) { |
| 794 | printf("ERROR: uImage is not uncompressed\n"); |
| 795 | return; |
| 796 | } |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 797 | #if defined(CONFIG_OF_LIBFDT) |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 798 | if (fdt_check_header(of_flat_tree + sizeof(image_header_t)) == 0) { |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 799 | #else |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 800 | if (*((ulong *)(of_flat_tree + sizeof(image_header_t))) != OF_DT_HEADER) { |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 801 | #endif |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 802 | printf ("ERROR: uImage data is not a flat device tree\n"); |
| 803 | return; |
| 804 | } |
Matthew McClintock | 27ec206 | 2006-08-22 09:23:55 -0500 | [diff] [blame] | 805 | |
| 806 | memmove((void *)ntohl(hdr->ih_load), |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 807 | (void *)(of_flat_tree + sizeof(image_header_t)), |
| 808 | ntohl(hdr->ih_size)); |
| 809 | of_flat_tree = (char *)ntohl(hdr->ih_load); |
| 810 | } else { |
| 811 | printf ("Did not find a flat flat device tree at address %08lX\n", of_flat_tree); |
| 812 | return; |
| 813 | } |
| 814 | printf (" Booting using flat device tree at 0x%x\n", |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 815 | of_flat_tree); |
Kumar Gala | 665915b | 2006-10-24 23:47:37 -0500 | [diff] [blame] | 816 | } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]) && (len_ptr[2])) { |
| 817 | u_long tail = ntohl(len_ptr[0]) % 4; |
| 818 | int i; |
| 819 | |
| 820 | /* skip kernel length, initrd length, and terminator */ |
| 821 | of_data = (ulong)(&len_ptr[3]); |
| 822 | /* skip any additional image length fields */ |
| 823 | for (i=2; len_ptr[i]; ++i) |
| 824 | of_data += 4; |
| 825 | /* add kernel length, and align */ |
| 826 | of_data += ntohl(len_ptr[0]); |
| 827 | if (tail) { |
| 828 | of_data += 4 - tail; |
| 829 | } |
| 830 | |
| 831 | /* add initrd length, and align */ |
| 832 | tail = ntohl(len_ptr[1]) % 4; |
| 833 | of_data += ntohl(len_ptr[1]); |
| 834 | if (tail) { |
| 835 | of_data += 4 - tail; |
| 836 | } |
| 837 | |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 838 | #if defined(CONFIG_OF_LIBFDT) |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 839 | if (fdt_check_header((void *)of_data) != 0) { |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 840 | #else |
Kumar Gala | 665915b | 2006-10-24 23:47:37 -0500 | [diff] [blame] | 841 | if (((struct boot_param_header *)of_data)->magic != OF_DT_HEADER) { |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 842 | #endif |
Kumar Gala | 665915b | 2006-10-24 23:47:37 -0500 | [diff] [blame] | 843 | printf ("ERROR: image is not a flat device tree\n"); |
| 844 | return; |
| 845 | } |
| 846 | |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 847 | #if defined(CONFIG_OF_LIBFDT) |
| 848 | if (be32_to_cpu(fdt_totalsize(of_data)) != ntohl(len_ptr[2])) { |
| 849 | #else |
Kumar Gala | 665915b | 2006-10-24 23:47:37 -0500 | [diff] [blame] | 850 | if (((struct boot_param_header *)of_data)->totalsize != ntohl(len_ptr[2])) { |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 851 | #endif |
Kumar Gala | 665915b | 2006-10-24 23:47:37 -0500 | [diff] [blame] | 852 | printf ("ERROR: flat device tree size does not agree with image\n"); |
| 853 | return; |
| 854 | } |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 855 | } |
| 856 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 857 | if (!data) { |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 858 | debug ("No initrd\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 859 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 860 | |
| 861 | if (data) { |
wdenk | 6f770ed | 2003-05-23 23:18:21 +0000 | [diff] [blame] | 862 | if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ |
| 863 | initrd_start = data; |
| 864 | initrd_end = initrd_start + len; |
| 865 | } else { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 866 | initrd_start = (ulong)kbd - len; |
| 867 | initrd_start &= ~(4096 - 1); /* align on page */ |
| 868 | |
| 869 | if (initrd_high) { |
| 870 | ulong nsp; |
| 871 | |
| 872 | /* |
| 873 | * the inital ramdisk does not need to be within |
| 874 | * CFG_BOOTMAPSZ as it is not accessed until after |
| 875 | * the mm system is initialised. |
| 876 | * |
| 877 | * do the stack bottom calculation again and see if |
| 878 | * the initrd will fit just below the monitor stack |
| 879 | * bottom without overwriting the area allocated |
| 880 | * above for command line args and board info. |
| 881 | */ |
| 882 | asm( "mr %0,1": "=r"(nsp) : ); |
| 883 | nsp -= 2048; /* just to be sure */ |
| 884 | nsp &= ~0xF; |
| 885 | if (nsp > initrd_high) /* limit as specified */ |
| 886 | nsp = initrd_high; |
| 887 | nsp -= len; |
| 888 | nsp &= ~(4096 - 1); /* align on page */ |
| 889 | if (nsp >= sp) |
| 890 | initrd_start = nsp; |
| 891 | } |
| 892 | |
| 893 | SHOW_BOOT_PROGRESS (12); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 894 | |
| 895 | debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 896 | data, data + len - 1, len, len); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 897 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 898 | initrd_end = initrd_start + len; |
| 899 | printf (" Loading Ramdisk to %08lx, end %08lx ... ", |
| 900 | initrd_start, initrd_end); |
| 901 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
| 902 | { |
| 903 | size_t l = len; |
| 904 | void *to = (void *)initrd_start; |
| 905 | void *from = (void *)data; |
| 906 | |
| 907 | while (l > 0) { |
| 908 | size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l; |
| 909 | WATCHDOG_RESET(); |
| 910 | memmove (to, from, tail); |
| 911 | to += tail; |
| 912 | from += tail; |
| 913 | l -= tail; |
| 914 | } |
| 915 | } |
| 916 | #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ |
| 917 | memmove ((void *)initrd_start, (void *)data, len); |
| 918 | #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 919 | puts ("OK\n"); |
wdenk | 6f770ed | 2003-05-23 23:18:21 +0000 | [diff] [blame] | 920 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 921 | } else { |
| 922 | initrd_start = 0; |
| 923 | initrd_end = 0; |
| 924 | } |
| 925 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 926 | debug ("## Transferring control to Linux (at address %08lx) ...\n", |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 927 | (ulong)kernel); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 928 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 929 | SHOW_BOOT_PROGRESS (15); |
| 930 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 931 | #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 932 | unlock_ram_in_cache(); |
| 933 | #endif |
Wolfgang Denk | 27a5b0b | 2005-10-13 01:45:54 +0200 | [diff] [blame] | 934 | |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 935 | #if defined(CONFIG_OF_LIBFDT) |
Kumar Gala | 665915b | 2006-10-24 23:47:37 -0500 | [diff] [blame] | 936 | /* move of_flat_tree if needed */ |
| 937 | if (of_data) { |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 938 | int err; |
| 939 | ulong of_start, of_len; |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 940 | |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 941 | of_len = be32_to_cpu(fdt_totalsize(of_data)); |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 942 | /* position on a 4K boundary before the initrd/kbd */ |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 943 | if (initrd_start) |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 944 | of_start = initrd_start - of_len; |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 945 | else |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 946 | of_start = (ulong)kbd - of_len; |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 947 | of_start &= ~(4096 - 1); /* align on page */ |
| 948 | debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", |
| 949 | of_data, of_data + of_len - 1, of_len, of_len); |
| 950 | |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 951 | of_flat_tree = (char *)of_start; |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 952 | printf (" Loading Device Tree to %08lx, end %08lx ... ", |
| 953 | of_start, of_start + of_len - 1); |
Gerald Van Baren | c4a57ea | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 954 | err = fdt_open_into((void *)of_start, (void *)of_data, of_len); |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 955 | if (err != 0) { |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 956 | printf ("libfdt: %s " __FILE__ " %d\n", fdt_strerror(err), __LINE__); |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 957 | } |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 958 | /* |
| 959 | * Add the chosen node if it doesn't exist, add the env and bd_t |
| 960 | * if the user wants it (the logic is in the subroutines). |
| 961 | */ |
| 962 | if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { |
| 963 | printf("Failed creating the /chosen node (0x%08X), aborting.\n", of_flat_tree); |
| 964 | return; |
| 965 | } |
| 966 | #ifdef CONFIG_OF_HAS_UBOOT_ENV |
| 967 | if (fdt_env(of_flat_tree) < 0) { |
| 968 | printf("Failed creating the /u-boot-env node, aborting.\n"); |
| 969 | return; |
| 970 | } |
| 971 | #endif |
| 972 | #ifdef CONFIG_OF_HAS_BD_T |
| 973 | if (fdt_bd_t(of_flat_tree) < 0) { |
| 974 | printf("Failed creating the /bd_t node, aborting.\n"); |
| 975 | return; |
| 976 | } |
| 977 | #endif |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 978 | } |
| 979 | #endif |
| 980 | #if defined(CONFIG_OF_FLAT_TREE) |
| 981 | /* move of_flat_tree if needed */ |
| 982 | if (of_data) { |
Kumar Gala | 665915b | 2006-10-24 23:47:37 -0500 | [diff] [blame] | 983 | ulong of_start, of_len; |
| 984 | of_len = ((struct boot_param_header *)of_data)->totalsize; |
| 985 | /* provide extra 8k pad */ |
| 986 | if (initrd_start) |
| 987 | of_start = initrd_start - of_len - 8192; |
| 988 | else |
| 989 | of_start = (ulong)kbd - of_len - 8192; |
| 990 | of_start &= ~(4096 - 1); /* align on page */ |
| 991 | debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", |
| 992 | of_data, of_data + of_len - 1, of_len, of_len); |
| 993 | |
| 994 | of_flat_tree = (char *)of_start; |
| 995 | printf (" Loading Device Tree to %08lx, end %08lx ... ", |
| 996 | of_start, of_start + of_len - 1); |
| 997 | memmove ((void *)of_start, (void *)of_data, of_len); |
| 998 | } |
Stefan Roese | 208d38a | 2006-11-27 17:04:06 +0100 | [diff] [blame] | 999 | #endif |
Wolfgang Denk | 27a5b0b | 2005-10-13 01:45:54 +0200 | [diff] [blame] | 1000 | |
Stefan Roese | 208d38a | 2006-11-27 17:04:06 +0100 | [diff] [blame] | 1001 | /* |
| 1002 | * Linux Kernel Parameters (passing board info data): |
| 1003 | * r3: ptr to board info data |
| 1004 | * r4: initrd_start or 0 if no initrd |
| 1005 | * r5: initrd_end - unused if r4 is 0 |
| 1006 | * r6: Start of command line string |
| 1007 | * r7: End of command line string |
| 1008 | */ |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 1009 | #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) |
Stefan Roese | 208d38a | 2006-11-27 17:04:06 +0100 | [diff] [blame] | 1010 | if (!of_flat_tree) /* no device tree; boot old style */ |
Wolfgang Denk | 27a5b0b | 2005-10-13 01:45:54 +0200 | [diff] [blame] | 1011 | #endif |
Stefan Roese | 208d38a | 2006-11-27 17:04:06 +0100 | [diff] [blame] | 1012 | (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); |
| 1013 | /* does not return */ |
| 1014 | |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 1015 | #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) |
Wolfgang Denk | 27a5b0b | 2005-10-13 01:45:54 +0200 | [diff] [blame] | 1016 | /* |
Stefan Roese | 208d38a | 2006-11-27 17:04:06 +0100 | [diff] [blame] | 1017 | * Linux Kernel Parameters (passing device tree): |
Wolfgang Denk | 27a5b0b | 2005-10-13 01:45:54 +0200 | [diff] [blame] | 1018 | * r3: ptr to OF flat tree, followed by the board info data |
Kumar Gala | a8b76de | 2006-01-11 16:41:35 -0600 | [diff] [blame] | 1019 | * r4: physical pointer to the kernel itself |
| 1020 | * r5: NULL |
| 1021 | * r6: NULL |
| 1022 | * r7: NULL |
Wolfgang Denk | 27a5b0b | 2005-10-13 01:45:54 +0200 | [diff] [blame] | 1023 | */ |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 1024 | #if defined(CONFIG_OF_FLAT_TREE) |
Stefan Roese | 208d38a | 2006-11-27 17:04:06 +0100 | [diff] [blame] | 1025 | ft_setup(of_flat_tree, kbd, initrd_start, initrd_end); |
| 1026 | /* ft_dump_blob(of_flat_tree); */ |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 1027 | #endif |
Gerald Van Baren | c9502b9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 1028 | #if defined(CONFIG_OF_LIBFDT) |
| 1029 | if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { |
| 1030 | printf("Failed creating the /chosen node (0x%08X), aborting.\n", of_flat_tree); |
| 1031 | return; |
| 1032 | } |
| 1033 | #ifdef CONFIG_OF_HAS_UBOOT_ENV |
| 1034 | if (fdt_env(of_flat_tree) < 0) { |
| 1035 | printf("Failed creating the /u-boot-env node, aborting.\n"); |
| 1036 | return; |
| 1037 | } |
| 1038 | #endif |
| 1039 | #ifdef CONFIG_OF_HAS_BD_T |
| 1040 | if (fdt_bd_t(of_flat_tree) < 0) { |
| 1041 | printf("Failed creating the /bd_t node, aborting.\n"); |
| 1042 | return; |
| 1043 | } |
| 1044 | #endif |
| 1045 | #endif /* if defined(CONFIG_OF_LIBFDT) */ |
Stefan Roese | 208d38a | 2006-11-27 17:04:06 +0100 | [diff] [blame] | 1046 | |
| 1047 | (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0); |
| 1048 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1049 | } |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 1050 | #endif /* CONFIG_PPC */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1051 | |
| 1052 | static void |
| 1053 | do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag, |
| 1054 | int argc, char *argv[], |
| 1055 | ulong addr, |
| 1056 | ulong *len_ptr, |
| 1057 | int verify) |
| 1058 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1059 | image_header_t *hdr = &header; |
| 1060 | |
| 1061 | void (*loader)(bd_t *, image_header_t *, char *, char *); |
| 1062 | image_header_t *img_addr; |
| 1063 | char *consdev; |
| 1064 | char *cmdline; |
| 1065 | |
| 1066 | |
| 1067 | /* |
| 1068 | * Booting a (NetBSD) kernel image |
| 1069 | * |
| 1070 | * This process is pretty similar to a standalone application: |
| 1071 | * The (first part of an multi-) image must be a stage-2 loader, |
| 1072 | * which in turn is responsible for loading & invoking the actual |
| 1073 | * kernel. The only differences are the parameters being passed: |
| 1074 | * besides the board info strucure, the loader expects a command |
| 1075 | * line, the name of the console device, and (optionally) the |
| 1076 | * address of the original image header. |
| 1077 | */ |
| 1078 | |
| 1079 | img_addr = 0; |
| 1080 | if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) |
| 1081 | img_addr = (image_header_t *) addr; |
| 1082 | |
| 1083 | |
| 1084 | consdev = ""; |
| 1085 | #if defined (CONFIG_8xx_CONS_SMC1) |
| 1086 | consdev = "smc1"; |
| 1087 | #elif defined (CONFIG_8xx_CONS_SMC2) |
| 1088 | consdev = "smc2"; |
| 1089 | #elif defined (CONFIG_8xx_CONS_SCC2) |
| 1090 | consdev = "scc2"; |
| 1091 | #elif defined (CONFIG_8xx_CONS_SCC3) |
| 1092 | consdev = "scc3"; |
| 1093 | #endif |
| 1094 | |
| 1095 | if (argc > 2) { |
| 1096 | ulong len; |
| 1097 | int i; |
| 1098 | |
| 1099 | for (i=2, len=0 ; i<argc ; i+=1) |
| 1100 | len += strlen (argv[i]) + 1; |
| 1101 | cmdline = malloc (len); |
| 1102 | |
| 1103 | for (i=2, len=0 ; i<argc ; i+=1) { |
| 1104 | if (i > 2) |
| 1105 | cmdline[len++] = ' '; |
| 1106 | strcpy (&cmdline[len], argv[i]); |
| 1107 | len += strlen (argv[i]); |
| 1108 | } |
| 1109 | } else if ((cmdline = getenv("bootargs")) == NULL) { |
| 1110 | cmdline = ""; |
| 1111 | } |
| 1112 | |
Wolfgang Denk | b6929f9 | 2006-03-12 01:59:35 +0100 | [diff] [blame] | 1113 | loader = (void (*)(bd_t *, image_header_t *, char *, char *)) ntohl(hdr->ih_ep); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1114 | |
| 1115 | printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n", |
| 1116 | (ulong)loader); |
| 1117 | |
| 1118 | SHOW_BOOT_PROGRESS (15); |
| 1119 | |
| 1120 | /* |
| 1121 | * NetBSD Stage-2 Loader Parameters: |
| 1122 | * r3: ptr to board info data |
| 1123 | * r4: image address |
| 1124 | * r5: console device |
| 1125 | * r6: boot args string |
| 1126 | */ |
| 1127 | (*loader) (gd->bd, img_addr, consdev, cmdline); |
| 1128 | } |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 1129 | |
| 1130 | #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) |
| 1131 | |
| 1132 | /* Function that returns a character from the environment */ |
| 1133 | extern uchar (*env_get_char)(int); |
| 1134 | |
| 1135 | static void |
| 1136 | do_bootm_artos (cmd_tbl_t *cmdtp, int flag, |
| 1137 | int argc, char *argv[], |
| 1138 | ulong addr, |
| 1139 | ulong *len_ptr, |
| 1140 | int verify) |
| 1141 | { |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 1142 | ulong top; |
| 1143 | char *s, *cmdline; |
| 1144 | char **fwenv, **ss; |
| 1145 | int i, j, nxt, len, envno, envsz; |
| 1146 | bd_t *kbd; |
| 1147 | void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top); |
| 1148 | image_header_t *hdr = &header; |
| 1149 | |
| 1150 | /* |
| 1151 | * Booting an ARTOS kernel image + application |
| 1152 | */ |
| 1153 | |
| 1154 | /* this used to be the top of memory, but was wrong... */ |
| 1155 | #ifdef CONFIG_PPC |
| 1156 | /* get stack pointer */ |
| 1157 | asm volatile ("mr %0,1" : "=r"(top) ); |
| 1158 | #endif |
| 1159 | debug ("## Current stack ends at 0x%08lX ", top); |
| 1160 | |
| 1161 | top -= 2048; /* just to be sure */ |
| 1162 | if (top > CFG_BOOTMAPSZ) |
| 1163 | top = CFG_BOOTMAPSZ; |
| 1164 | top &= ~0xF; |
| 1165 | |
| 1166 | debug ("=> set upper limit to 0x%08lX\n", top); |
| 1167 | |
| 1168 | /* first check the artos specific boot args, then the linux args*/ |
| 1169 | if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL) |
| 1170 | s = ""; |
| 1171 | |
| 1172 | /* get length of cmdline, and place it */ |
| 1173 | len = strlen(s); |
| 1174 | top = (top - (len + 1)) & ~0xF; |
| 1175 | cmdline = (char *)top; |
| 1176 | debug ("## cmdline at 0x%08lX ", top); |
| 1177 | strcpy(cmdline, s); |
| 1178 | |
| 1179 | /* copy bdinfo */ |
| 1180 | top = (top - sizeof(bd_t)) & ~0xF; |
| 1181 | debug ("## bd at 0x%08lX ", top); |
| 1182 | kbd = (bd_t *)top; |
| 1183 | memcpy(kbd, gd->bd, sizeof(bd_t)); |
| 1184 | |
| 1185 | /* first find number of env entries, and their size */ |
| 1186 | envno = 0; |
| 1187 | envsz = 0; |
| 1188 | for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) { |
| 1189 | for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) |
| 1190 | ; |
| 1191 | envno++; |
| 1192 | envsz += (nxt - i) + 1; /* plus trailing zero */ |
| 1193 | } |
| 1194 | envno++; /* plus the terminating zero */ |
| 1195 | debug ("## %u envvars total size %u ", envno, envsz); |
| 1196 | |
| 1197 | top = (top - sizeof(char **)*envno) & ~0xF; |
| 1198 | fwenv = (char **)top; |
| 1199 | debug ("## fwenv at 0x%08lX ", top); |
| 1200 | |
| 1201 | top = (top - envsz) & ~0xF; |
| 1202 | s = (char *)top; |
| 1203 | ss = fwenv; |
| 1204 | |
| 1205 | /* now copy them */ |
| 1206 | for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) { |
| 1207 | for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) |
| 1208 | ; |
| 1209 | *ss++ = s; |
| 1210 | for (j = i; j < nxt; ++j) |
| 1211 | *s++ = env_get_char(j); |
| 1212 | *s++ = '\0'; |
| 1213 | } |
| 1214 | *ss++ = NULL; /* terminate */ |
| 1215 | |
| 1216 | entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep); |
| 1217 | (*entry)(kbd, cmdline, fwenv, top); |
| 1218 | } |
| 1219 | #endif |
| 1220 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1221 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 1222 | #if defined(CONFIG_CMD_BOOTD) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1223 | int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 1224 | { |
| 1225 | int rcode = 0; |
| 1226 | #ifndef CFG_HUSH_PARSER |
| 1227 | if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1; |
| 1228 | #else |
| 1229 | if (parse_string_outer(getenv("bootcmd"), |
| 1230 | FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1; |
| 1231 | #endif |
| 1232 | return rcode; |
| 1233 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1234 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1235 | U_BOOT_CMD( |
| 1236 | boot, 1, 1, do_bootd, |
wdenk | 3086a97 | 2003-06-28 23:11:04 +0000 | [diff] [blame] | 1237 | "boot - boot default, i.e., run 'bootcmd'\n", |
| 1238 | NULL |
| 1239 | ); |
| 1240 | |
| 1241 | /* keep old command name "bootd" for backward compatibility */ |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1242 | U_BOOT_CMD( |
| 1243 | bootd, 1, 1, do_bootd, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1244 | "bootd - boot default, i.e., run 'bootcmd'\n", |
| 1245 | NULL |
| 1246 | ); |
| 1247 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1248 | #endif |
| 1249 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 1250 | #if defined(CONFIG_CMD_IMI) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1251 | int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 1252 | { |
| 1253 | int arg; |
| 1254 | ulong addr; |
| 1255 | int rcode=0; |
| 1256 | |
| 1257 | if (argc < 2) { |
| 1258 | return image_info (load_addr); |
| 1259 | } |
| 1260 | |
| 1261 | for (arg=1; arg <argc; ++arg) { |
| 1262 | addr = simple_strtoul(argv[arg], NULL, 16); |
| 1263 | if (image_info (addr) != 0) rcode = 1; |
| 1264 | } |
| 1265 | return rcode; |
| 1266 | } |
| 1267 | |
| 1268 | static int image_info (ulong addr) |
| 1269 | { |
| 1270 | ulong data, len, checksum; |
| 1271 | image_header_t *hdr = &header; |
| 1272 | |
| 1273 | printf ("\n## Checking Image at %08lx ...\n", addr); |
| 1274 | |
| 1275 | /* Copy header so we can blank CRC field for re-calculation */ |
| 1276 | memmove (&header, (char *)addr, sizeof(image_header_t)); |
| 1277 | |
| 1278 | if (ntohl(hdr->ih_magic) != IH_MAGIC) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1279 | puts (" Bad Magic Number\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1280 | return 1; |
| 1281 | } |
| 1282 | |
| 1283 | data = (ulong)&header; |
| 1284 | len = sizeof(image_header_t); |
| 1285 | |
| 1286 | checksum = ntohl(hdr->ih_hcrc); |
| 1287 | hdr->ih_hcrc = 0; |
| 1288 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 1289 | if (crc32 (0, (uchar *)data, len) != checksum) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1290 | puts (" Bad Header Checksum\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1291 | return 1; |
| 1292 | } |
| 1293 | |
| 1294 | /* for multi-file images we need the data part, too */ |
| 1295 | print_image_hdr ((image_header_t *)addr); |
| 1296 | |
| 1297 | data = addr + sizeof(image_header_t); |
| 1298 | len = ntohl(hdr->ih_size); |
| 1299 | |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1300 | puts (" Verifying Checksum ... "); |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 1301 | if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1302 | puts (" Bad Data CRC\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1303 | return 1; |
| 1304 | } |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1305 | puts ("OK\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1306 | return 0; |
| 1307 | } |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1308 | |
| 1309 | U_BOOT_CMD( |
| 1310 | iminfo, CFG_MAXARGS, 1, do_iminfo, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1311 | "iminfo - print header information for application image\n", |
| 1312 | "addr [addr ...]\n" |
| 1313 | " - print header information for application image starting at\n" |
| 1314 | " address 'addr' in memory; this includes verification of the\n" |
| 1315 | " image contents (magic number, header and payload checksums)\n" |
| 1316 | ); |
| 1317 | |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame^] | 1318 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1319 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 1320 | #if defined(CONFIG_CMD_IMLS) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1321 | /*----------------------------------------------------------------------- |
| 1322 | * List all images found in flash. |
| 1323 | */ |
| 1324 | int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 1325 | { |
| 1326 | flash_info_t *info; |
| 1327 | int i, j; |
| 1328 | image_header_t *hdr; |
wdenk | c6abb7e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 1329 | ulong data, len, checksum; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1330 | |
| 1331 | for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) { |
| 1332 | if (info->flash_id == FLASH_UNKNOWN) |
| 1333 | goto next_bank; |
Marian Balakowicz | 513b4a1 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 1334 | for (j=0; j<info->sector_count; ++j) { |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1335 | |
| 1336 | if (!(hdr=(image_header_t *)info->start[j]) || |
| 1337 | (ntohl(hdr->ih_magic) != IH_MAGIC)) |
| 1338 | goto next_sector; |
| 1339 | |
| 1340 | /* Copy header so we can blank CRC field for re-calculation */ |
| 1341 | memmove (&header, (char *)hdr, sizeof(image_header_t)); |
| 1342 | |
| 1343 | checksum = ntohl(header.ih_hcrc); |
| 1344 | header.ih_hcrc = 0; |
| 1345 | |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 1346 | if (crc32 (0, (uchar *)&header, sizeof(image_header_t)) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1347 | != checksum) |
| 1348 | goto next_sector; |
| 1349 | |
| 1350 | printf ("Image at %08lX:\n", (ulong)hdr); |
| 1351 | print_image_hdr( hdr ); |
wdenk | c6abb7e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 1352 | |
| 1353 | data = (ulong)hdr + sizeof(image_header_t); |
| 1354 | len = ntohl(hdr->ih_size); |
| 1355 | |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1356 | puts (" Verifying Checksum ... "); |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 1357 | if (crc32 (0, (uchar *)data, len) != ntohl(hdr->ih_dcrc)) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1358 | puts (" Bad Data CRC\n"); |
wdenk | c6abb7e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 1359 | } |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1360 | puts ("OK\n"); |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 1361 | next_sector: ; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1362 | } |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 1363 | next_bank: ; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | return (0); |
| 1367 | } |
| 1368 | |
| 1369 | U_BOOT_CMD( |
| 1370 | imls, 1, 1, do_imls, |
| 1371 | "imls - list all images found in flash\n", |
| 1372 | "\n" |
| 1373 | " - Prints information about all images found at sector\n" |
| 1374 | " boundaries in flash.\n" |
| 1375 | ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame^] | 1376 | #endif |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1377 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1378 | void |
| 1379 | print_image_hdr (image_header_t *hdr) |
| 1380 | { |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 1381 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1382 | time_t timestamp = (time_t)ntohl(hdr->ih_time); |
| 1383 | struct rtc_time tm; |
| 1384 | #endif |
| 1385 | |
| 1386 | printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name); |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 1387 | #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1388 | to_tm (timestamp, &tm); |
| 1389 | printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n", |
| 1390 | tm.tm_year, tm.tm_mon, tm.tm_mday, |
| 1391 | tm.tm_hour, tm.tm_min, tm.tm_sec); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame^] | 1392 | #endif |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1393 | puts (" Image Type: "); print_type(hdr); |
| 1394 | printf ("\n Data Size: %d Bytes = ", ntohl(hdr->ih_size)); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1395 | print_size (ntohl(hdr->ih_size), "\n"); |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1396 | printf (" Load Address: %08x\n" |
| 1397 | " Entry Point: %08x\n", |
| 1398 | ntohl(hdr->ih_load), ntohl(hdr->ih_ep)); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1399 | |
| 1400 | if (hdr->ih_type == IH_TYPE_MULTI) { |
| 1401 | int i; |
| 1402 | ulong len; |
| 1403 | ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t)); |
| 1404 | |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1405 | puts (" Contents:\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1406 | for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) { |
| 1407 | printf (" Image %d: %8ld Bytes = ", i, len); |
| 1408 | print_size (len, "\n"); |
| 1409 | } |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | |
| 1414 | static void |
| 1415 | print_type (image_header_t *hdr) |
| 1416 | { |
| 1417 | char *os, *arch, *type, *comp; |
| 1418 | |
| 1419 | switch (hdr->ih_os) { |
| 1420 | case IH_OS_INVALID: os = "Invalid OS"; break; |
| 1421 | case IH_OS_NETBSD: os = "NetBSD"; break; |
| 1422 | case IH_OS_LINUX: os = "Linux"; break; |
| 1423 | case IH_OS_VXWORKS: os = "VxWorks"; break; |
| 1424 | case IH_OS_QNX: os = "QNX"; break; |
| 1425 | case IH_OS_U_BOOT: os = "U-Boot"; break; |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 1426 | case IH_OS_RTEMS: os = "RTEMS"; break; |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 1427 | #ifdef CONFIG_ARTOS |
| 1428 | case IH_OS_ARTOS: os = "ARTOS"; break; |
| 1429 | #endif |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 1430 | #ifdef CONFIG_LYNXKDI |
| 1431 | case IH_OS_LYNXOS: os = "LynxOS"; break; |
| 1432 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1433 | default: os = "Unknown OS"; break; |
| 1434 | } |
| 1435 | |
| 1436 | switch (hdr->ih_arch) { |
| 1437 | case IH_CPU_INVALID: arch = "Invalid CPU"; break; |
| 1438 | case IH_CPU_ALPHA: arch = "Alpha"; break; |
| 1439 | case IH_CPU_ARM: arch = "ARM"; break; |
Stefan Roese | df86f15 | 2006-10-09 12:55:38 +0200 | [diff] [blame] | 1440 | case IH_CPU_AVR32: arch = "AVR32"; break; |
Wolfgang Denk | b284679 | 2007-03-22 00:13:12 +0100 | [diff] [blame] | 1441 | case IH_CPU_BLACKFIN: arch = "Blackfin"; break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1442 | case IH_CPU_I386: arch = "Intel x86"; break; |
| 1443 | case IH_CPU_IA64: arch = "IA64"; break; |
Wolfgang Denk | b284679 | 2007-03-22 00:13:12 +0100 | [diff] [blame] | 1444 | case IH_CPU_M68K: arch = "M68K"; break; |
| 1445 | case IH_CPU_MICROBLAZE: arch = "Microblaze"; break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1446 | case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break; |
Wolfgang Denk | b284679 | 2007-03-22 00:13:12 +0100 | [diff] [blame] | 1447 | case IH_CPU_MIPS: arch = "MIPS"; break; |
| 1448 | case IH_CPU_NIOS2: arch = "Nios-II"; break; |
| 1449 | case IH_CPU_NIOS: arch = "Nios"; break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1450 | case IH_CPU_PPC: arch = "PowerPC"; break; |
| 1451 | case IH_CPU_S390: arch = "IBM S390"; break; |
| 1452 | case IH_CPU_SH: arch = "SuperH"; break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1453 | case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break; |
Wolfgang Denk | b284679 | 2007-03-22 00:13:12 +0100 | [diff] [blame] | 1454 | case IH_CPU_SPARC: arch = "SPARC"; break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1455 | default: arch = "Unknown Architecture"; break; |
| 1456 | } |
| 1457 | |
| 1458 | switch (hdr->ih_type) { |
| 1459 | case IH_TYPE_INVALID: type = "Invalid Image"; break; |
| 1460 | case IH_TYPE_STANDALONE:type = "Standalone Program"; break; |
| 1461 | case IH_TYPE_KERNEL: type = "Kernel Image"; break; |
| 1462 | case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break; |
| 1463 | case IH_TYPE_MULTI: type = "Multi-File Image"; break; |
| 1464 | case IH_TYPE_FIRMWARE: type = "Firmware"; break; |
| 1465 | case IH_TYPE_SCRIPT: type = "Script"; break; |
Matthew McClintock | 16485a6 | 2006-08-16 10:54:09 -0500 | [diff] [blame] | 1466 | case IH_TYPE_FLATDT: type = "Flat Device Tree"; break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1467 | default: type = "Unknown Image"; break; |
| 1468 | } |
| 1469 | |
| 1470 | switch (hdr->ih_comp) { |
| 1471 | case IH_COMP_NONE: comp = "uncompressed"; break; |
| 1472 | case IH_COMP_GZIP: comp = "gzip compressed"; break; |
| 1473 | case IH_COMP_BZIP2: comp = "bzip2 compressed"; break; |
| 1474 | default: comp = "unknown compression"; break; |
| 1475 | } |
| 1476 | |
| 1477 | printf ("%s %s %s (%s)", arch, os, type, comp); |
| 1478 | } |
| 1479 | |
| 1480 | #define ZALLOC_ALIGNMENT 16 |
| 1481 | |
| 1482 | static void *zalloc(void *x, unsigned items, unsigned size) |
| 1483 | { |
| 1484 | void *p; |
| 1485 | |
| 1486 | size *= items; |
| 1487 | size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1); |
| 1488 | |
| 1489 | p = malloc (size); |
| 1490 | |
| 1491 | return (p); |
| 1492 | } |
| 1493 | |
| 1494 | static void zfree(void *x, void *addr, unsigned nb) |
| 1495 | { |
| 1496 | free (addr); |
| 1497 | } |
| 1498 | |
| 1499 | #define HEAD_CRC 2 |
| 1500 | #define EXTRA_FIELD 4 |
| 1501 | #define ORIG_NAME 8 |
| 1502 | #define COMMENT 0x10 |
| 1503 | #define RESERVED 0xe0 |
| 1504 | |
| 1505 | #define DEFLATED 8 |
| 1506 | |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 1507 | int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1508 | { |
| 1509 | z_stream s; |
| 1510 | int r, i, flags; |
| 1511 | |
| 1512 | /* skip header */ |
| 1513 | i = 10; |
| 1514 | flags = src[3]; |
| 1515 | if (src[2] != DEFLATED || (flags & RESERVED) != 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1516 | puts ("Error: Bad gzipped data\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1517 | return (-1); |
| 1518 | } |
| 1519 | if ((flags & EXTRA_FIELD) != 0) |
| 1520 | i = 12 + src[10] + (src[11] << 8); |
| 1521 | if ((flags & ORIG_NAME) != 0) |
| 1522 | while (src[i++] != 0) |
| 1523 | ; |
| 1524 | if ((flags & COMMENT) != 0) |
| 1525 | while (src[i++] != 0) |
| 1526 | ; |
| 1527 | if ((flags & HEAD_CRC) != 0) |
| 1528 | i += 2; |
| 1529 | if (i >= *lenp) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 1530 | puts ("Error: gunzip out of data in header\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1531 | return (-1); |
| 1532 | } |
| 1533 | |
| 1534 | s.zalloc = zalloc; |
| 1535 | s.zfree = zfree; |
| 1536 | #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) |
| 1537 | s.outcb = (cb_func)WATCHDOG_RESET; |
| 1538 | #else |
| 1539 | s.outcb = Z_NULL; |
| 1540 | #endif /* CONFIG_HW_WATCHDOG */ |
| 1541 | |
| 1542 | r = inflateInit2(&s, -MAX_WBITS); |
| 1543 | if (r != Z_OK) { |
| 1544 | printf ("Error: inflateInit2() returned %d\n", r); |
| 1545 | return (-1); |
| 1546 | } |
| 1547 | s.next_in = src + i; |
| 1548 | s.avail_in = *lenp - i; |
| 1549 | s.next_out = dst; |
| 1550 | s.avail_out = dstlen; |
| 1551 | r = inflate(&s, Z_FINISH); |
| 1552 | if (r != Z_OK && r != Z_STREAM_END) { |
| 1553 | printf ("Error: inflate() returned %d\n", r); |
| 1554 | return (-1); |
| 1555 | } |
| 1556 | *lenp = s.next_out - (unsigned char *) dst; |
| 1557 | inflateEnd(&s); |
| 1558 | |
| 1559 | return (0); |
| 1560 | } |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 1561 | |
| 1562 | #ifdef CONFIG_BZIP2 |
| 1563 | void bz_internal_error(int errcode) |
| 1564 | { |
| 1565 | printf ("BZIP2 internal error %d\n", errcode); |
| 1566 | } |
| 1567 | #endif /* CONFIG_BZIP2 */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1568 | |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 1569 | static void |
| 1570 | do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 1571 | ulong addr, ulong *len_ptr, int verify) |
| 1572 | { |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 1573 | image_header_t *hdr = &header; |
| 1574 | void (*entry_point)(bd_t *); |
| 1575 | |
Wolfgang Denk | b6929f9 | 2006-03-12 01:59:35 +0100 | [diff] [blame] | 1576 | entry_point = (void (*)(bd_t *)) ntohl(hdr->ih_ep); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 1577 | |
| 1578 | printf ("## Transferring control to RTEMS (at address %08lx) ...\n", |
| 1579 | (ulong)entry_point); |
| 1580 | |
| 1581 | SHOW_BOOT_PROGRESS (15); |
| 1582 | |
| 1583 | /* |
| 1584 | * RTEMS Parameters: |
| 1585 | * r3: ptr to board info data |
| 1586 | */ |
| 1587 | |
| 1588 | (*entry_point ) ( gd->bd ); |
| 1589 | } |
| 1590 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 1591 | #if defined(CONFIG_CMD_ELF) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1592 | static void |
| 1593 | do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 1594 | ulong addr, ulong *len_ptr, int verify) |
| 1595 | { |
| 1596 | image_header_t *hdr = &header; |
| 1597 | char str[80]; |
| 1598 | |
Wolfgang Denk | b6929f9 | 2006-03-12 01:59:35 +0100 | [diff] [blame] | 1599 | sprintf(str, "%x", ntohl(hdr->ih_ep)); /* write entry-point into string */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1600 | setenv("loadaddr", str); |
| 1601 | do_bootvx(cmdtp, 0, 0, NULL); |
| 1602 | } |
| 1603 | |
| 1604 | static void |
| 1605 | do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 1606 | ulong addr, ulong *len_ptr, int verify) |
| 1607 | { |
| 1608 | image_header_t *hdr = &header; |
| 1609 | char *local_args[2]; |
| 1610 | char str[16]; |
| 1611 | |
Wolfgang Denk | b6929f9 | 2006-03-12 01:59:35 +0100 | [diff] [blame] | 1612 | sprintf(str, "%x", ntohl(hdr->ih_ep)); /* write entry-point into string */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1613 | local_args[0] = argv[0]; |
| 1614 | local_args[1] = str; /* and provide it via the arguments */ |
| 1615 | do_bootelf(cmdtp, 0, 2, local_args); |
| 1616 | } |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame^] | 1617 | #endif |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 1618 | |
| 1619 | #ifdef CONFIG_LYNXKDI |
| 1620 | static void |
| 1621 | do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag, |
| 1622 | int argc, char *argv[], |
| 1623 | ulong addr, |
| 1624 | ulong *len_ptr, |
| 1625 | int verify) |
| 1626 | { |
| 1627 | lynxkdi_boot( &header ); |
| 1628 | } |
| 1629 | |
| 1630 | #endif /* CONFIG_LYNXKDI */ |