wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1 | /* |
Stefan Roese | 5d5ce29 | 2006-03-13 11:16:36 +0100 | [diff] [blame] | 2 | * (C) Copyright 2000-2006 |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
Marian Balakowicz | 41d71ed | 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 | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 35 | #include <bzlib.h> |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 36 | #include <environment.h> |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 37 | #include <lmb.h> |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 38 | #include <asm/byteorder.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 39 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 40 | #ifdef CFG_HUSH_PARSER |
| 41 | #include <hush.h> |
| 42 | #endif |
| 43 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 44 | DECLARE_GLOBAL_DATA_PTR; |
| 45 | |
| 46 | extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp); |
| 47 | #ifndef CFG_BOOTM_LEN |
| 48 | #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */ |
| 49 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 50 | |
Marian Balakowicz | be946ba | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 51 | #ifdef CONFIG_BZIP2 |
| 52 | extern void bz_internal_error(int); |
| 53 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 54 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 55 | #if defined(CONFIG_CMD_IMI) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 56 | static int image_info (unsigned long addr); |
| 57 | #endif |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 58 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 59 | #if defined(CONFIG_CMD_IMLS) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 60 | #include <flash.h> |
Marian Balakowicz | 513b4a1 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 61 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 62 | static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 63 | #endif |
| 64 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 65 | #ifdef CONFIG_SILENT_CONSOLE |
| 66 | static void fixup_silent_linux (void); |
| 67 | #endif |
| 68 | |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 69 | static image_header_t *image_get_kernel (ulong img_addr, int verify); |
| 70 | #if defined(CONFIG_FIT) |
| 71 | static int fit_check_kernel (const void *fit, int os_noffset, int verify); |
| 72 | #endif |
| 73 | |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 74 | static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 75 | bootm_headers_t *images, ulong *os_data, ulong *os_len); |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 76 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Continue booting an OS image; caller already has: |
| 80 | * - copied image header to global variable `header' |
| 81 | * - checked header magic number, checksums (both header & image), |
| 82 | * - verified image architecture (PPC) and type (KERNEL or MULTI), |
| 83 | * - loaded (first part of) image to header load address, |
| 84 | * - disabled interrupts. |
| 85 | */ |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 86 | typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 87 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 88 | bootm_headers_t *images); /* pointers to os/initrd/fdt */ |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 89 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 90 | extern boot_os_fn do_bootm_linux; |
| 91 | static boot_os_fn do_bootm_netbsd; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 92 | #if defined(CONFIG_LYNXKDI) |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 93 | static boot_os_fn do_bootm_lynxkdi; |
| 94 | extern void lynxkdi_boot (image_header_t *); |
wdenk | 808532a | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 95 | #endif |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 96 | static boot_os_fn do_bootm_rtems; |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 97 | #if defined(CONFIG_CMD_ELF) |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 98 | static boot_os_fn do_bootm_vxworks; |
| 99 | static boot_os_fn do_bootm_qnxelf; |
| 100 | int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 101 | int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 102 | #endif |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 103 | #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 104 | extern uchar (*env_get_char)(int); /* Returns a character from the environment */ |
| 105 | static boot_os_fn do_bootm_artos; |
Stefan Roese | 5d5ce29 | 2006-03-13 11:16:36 +0100 | [diff] [blame] | 106 | #endif |
| 107 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 108 | ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */ |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 109 | static bootm_headers_t images; /* pointers to os/initrd/fdt images */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 110 | |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 111 | void __board_lmb_reserve(struct lmb *lmb) |
| 112 | { |
| 113 | /* please define platform specific board_lmb_reserve() */ |
| 114 | } |
| 115 | void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve"))); |
| 116 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 117 | |
| 118 | /*******************************************************************/ |
| 119 | /* bootm - boot application image from image in memory */ |
| 120 | /*******************************************************************/ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 121 | int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 122 | { |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 123 | ulong iflag; |
Marian Balakowicz | 05c1d3f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 124 | const char *type_name; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 125 | uint unc_len = CFG_BOOTM_LEN; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 126 | uint8_t comp, type, os; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 127 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 128 | void *os_hdr; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 129 | ulong os_data, os_len; |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 130 | ulong image_start, image_end; |
| 131 | ulong load_start, load_end; |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 132 | ulong mem_start, mem_size; |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 133 | |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 134 | struct lmb lmb; |
| 135 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 136 | memset ((void *)&images, 0, sizeof (images)); |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 137 | images.verify = getenv_verify(); |
Kumar Gala | fb71ccf | 2008-02-27 21:51:48 -0600 | [diff] [blame] | 138 | images.autostart = getenv_autostart(); |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 139 | images.lmb = &lmb; |
| 140 | |
| 141 | lmb_init(&lmb); |
| 142 | |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 143 | mem_start = getenv_bootm_low(); |
| 144 | mem_size = getenv_bootm_size(); |
| 145 | |
| 146 | lmb_add(&lmb, mem_start, mem_size); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 147 | |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 148 | board_lmb_reserve(&lmb); |
| 149 | |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 150 | /* get kernel image header, start address and length */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 151 | os_hdr = boot_get_kernel (cmdtp, flag, argc, argv, |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 152 | &images, &os_data, &os_len); |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 153 | if (os_len == 0) { |
| 154 | puts ("ERROR: can't get kernel image!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 155 | return 1; |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 156 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 157 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 158 | show_boot_progress (6); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 159 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 160 | /* get image parameters */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 161 | switch (genimg_get_format (os_hdr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 162 | case IMAGE_FORMAT_LEGACY: |
| 163 | type = image_get_type (os_hdr); |
| 164 | comp = image_get_comp (os_hdr); |
| 165 | os = image_get_os (os_hdr); |
| 166 | |
| 167 | image_end = image_get_image_end (os_hdr); |
| 168 | load_start = image_get_load (os_hdr); |
| 169 | break; |
| 170 | #if defined(CONFIG_FIT) |
| 171 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | 61c1ad5 | 2008-03-12 10:32:59 +0100 | [diff] [blame^] | 172 | if (fit_image_get_type (images.fit_hdr_os, |
| 173 | images.fit_noffset_os, &type)) { |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 174 | puts ("Can't get image type!\n"); |
| 175 | return 1; |
| 176 | } |
| 177 | |
Marian Balakowicz | 61c1ad5 | 2008-03-12 10:32:59 +0100 | [diff] [blame^] | 178 | if (fit_image_get_comp (images.fit_hdr_os, |
| 179 | images.fit_noffset_os, &comp)) { |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 180 | puts ("Can't get image compression!\n"); |
| 181 | return 1; |
| 182 | } |
| 183 | |
Marian Balakowicz | 61c1ad5 | 2008-03-12 10:32:59 +0100 | [diff] [blame^] | 184 | if (fit_image_get_os (images.fit_hdr_os, |
| 185 | images.fit_noffset_os, &os)) { |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 186 | puts ("Can't get image OS!\n"); |
| 187 | return 1; |
| 188 | } |
| 189 | |
| 190 | image_end = fit_get_end (images.fit_hdr_os); |
| 191 | |
Marian Balakowicz | 61c1ad5 | 2008-03-12 10:32:59 +0100 | [diff] [blame^] | 192 | if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os, |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 193 | &load_start)) { |
| 194 | puts ("Can't get image load address!\n"); |
| 195 | return 1; |
| 196 | } |
| 197 | break; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 198 | #endif |
| 199 | default: |
| 200 | puts ("ERROR: unknown image format type!\n"); |
| 201 | return 1; |
| 202 | } |
| 203 | |
| 204 | image_start = (ulong)os_hdr; |
| 205 | load_end = 0; |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 206 | type_name = genimg_get_type_name (type); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 207 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 208 | /* |
| 209 | * We have reached the point of no return: we are going to |
| 210 | * overwrite all exception vector code, so we cannot easily |
| 211 | * recover from any failures any more... |
| 212 | */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 213 | iflag = disable_interrupts(); |
| 214 | |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 215 | #ifdef CONFIG_AMIGAONEG3SE |
| 216 | /* |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 217 | * We've possible left the caches enabled during |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 218 | * bios emulation, so turn them off again |
| 219 | */ |
| 220 | icache_disable(); |
| 221 | invalidate_l1_instruction_cache(); |
| 222 | flush_data_cache(); |
| 223 | dcache_disable(); |
| 224 | #endif |
| 225 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 226 | switch (comp) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 227 | case IH_COMP_NONE: |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 228 | if (load_start == (ulong)os_hdr) { |
Marian Balakowicz | 05c1d3f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 229 | printf (" XIP %s ... ", type_name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 230 | } else { |
Marian Balakowicz | 05c1d3f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 231 | printf (" Loading %s ... ", type_name); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 232 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 233 | memmove_wd ((void *)load_start, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 234 | (void *)os_data, os_len, CHUNKSZ); |
Marian Balakowicz | f9a67bd | 2008-01-08 18:11:45 +0100 | [diff] [blame] | 235 | |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 236 | load_end = load_start + os_len; |
Marian Balakowicz | f9a67bd | 2008-01-08 18:11:45 +0100 | [diff] [blame] | 237 | puts("OK\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 238 | } |
| 239 | break; |
| 240 | case IH_COMP_GZIP: |
Marian Balakowicz | 05c1d3f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 241 | printf (" Uncompressing %s ... ", type_name); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 242 | if (gunzip ((void *)load_start, unc_len, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 243 | (uchar *)os_data, &os_len) != 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 244 | puts ("GUNZIP ERROR - must RESET board to recover\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 245 | show_boot_progress (-6); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 246 | do_reset (cmdtp, flag, argc, argv); |
| 247 | } |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 248 | |
| 249 | load_end = load_start + os_len; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 250 | break; |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 251 | #ifdef CONFIG_BZIP2 |
| 252 | case IH_COMP_BZIP2: |
Marian Balakowicz | 05c1d3f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 253 | printf (" Uncompressing %s ... ", type_name); |
wdenk | 2cefd15 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 254 | /* |
| 255 | * If we've got less than 4 MB of malloc() space, |
| 256 | * use slower decompression algorithm which requires |
| 257 | * at most 2300 KB of memory. |
| 258 | */ |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 259 | int i = BZ2_bzBuffToBuffDecompress ((char*)load_start, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 260 | &unc_len, (char *)os_data, os_len, |
| 261 | CFG_MALLOC_LEN < (4096 * 1024), 0); |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 262 | if (i != BZ_OK) { |
| 263 | printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 264 | show_boot_progress (-6); |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 265 | do_reset (cmdtp, flag, argc, argv); |
| 266 | } |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 267 | |
| 268 | load_end = load_start + unc_len; |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 269 | break; |
| 270 | #endif /* CONFIG_BZIP2 */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 271 | default: |
| 272 | if (iflag) |
| 273 | enable_interrupts(); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 274 | printf ("Unimplemented compression type %d\n", comp); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 275 | show_boot_progress (-7); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 276 | return 1; |
| 277 | } |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 278 | puts ("OK\n"); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 279 | debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 280 | show_boot_progress (7); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 281 | |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 282 | if ((load_start < image_end) && (load_end > image_start)) { |
| 283 | debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end); |
| 284 | debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end); |
| 285 | |
| 286 | puts ("ERROR: image overwritten - must RESET the board to recover.\n"); |
| 287 | do_reset (cmdtp, flag, argc, argv); |
| 288 | } |
| 289 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 290 | show_boot_progress (8); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 291 | |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 292 | lmb_reserve(&lmb, load_start, (load_end - load_start)); |
| 293 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 294 | switch (os) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 295 | default: /* handled by (original) Linux case */ |
| 296 | case IH_OS_LINUX: |
wdenk | 808532a | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 297 | #ifdef CONFIG_SILENT_CONSOLE |
| 298 | fixup_silent_linux(); |
| 299 | #endif |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 300 | do_bootm_linux (cmdtp, flag, argc, argv, &images); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 301 | break; |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 302 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 303 | case IH_OS_NETBSD: |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 304 | do_bootm_netbsd (cmdtp, flag, argc, argv, &images); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 305 | break; |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 306 | |
| 307 | #ifdef CONFIG_LYNXKDI |
| 308 | case IH_OS_LYNXOS: |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 309 | do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images); |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 310 | break; |
| 311 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 312 | |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 313 | case IH_OS_RTEMS: |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 314 | do_bootm_rtems (cmdtp, flag, argc, argv, &images); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 315 | break; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 316 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 317 | #if defined(CONFIG_CMD_ELF) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 318 | case IH_OS_VXWORKS: |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 319 | do_bootm_vxworks (cmdtp, flag, argc, argv, &images); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 320 | break; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 321 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 322 | case IH_OS_QNX: |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 323 | do_bootm_qnxelf (cmdtp, flag, argc, argv, &images); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 324 | break; |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 325 | #endif |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 326 | |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 327 | #ifdef CONFIG_ARTOS |
| 328 | case IH_OS_ARTOS: |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 329 | do_bootm_artos (cmdtp, flag, argc, argv, &images); |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 330 | break; |
| 331 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 334 | show_boot_progress (-9); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 335 | #ifdef DEBUG |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 336 | puts ("\n## Control returned to monitor - resetting...\n"); |
Marian Balakowicz | 9c22026 | 2008-03-12 10:14:57 +0100 | [diff] [blame] | 337 | if (images.autostart) |
| 338 | do_reset (cmdtp, flag, argc, argv); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 339 | #endif |
Marian Balakowicz | 9c22026 | 2008-03-12 10:14:57 +0100 | [diff] [blame] | 340 | if (!images.autostart && iflag) |
| 341 | enable_interrupts(); |
| 342 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 343 | return 1; |
| 344 | } |
| 345 | |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 346 | /** |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 347 | * image_get_kernel - verify legacy format kernel image |
| 348 | * @img_addr: in RAM address of the legacy format image to be verified |
| 349 | * @verify: data CRC verification flag |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 350 | * |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 351 | * image_get_kernel() verifies legacy image integrity and returns pointer to |
| 352 | * legacy image header if image verification was completed successfully. |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 353 | * |
| 354 | * returns: |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 355 | * pointer to a legacy image header if valid image was found |
| 356 | * otherwise return NULL |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 357 | */ |
Marian Balakowicz | 59504f6 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 358 | static image_header_t *image_get_kernel (ulong img_addr, int verify) |
| 359 | { |
| 360 | image_header_t *hdr = (image_header_t *)img_addr; |
| 361 | |
| 362 | if (!image_check_magic(hdr)) { |
| 363 | puts ("Bad Magic Number\n"); |
| 364 | show_boot_progress (-1); |
| 365 | return NULL; |
| 366 | } |
| 367 | show_boot_progress (2); |
| 368 | |
| 369 | if (!image_check_hcrc (hdr)) { |
| 370 | puts ("Bad Header Checksum\n"); |
| 371 | show_boot_progress (-2); |
| 372 | return NULL; |
| 373 | } |
| 374 | |
| 375 | show_boot_progress (3); |
| 376 | image_print_contents (hdr); |
| 377 | |
| 378 | if (verify) { |
| 379 | puts (" Verifying Checksum ... "); |
| 380 | if (!image_check_dcrc (hdr)) { |
| 381 | printf ("Bad Data CRC\n"); |
| 382 | show_boot_progress (-3); |
| 383 | return NULL; |
| 384 | } |
| 385 | puts ("OK\n"); |
| 386 | } |
| 387 | show_boot_progress (4); |
| 388 | |
| 389 | if (!image_check_target_arch (hdr)) { |
| 390 | printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr)); |
| 391 | show_boot_progress (-4); |
| 392 | return NULL; |
| 393 | } |
| 394 | return hdr; |
| 395 | } |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 396 | |
| 397 | /** |
| 398 | * fit_check_kernel - verify FIT format kernel subimage |
| 399 | * @fit_hdr: pointer to the FIT image header |
| 400 | * os_noffset: kernel subimage node offset within FIT image |
| 401 | * @verify: data CRC verification flag |
| 402 | * |
| 403 | * fit_check_kernel() verifies integrity of the kernel subimage and from |
| 404 | * specified FIT image. |
| 405 | * |
| 406 | * returns: |
| 407 | * 1, on success |
| 408 | * 0, on failure |
| 409 | */ |
| 410 | #if defined (CONFIG_FIT) |
| 411 | static int fit_check_kernel (const void *fit, int os_noffset, int verify) |
| 412 | { |
| 413 | fit_image_print (fit, os_noffset, " "); |
| 414 | |
| 415 | if (verify) { |
| 416 | puts (" Verifying Hash Integrity ... "); |
| 417 | if (!fit_image_check_hashes (fit, os_noffset)) { |
| 418 | puts ("Bad Data Hash\n"); |
| 419 | return 0; |
| 420 | } |
| 421 | puts ("OK\n"); |
| 422 | } |
| 423 | |
| 424 | if (!fit_image_check_target_arch (fit, os_noffset)) { |
| 425 | puts ("Unsupported Architecture\n"); |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) { |
| 430 | puts ("Not a kernel image\n"); |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | return 1; |
| 435 | } |
| 436 | #endif /* CONFIG_FIT */ |
Marian Balakowicz | 59504f6 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 437 | |
| 438 | /** |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 439 | * boot_get_kernel - find kernel image |
Marian Balakowicz | 59504f6 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 440 | * @os_data: pointer to a ulong variable, will hold os data start address |
| 441 | * @os_len: pointer to a ulong variable, will hold os data length |
| 442 | * |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 443 | * boot_get_kernel() tries to find a kernel image, verifies its integrity |
Marian Balakowicz | 59504f6 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 444 | * and locates kernel data. |
| 445 | * |
| 446 | * returns: |
| 447 | * pointer to image header if valid image was found, plus kernel start |
| 448 | * address and length, otherwise NULL |
| 449 | */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 450 | static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 451 | bootm_headers_t *images, ulong *os_data, ulong *os_len) |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 452 | { |
| 453 | image_header_t *hdr; |
| 454 | ulong img_addr; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 455 | #if defined(CONFIG_FIT) |
| 456 | void *fit_hdr; |
| 457 | const char *fit_uname_config = NULL; |
| 458 | const char *fit_uname_kernel = NULL; |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 459 | const void *data; |
| 460 | size_t len; |
| 461 | int conf_noffset; |
| 462 | int os_noffset; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 463 | #endif |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 464 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 465 | /* find out kernel image address */ |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 466 | if (argc < 2) { |
| 467 | img_addr = load_addr; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 468 | debug ("* kernel: default image load address = 0x%08lx\n", |
| 469 | load_addr); |
| 470 | #if defined(CONFIG_FIT) |
| 471 | } else if (fit_parse_conf (argv[1], load_addr, &img_addr, |
| 472 | &fit_uname_config)) { |
| 473 | debug ("* kernel: config '%s' from image at 0x%08lx\n", |
| 474 | fit_uname_config, img_addr); |
| 475 | } else if (fit_parse_subimage (argv[1], load_addr, &img_addr, |
| 476 | &fit_uname_kernel)) { |
| 477 | debug ("* kernel: subimage '%s' from image at 0x%08lx\n", |
| 478 | fit_uname_kernel, img_addr); |
| 479 | #endif |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 480 | } else { |
| 481 | img_addr = simple_strtoul(argv[1], NULL, 16); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 482 | debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | show_boot_progress (1); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 486 | |
Marian Balakowicz | c536d6f | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 487 | /* copy from dataflash if needed */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 488 | img_addr = genimg_get_image (img_addr); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 489 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 490 | /* check image type, for FIT images get FIT kernel node */ |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 491 | *os_data = *os_len = 0; |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 492 | switch (genimg_get_format ((void *)img_addr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 493 | case IMAGE_FORMAT_LEGACY: |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 494 | printf ("## Booting kernel from Legacy Image at %08lx ...\n", |
| 495 | img_addr); |
Marian Balakowicz | 59504f6 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 496 | hdr = image_get_kernel (img_addr, images->verify); |
| 497 | if (!hdr) |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 498 | return NULL; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 499 | show_boot_progress (5); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 500 | |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 501 | /* get os_data and os_len */ |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 502 | switch (image_get_type (hdr)) { |
| 503 | case IH_TYPE_KERNEL: |
| 504 | *os_data = image_get_data (hdr); |
| 505 | *os_len = image_get_data_size (hdr); |
| 506 | break; |
| 507 | case IH_TYPE_MULTI: |
| 508 | image_multi_getimg (hdr, 0, os_data, os_len); |
| 509 | break; |
| 510 | default: |
| 511 | printf ("Wrong Image Type for %s command\n", cmdtp->name); |
| 512 | show_boot_progress (-5); |
| 513 | return NULL; |
| 514 | } |
| 515 | images->legacy_hdr_os = hdr; |
| 516 | images->legacy_hdr_valid = 1; |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 517 | |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 518 | break; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 519 | #if defined(CONFIG_FIT) |
| 520 | case IMAGE_FORMAT_FIT: |
| 521 | fit_hdr = (void *)img_addr; |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 522 | printf ("## Booting kernel from FIT Image at %08lx ...\n", |
| 523 | img_addr); |
| 524 | |
| 525 | if (!fit_check_format (fit_hdr)) { |
| 526 | puts ("Bad FIT kernel image format!\n"); |
| 527 | return NULL; |
| 528 | } |
| 529 | |
| 530 | if (!fit_uname_kernel) { |
| 531 | /* |
| 532 | * no kernel image node unit name, try to get config |
| 533 | * node first. If config unit node name is NULL |
| 534 | * fit_conf_get_node() will try to find default config node |
| 535 | */ |
| 536 | conf_noffset = fit_conf_get_node (fit_hdr, fit_uname_config); |
| 537 | if (conf_noffset < 0) |
| 538 | return NULL; |
| 539 | |
| 540 | os_noffset = fit_conf_get_kernel_node (fit_hdr, conf_noffset); |
| 541 | fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL); |
| 542 | } else { |
| 543 | /* get kernel component image node offset */ |
| 544 | os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel); |
| 545 | } |
| 546 | if (os_noffset < 0) |
| 547 | return NULL; |
| 548 | |
| 549 | printf (" Trying '%s' kernel subimage\n", fit_uname_kernel); |
| 550 | |
| 551 | if (!fit_check_kernel (fit_hdr, os_noffset, images->verify)) |
| 552 | return NULL; |
| 553 | |
| 554 | /* get kernel image data address and length */ |
| 555 | if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) { |
| 556 | puts ("Could not find kernel subimage data!\n"); |
| 557 | return NULL; |
| 558 | } |
| 559 | |
| 560 | *os_len = len; |
| 561 | *os_data = (ulong)data; |
| 562 | images->fit_hdr_os = fit_hdr; |
| 563 | images->fit_uname_os = fit_uname_kernel; |
Marian Balakowicz | 61c1ad5 | 2008-03-12 10:32:59 +0100 | [diff] [blame^] | 564 | images->fit_noffset_os = os_noffset; |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 565 | break; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 566 | #endif |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 567 | default: |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 568 | printf ("Wrong Image Format for %s command\n", cmdtp->name); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 569 | return NULL; |
| 570 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 571 | |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 572 | debug (" kernel data at 0x%08lx, len = 0x%08lx (%d)\n", |
| 573 | *os_data, *os_len, *os_len); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 574 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 575 | return (void *)img_addr; |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 576 | } |
| 577 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 578 | U_BOOT_CMD( |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 579 | bootm, CFG_MAXARGS, 1, do_bootm, |
| 580 | "bootm - boot application image from memory\n", |
| 581 | "[addr [arg ...]]\n - boot application image stored in memory\n" |
| 582 | "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n" |
| 583 | "\t'arg' can be the address of an initrd image\n" |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 584 | #if defined(CONFIG_OF_LIBFDT) |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 585 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
Detlev Zundel | e609916 | 2007-10-19 16:47:26 +0200 | [diff] [blame] | 586 | "\ta third argument is required which is the address of the\n" |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 587 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 588 | "\tuse a '-' for the second argument. If you do not pass a third\n" |
| 589 | "\ta bd_info struct will be passed instead\n" |
| 590 | #endif |
Marian Balakowicz | 9f8e4aa | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 591 | #if defined(CONFIG_FIT) |
| 592 | "\t\nFor the new multi component uImage format (FIT) addresses\n" |
| 593 | "\tmust be extened to include component or configuration unit name:\n" |
| 594 | "\taddr:<subimg_uname> - direct component image specification\n" |
| 595 | "\taddr#<conf_uname> - configuration specification\n" |
| 596 | "\tUse iminfo command to get the list of existing component\n" |
| 597 | "\timages and configurations.\n" |
| 598 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 599 | ); |
| 600 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 601 | /*******************************************************************/ |
| 602 | /* bootd - boot default image */ |
| 603 | /*******************************************************************/ |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 604 | #if defined(CONFIG_CMD_BOOTD) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 605 | int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 606 | { |
| 607 | int rcode = 0; |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 608 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 609 | #ifndef CFG_HUSH_PARSER |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 610 | if (run_command (getenv ("bootcmd"), flag) < 0) |
| 611 | rcode = 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 612 | #else |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 613 | if (parse_string_outer (getenv ("bootcmd"), |
| 614 | FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0) |
| 615 | rcode = 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 616 | #endif |
| 617 | return rcode; |
| 618 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 619 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 620 | U_BOOT_CMD( |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 621 | boot, 1, 1, do_bootd, |
| 622 | "boot - boot default, i.e., run 'bootcmd'\n", |
wdenk | 3086a97 | 2003-06-28 23:11:04 +0000 | [diff] [blame] | 623 | NULL |
| 624 | ); |
| 625 | |
| 626 | /* keep old command name "bootd" for backward compatibility */ |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 627 | U_BOOT_CMD( |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 628 | bootd, 1, 1, do_bootd, |
| 629 | "bootd - boot default, i.e., run 'bootcmd'\n", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 630 | NULL |
| 631 | ); |
| 632 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 633 | #endif |
| 634 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 635 | |
| 636 | /*******************************************************************/ |
| 637 | /* iminfo - print header info for a requested image */ |
| 638 | /*******************************************************************/ |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 639 | #if defined(CONFIG_CMD_IMI) |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 640 | int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 641 | { |
| 642 | int arg; |
| 643 | ulong addr; |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 644 | int rcode = 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 645 | |
| 646 | if (argc < 2) { |
| 647 | return image_info (load_addr); |
| 648 | } |
| 649 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 650 | for (arg = 1; arg < argc; ++arg) { |
| 651 | addr = simple_strtoul (argv[arg], NULL, 16); |
| 652 | if (image_info (addr) != 0) |
| 653 | rcode = 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 654 | } |
| 655 | return rcode; |
| 656 | } |
| 657 | |
| 658 | static int image_info (ulong addr) |
| 659 | { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 660 | void *hdr = (void *)addr; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 661 | |
| 662 | printf ("\n## Checking Image at %08lx ...\n", addr); |
| 663 | |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 664 | switch (genimg_get_format (hdr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 665 | case IMAGE_FORMAT_LEGACY: |
| 666 | puts (" Legacy image found\n"); |
| 667 | if (!image_check_magic (hdr)) { |
| 668 | puts (" Bad Magic Number\n"); |
| 669 | return 1; |
| 670 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 671 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 672 | if (!image_check_hcrc (hdr)) { |
| 673 | puts (" Bad Header Checksum\n"); |
| 674 | return 1; |
| 675 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 676 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 677 | image_print_contents (hdr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 678 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 679 | puts (" Verifying Checksum ... "); |
| 680 | if (!image_check_dcrc (hdr)) { |
| 681 | puts (" Bad Data CRC\n"); |
| 682 | return 1; |
| 683 | } |
| 684 | puts ("OK\n"); |
| 685 | return 0; |
| 686 | #if defined(CONFIG_FIT) |
| 687 | case IMAGE_FORMAT_FIT: |
| 688 | puts (" FIT image found\n"); |
Marian Balakowicz | cc1fd91 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 689 | |
| 690 | if (!fit_check_format (hdr)) { |
| 691 | puts ("Bad FIT image format!\n"); |
| 692 | return 1; |
| 693 | } |
| 694 | |
| 695 | fit_print_contents (hdr); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 696 | return 0; |
| 697 | #endif |
| 698 | default: |
| 699 | puts ("Unknown image format!\n"); |
| 700 | break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 701 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 702 | |
| 703 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 704 | } |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 705 | |
| 706 | U_BOOT_CMD( |
| 707 | iminfo, CFG_MAXARGS, 1, do_iminfo, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 708 | "iminfo - print header information for application image\n", |
| 709 | "addr [addr ...]\n" |
| 710 | " - print header information for application image starting at\n" |
| 711 | " address 'addr' in memory; this includes verification of the\n" |
| 712 | " image contents (magic number, header and payload checksums)\n" |
| 713 | ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 714 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 715 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 716 | |
| 717 | /*******************************************************************/ |
| 718 | /* imls - list all images found in flash */ |
| 719 | /*******************************************************************/ |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 720 | #if defined(CONFIG_CMD_IMLS) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 721 | int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 722 | { |
| 723 | flash_info_t *info; |
| 724 | int i, j; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 725 | void *hdr; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 726 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 727 | for (i = 0, info = &flash_info[0]; |
| 728 | i < CFG_MAX_FLASH_BANKS; ++i, ++info) { |
| 729 | |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 730 | if (info->flash_id == FLASH_UNKNOWN) |
| 731 | goto next_bank; |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 732 | for (j = 0; j < info->sector_count; ++j) { |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 733 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 734 | hdr = (void *)info->start[j]; |
| 735 | if (!hdr) |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 736 | goto next_sector; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 737 | |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 738 | switch (genimg_get_format (hdr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 739 | case IMAGE_FORMAT_LEGACY: |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 740 | if (!image_check_hcrc (hdr)) |
| 741 | goto next_sector; |
wdenk | c6abb7e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 742 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 743 | printf ("Legacy Image at %08lX:\n", (ulong)hdr); |
| 744 | image_print_contents (hdr); |
| 745 | |
| 746 | puts (" Verifying Checksum ... "); |
| 747 | if (!image_check_dcrc (hdr)) { |
| 748 | puts ("Bad Data CRC\n"); |
| 749 | } else { |
| 750 | puts ("OK\n"); |
| 751 | } |
| 752 | break; |
| 753 | #if defined(CONFIG_FIT) |
| 754 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | cc1fd91 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 755 | if (!fit_check_format (hdr)) |
| 756 | goto next_sector; |
| 757 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 758 | printf ("FIT Image at %08lX:\n", (ulong)hdr); |
Marian Balakowicz | cc1fd91 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 759 | fit_print_contents (hdr); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 760 | break; |
| 761 | #endif |
| 762 | default: |
| 763 | goto next_sector; |
wdenk | c6abb7e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 764 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 765 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 766 | next_sector: ; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 767 | } |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 768 | next_bank: ; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | return (0); |
| 772 | } |
| 773 | |
| 774 | U_BOOT_CMD( |
| 775 | imls, 1, 1, do_imls, |
| 776 | "imls - list all images found in flash\n", |
| 777 | "\n" |
| 778 | " - Prints information about all images found at sector\n" |
| 779 | " boundaries in flash.\n" |
| 780 | ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 781 | #endif |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 782 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 783 | /*******************************************************************/ |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 784 | /* helper routines */ |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 785 | /*******************************************************************/ |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 786 | #ifdef CONFIG_SILENT_CONSOLE |
| 787 | static void fixup_silent_linux () |
| 788 | { |
| 789 | char buf[256], *start, *end; |
| 790 | char *cmdline = getenv ("bootargs"); |
| 791 | |
| 792 | /* Only fix cmdline when requested */ |
| 793 | if (!(gd->flags & GD_FLG_SILENT)) |
| 794 | return; |
| 795 | |
| 796 | debug ("before silent fix-up: %s\n", cmdline); |
| 797 | if (cmdline) { |
| 798 | if ((start = strstr (cmdline, "console=")) != NULL) { |
| 799 | end = strchr (start, ' '); |
| 800 | strncpy (buf, cmdline, (start - cmdline + 8)); |
| 801 | if (end) |
| 802 | strcpy (buf + (start - cmdline + 8), end); |
| 803 | else |
| 804 | buf[start - cmdline + 8] = '\0'; |
| 805 | } else { |
| 806 | strcpy (buf, cmdline); |
| 807 | strcat (buf, " console="); |
| 808 | } |
| 809 | } else { |
| 810 | strcpy (buf, "console="); |
| 811 | } |
| 812 | |
| 813 | setenv ("bootargs", buf); |
| 814 | debug ("after silent fix-up: %s\n", buf); |
| 815 | } |
| 816 | #endif /* CONFIG_SILENT_CONSOLE */ |
| 817 | |
| 818 | |
| 819 | /*******************************************************************/ |
| 820 | /* OS booting routines */ |
| 821 | /*******************************************************************/ |
| 822 | |
| 823 | static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 824 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 825 | bootm_headers_t *images) |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 826 | { |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 827 | void (*loader)(bd_t *, image_header_t *, char *, char *); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 828 | image_header_t *os_hdr, *hdr; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 829 | ulong kernel_data, kernel_len; |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 830 | char *consdev; |
| 831 | char *cmdline; |
| 832 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 833 | #if defined(CONFIG_FIT) |
| 834 | if (!images->legacy_hdr_valid) { |
| 835 | fit_unsupported_reset ("NetBSD"); |
| 836 | do_reset (cmdtp, flag, argc, argv); |
| 837 | } |
| 838 | #endif |
| 839 | hdr = images->legacy_hdr_os; |
| 840 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 841 | /* |
| 842 | * Booting a (NetBSD) kernel image |
| 843 | * |
| 844 | * This process is pretty similar to a standalone application: |
| 845 | * The (first part of an multi-) image must be a stage-2 loader, |
| 846 | * which in turn is responsible for loading & invoking the actual |
| 847 | * kernel. The only differences are the parameters being passed: |
| 848 | * besides the board info strucure, the loader expects a command |
| 849 | * line, the name of the console device, and (optionally) the |
| 850 | * address of the original image header. |
| 851 | */ |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 852 | os_hdr = NULL; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 853 | if (image_check_type (hdr, IH_TYPE_MULTI)) { |
| 854 | image_multi_getimg (hdr, 1, &kernel_data, &kernel_len); |
| 855 | if (kernel_len) |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 856 | os_hdr = hdr; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 857 | } |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 858 | |
| 859 | consdev = ""; |
| 860 | #if defined (CONFIG_8xx_CONS_SMC1) |
| 861 | consdev = "smc1"; |
| 862 | #elif defined (CONFIG_8xx_CONS_SMC2) |
| 863 | consdev = "smc2"; |
| 864 | #elif defined (CONFIG_8xx_CONS_SCC2) |
| 865 | consdev = "scc2"; |
| 866 | #elif defined (CONFIG_8xx_CONS_SCC3) |
| 867 | consdev = "scc3"; |
| 868 | #endif |
| 869 | |
| 870 | if (argc > 2) { |
| 871 | ulong len; |
| 872 | int i; |
| 873 | |
| 874 | for (i = 2, len = 0; i < argc; i += 1) |
| 875 | len += strlen (argv[i]) + 1; |
| 876 | cmdline = malloc (len); |
| 877 | |
| 878 | for (i = 2, len = 0; i < argc; i += 1) { |
| 879 | if (i > 2) |
| 880 | cmdline[len++] = ' '; |
| 881 | strcpy (&cmdline[len], argv[i]); |
| 882 | len += strlen (argv[i]); |
| 883 | } |
| 884 | } else if ((cmdline = getenv ("bootargs")) == NULL) { |
| 885 | cmdline = ""; |
| 886 | } |
| 887 | |
| 888 | loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr); |
| 889 | |
| 890 | printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n", |
| 891 | (ulong)loader); |
| 892 | |
| 893 | show_boot_progress (15); |
| 894 | |
| 895 | /* |
| 896 | * NetBSD Stage-2 Loader Parameters: |
| 897 | * r3: ptr to board info data |
| 898 | * r4: image address |
| 899 | * r5: console device |
| 900 | * r6: boot args string |
| 901 | */ |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 902 | (*loader) (gd->bd, os_hdr, consdev, cmdline); |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | #ifdef CONFIG_LYNXKDI |
| 906 | static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag, |
| 907 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 908 | bootm_headers_t *images) |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 909 | { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 910 | image_header_t *hdr = images->legacy_hdr_os; |
| 911 | |
| 912 | #if defined(CONFIG_FIT) |
| 913 | if (!images->legacy_hdr_valid) { |
| 914 | fit_unsupported_reset ("Lynx"); |
| 915 | do_reset (cmdtp, flag, argc, argv); |
| 916 | } |
| 917 | #endif |
| 918 | |
| 919 | lynxkdi_boot ((image_header_t *)hdr); |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 920 | } |
| 921 | #endif /* CONFIG_LYNXKDI */ |
| 922 | |
| 923 | static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, |
| 924 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 925 | bootm_headers_t *images) |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 926 | { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 927 | image_header_t *hdr = images->legacy_hdr_os; |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 928 | void (*entry_point)(bd_t *); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 929 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 930 | #if defined(CONFIG_FIT) |
| 931 | if (!images->legacy_hdr_valid) { |
| 932 | fit_unsupported_reset ("RTEMS"); |
| 933 | do_reset (cmdtp, flag, argc, argv); |
| 934 | } |
| 935 | #endif |
| 936 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 937 | entry_point = (void (*)(bd_t *))image_get_ep (hdr); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 938 | |
| 939 | printf ("## Transferring control to RTEMS (at address %08lx) ...\n", |
| 940 | (ulong)entry_point); |
| 941 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 942 | show_boot_progress (15); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 943 | |
| 944 | /* |
| 945 | * RTEMS Parameters: |
| 946 | * r3: ptr to board info data |
| 947 | */ |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 948 | (*entry_point)(gd->bd); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 951 | #if defined(CONFIG_CMD_ELF) |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 952 | static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, |
| 953 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 954 | bootm_headers_t *images) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 955 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 956 | char str[80]; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 957 | image_header_t *hdr = images->legacy_hdr_os; |
| 958 | |
| 959 | #if defined(CONFIG_FIT) |
| 960 | if (hdr == NULL) { |
| 961 | fit_unsupported_reset ("VxWorks"); |
| 962 | do_reset (cmdtp, flag, argc, argv); |
| 963 | } |
| 964 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 965 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 966 | sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 967 | setenv("loadaddr", str); |
| 968 | do_bootvx(cmdtp, 0, 0, NULL); |
| 969 | } |
| 970 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 971 | static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag, |
| 972 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 973 | bootm_headers_t *images) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 974 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 975 | char *local_args[2]; |
| 976 | char str[16]; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 977 | image_header_t *hdr = images->legacy_hdr_os; |
| 978 | |
| 979 | #if defined(CONFIG_FIT) |
| 980 | if (!images->legacy_hdr_valid) { |
| 981 | fit_unsupported_reset ("QNX"); |
| 982 | do_reset (cmdtp, flag, argc, argv); |
| 983 | } |
| 984 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 985 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 986 | sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 987 | local_args[0] = argv[0]; |
| 988 | local_args[1] = str; /* and provide it via the arguments */ |
| 989 | do_bootelf(cmdtp, 0, 2, local_args); |
| 990 | } |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 991 | #endif |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 992 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 993 | #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) |
| 994 | static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag, |
| 995 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 996 | bootm_headers_t *images) |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 997 | { |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 998 | ulong top; |
| 999 | char *s, *cmdline; |
| 1000 | char **fwenv, **ss; |
| 1001 | int i, j, nxt, len, envno, envsz; |
| 1002 | bd_t *kbd; |
| 1003 | void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1004 | image_header_t *hdr = images->legacy_hdr_os; |
| 1005 | |
| 1006 | #if defined(CONFIG_FIT) |
| 1007 | if (!images->legacy_hdr_valid) { |
| 1008 | fit_unsupported_reset ("ARTOS"); |
| 1009 | do_reset (cmdtp, flag, argc, argv); |
| 1010 | } |
| 1011 | #endif |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 1012 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1013 | /* |
| 1014 | * Booting an ARTOS kernel image + application |
| 1015 | */ |
| 1016 | |
| 1017 | /* this used to be the top of memory, but was wrong... */ |
| 1018 | #ifdef CONFIG_PPC |
| 1019 | /* get stack pointer */ |
| 1020 | asm volatile ("mr %0,1" : "=r"(top) ); |
| 1021 | #endif |
| 1022 | debug ("## Current stack ends at 0x%08lX ", top); |
| 1023 | |
| 1024 | top -= 2048; /* just to be sure */ |
| 1025 | if (top > CFG_BOOTMAPSZ) |
| 1026 | top = CFG_BOOTMAPSZ; |
| 1027 | top &= ~0xF; |
| 1028 | |
| 1029 | debug ("=> set upper limit to 0x%08lX\n", top); |
| 1030 | |
| 1031 | /* first check the artos specific boot args, then the linux args*/ |
| 1032 | if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL) |
| 1033 | s = ""; |
| 1034 | |
| 1035 | /* get length of cmdline, and place it */ |
| 1036 | len = strlen (s); |
| 1037 | top = (top - (len + 1)) & ~0xF; |
| 1038 | cmdline = (char *)top; |
| 1039 | debug ("## cmdline at 0x%08lX ", top); |
| 1040 | strcpy (cmdline, s); |
| 1041 | |
| 1042 | /* copy bdinfo */ |
| 1043 | top = (top - sizeof (bd_t)) & ~0xF; |
| 1044 | debug ("## bd at 0x%08lX ", top); |
| 1045 | kbd = (bd_t *)top; |
| 1046 | memcpy (kbd, gd->bd, sizeof (bd_t)); |
| 1047 | |
| 1048 | /* first find number of env entries, and their size */ |
| 1049 | envno = 0; |
| 1050 | envsz = 0; |
| 1051 | for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) { |
| 1052 | for (nxt = i; env_get_char (nxt) != '\0'; ++nxt) |
| 1053 | ; |
| 1054 | envno++; |
| 1055 | envsz += (nxt - i) + 1; /* plus trailing zero */ |
| 1056 | } |
| 1057 | envno++; /* plus the terminating zero */ |
| 1058 | debug ("## %u envvars total size %u ", envno, envsz); |
| 1059 | |
| 1060 | top = (top - sizeof (char **) * envno) & ~0xF; |
| 1061 | fwenv = (char **)top; |
| 1062 | debug ("## fwenv at 0x%08lX ", top); |
| 1063 | |
| 1064 | top = (top - envsz) & ~0xF; |
| 1065 | s = (char *)top; |
| 1066 | ss = fwenv; |
| 1067 | |
| 1068 | /* now copy them */ |
| 1069 | for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) { |
| 1070 | for (nxt = i; env_get_char (nxt) != '\0'; ++nxt) |
| 1071 | ; |
| 1072 | *ss++ = s; |
| 1073 | for (j = i; j < nxt; ++j) |
| 1074 | *s++ = env_get_char (j); |
| 1075 | *s++ = '\0'; |
| 1076 | } |
| 1077 | *ss++ = NULL; /* terminate */ |
| 1078 | |
| 1079 | entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr); |
| 1080 | (*entry) (kbd, cmdline, fwenv, top); |
| 1081 | } |
| 1082 | #endif |