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