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