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