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