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