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 | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 69 | 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] | 70 | bootm_headers_t *images, ulong *os_data, ulong *os_len); |
Marian Balakowicz | 2df645e | 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 | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 81 | typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 82 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 83 | bootm_headers_t *images); /* pointers to os/initrd/fdt */ |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 84 | |
Marian Balakowicz | 2df645e | 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 | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 87 | #if defined(CONFIG_LYNXKDI) |
Marian Balakowicz | 2df645e | 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 | 808532a | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 90 | #endif |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 91 | static boot_os_fn do_bootm_rtems; |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 92 | #if defined(CONFIG_CMD_ELF) |
Marian Balakowicz | 2df645e | 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 | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 97 | #endif |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 98 | #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) |
Marian Balakowicz | 2df645e | 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 | 5d5ce29 | 2006-03-13 11:16:36 +0100 | [diff] [blame] | 101 | #endif |
| 102 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 103 | ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */ |
Marian Balakowicz | dbdd16a | 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 | b937bb7 | 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 | 2df645e | 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 | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 118 | ulong iflag; |
Marian Balakowicz | 05c1d3f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 119 | const char *type_name; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 120 | uint unc_len = CFG_BOOTM_LEN; |
Marian Balakowicz | dbdd16a | 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 | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 123 | void *os_hdr; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 124 | ulong os_data, os_len; |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 125 | ulong image_start, image_end; |
| 126 | ulong load_start, load_end; |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 127 | ulong mem_start, mem_size; |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 128 | |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 129 | struct lmb lmb; |
| 130 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 131 | memset ((void *)&images, 0, sizeof (images)); |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 132 | images.verify = getenv_verify(); |
Kumar Gala | fb71ccf | 2008-02-27 21:51:48 -0600 | [diff] [blame] | 133 | images.autostart = getenv_autostart(); |
Kumar Gala | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 134 | images.lmb = &lmb; |
| 135 | |
| 136 | lmb_init(&lmb); |
| 137 | |
Kumar Gala | c5bacfd | 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 | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 142 | |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 143 | board_lmb_reserve(&lmb); |
| 144 | |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 145 | /* get kernel image header, start address and length */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 146 | os_hdr = boot_get_kernel (cmdtp, flag, argc, argv, |
Marian Balakowicz | dbdd16a | 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 | 8a8ec53 | 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 | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 153 | /* get image parameters */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 154 | switch (genimg_get_format (os_hdr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 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; |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 175 | type_name = genimg_get_type_name (type); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 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 | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 184 | #ifdef CONFIG_AMIGAONEG3SE |
| 185 | /* |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 186 | * We've possible left the caches enabled during |
wdenk | 452cfd6 | 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 | dbdd16a | 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 | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 197 | if (load_start == (ulong)os_hdr) { |
Marian Balakowicz | 05c1d3f | 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 | 05c1d3f | 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 | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 202 | memmove_wd ((void *)load_start, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 203 | (void *)os_data, os_len, CHUNKSZ); |
Marian Balakowicz | f9a67bd | 2008-01-08 18:11:45 +0100 | [diff] [blame] | 204 | |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 205 | load_end = load_start + os_len; |
Marian Balakowicz | f9a67bd | 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 | 05c1d3f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 210 | printf (" Uncompressing %s ... ", type_name); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 211 | if (gunzip ((void *)load_start, unc_len, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 212 | (uchar *)os_data, &os_len) != 0) { |
wdenk | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 213 | puts ("GUNZIP ERROR - must RESET board to recover\n"); |
Heiko Schocher | 8a8ec53 | 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 | f92332b | 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 | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 220 | #ifdef CONFIG_BZIP2 |
| 221 | case IH_COMP_BZIP2: |
Marian Balakowicz | 05c1d3f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 222 | printf (" Uncompressing %s ... ", type_name); |
wdenk | 2cefd15 | 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 | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 228 | int i = BZ2_bzBuffToBuffDecompress ((char*)load_start, |
Marian Balakowicz | b4a12a9 | 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 | 710e350 | 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 | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 233 | show_boot_progress (-6); |
wdenk | 710e350 | 2003-08-29 20:57:53 +0000 | [diff] [blame] | 234 | do_reset (cmdtp, flag, argc, argv); |
| 235 | } |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 236 | |
| 237 | load_end = load_start + unc_len; |
wdenk | 710e350 | 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 | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 243 | printf ("Unimplemented compression type %d\n", comp); |
Heiko Schocher | 8a8ec53 | 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 | 42c0547 | 2004-03-23 22:14:11 +0000 | [diff] [blame] | 247 | puts ("OK\n"); |
Marian Balakowicz | c40032c | 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 | 8a8ec53 | 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 | f92332b | 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 | 8a8ec53 | 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 | 6d7bfa8 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 261 | lmb_reserve(&lmb, load_start, (load_end - load_start)); |
| 262 | |
Marian Balakowicz | dbdd16a | 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 | 808532a | 2003-10-10 10:05:42 +0000 | [diff] [blame] | 266 | #ifdef CONFIG_SILENT_CONSOLE |
| 267 | fixup_silent_linux(); |
| 268 | #endif |
Marian Balakowicz | 61fde55 | 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 | 2df645e | 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 | 61fde55 | 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 | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 275 | |
| 276 | #ifdef CONFIG_LYNXKDI |
| 277 | case IH_OS_LYNXOS: |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 278 | do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images); |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 279 | break; |
| 280 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 281 | |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 282 | case IH_OS_RTEMS: |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 283 | do_bootm_rtems (cmdtp, flag, argc, argv, &images); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 284 | break; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 285 | |
Jon Loeliger | 54324d0 | 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 | 61fde55 | 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 | b4a12a9 | 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 | 61fde55 | 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 | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 294 | #endif |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 295 | |
wdenk | 0893c47 | 2003-05-20 14:25:27 +0000 | [diff] [blame] | 296 | #ifdef CONFIG_ARTOS |
| 297 | case IH_OS_ARTOS: |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 298 | do_bootm_artos (cmdtp, flag, argc, argv, &images); |
wdenk | 0893c47 | 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 | 8a8ec53 | 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 | 42c0547 | 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 | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 311 | /** |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 312 | * image_get_kernel - verify legacy format kernel image |
| 313 | * @img_addr: in RAM address of the legacy format image to be verified |
| 314 | * @verify: data CRC verification flag |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 315 | * |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 316 | * image_get_kernel() verifies legacy image integrity and returns pointer to |
| 317 | * legacy image header if image verification was completed successfully. |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 318 | * |
| 319 | * returns: |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 320 | * pointer to a legacy image header if valid image was found |
| 321 | * otherwise return NULL |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 322 | */ |
Marian Balakowicz | 59504f6 | 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 | /** |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 363 | * boot_get_kernel - find kernel image |
Marian Balakowicz | 59504f6 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 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 | * |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 367 | * boot_get_kernel() tries to find a kernel image, verifies its integrity |
Marian Balakowicz | 59504f6 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 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 | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 374 | 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] | 375 | bootm_headers_t *images, ulong *os_data, ulong *os_len) |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 376 | { |
| 377 | image_header_t *hdr; |
| 378 | ulong img_addr; |
Marian Balakowicz | dbdd16a | 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 | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 384 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 385 | /* find out kernel image address */ |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 386 | if (argc < 2) { |
| 387 | img_addr = load_addr; |
Marian Balakowicz | dbdd16a | 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 | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 400 | } else { |
| 401 | img_addr = simple_strtoul(argv[1], NULL, 16); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 402 | debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | show_boot_progress (1); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 406 | printf ("## Booting kernel image at %08lx ...\n", img_addr); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 407 | |
Marian Balakowicz | c536d6f | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 408 | /* copy from dataflash if needed */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 409 | img_addr = genimg_get_image (img_addr); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 410 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 411 | /* check image type, for FIT images get FIT kernel node */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 412 | switch (genimg_get_format ((void *)img_addr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 413 | case IMAGE_FORMAT_LEGACY: |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 414 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 415 | debug ("* kernel: legacy format image\n"); |
Marian Balakowicz | 59504f6 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 416 | hdr = image_get_kernel (img_addr, images->verify); |
| 417 | if (!hdr) |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 418 | return NULL; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 419 | show_boot_progress (5); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 420 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 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; |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 436 | |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 437 | break; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 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"); |
| 443 | return NULL; |
| 444 | #endif |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 445 | default: |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 446 | printf ("Wrong Image Format for %s command\n", cmdtp->name); |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 447 | return NULL; |
| 448 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 449 | |
Marian Balakowicz | c40032c | 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 | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 453 | return (void *)img_addr; |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 454 | } |
| 455 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 456 | U_BOOT_CMD( |
Marian Balakowicz | 2df645e | 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 | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 462 | #if defined(CONFIG_OF_LIBFDT) |
Matthew McClintock | 6fb7c81 | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 463 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
Detlev Zundel | e609916 | 2007-10-19 16:47:26 +0200 | [diff] [blame] | 464 | "\ta third argument is required which is the address of the\n" |
Matthew McClintock | 6fb7c81 | 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 | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 469 | ); |
| 470 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 471 | /*******************************************************************/ |
| 472 | /* bootd - boot default image */ |
| 473 | /*******************************************************************/ |
Jon Loeliger | 54324d0 | 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 | 2df645e | 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 | 2df645e | 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 | 2df645e | 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 | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 489 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 490 | U_BOOT_CMD( |
Marian Balakowicz | 2df645e | 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 | 3086a97 | 2003-06-28 23:11:04 +0000 | [diff] [blame] | 493 | NULL |
| 494 | ); |
| 495 | |
| 496 | /* keep old command name "bootd" for backward compatibility */ |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 497 | U_BOOT_CMD( |
Marian Balakowicz | 2df645e | 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 | 57b2d80 | 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 | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 505 | |
| 506 | /*******************************************************************/ |
| 507 | /* iminfo - print header info for a requested image */ |
| 508 | /*******************************************************************/ |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 509 | #if defined(CONFIG_CMD_IMI) |
Marian Balakowicz | 2df645e | 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 | 2df645e | 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 | 2df645e | 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 | dbdd16a | 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 | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 534 | switch (genimg_get_format (hdr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 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 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 541 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 542 | if (!image_check_hcrc (hdr)) { |
| 543 | puts (" Bad Header Checksum\n"); |
| 544 | return 1; |
| 545 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 546 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 547 | image_print_contents (hdr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 548 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 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"); |
Marian Balakowicz | cc1fd91 | 2008-03-11 12:35:20 +0100 | [diff] [blame^] | 559 | |
| 560 | if (!fit_check_format (hdr)) { |
| 561 | puts ("Bad FIT image format!\n"); |
| 562 | return 1; |
| 563 | } |
| 564 | |
| 565 | fit_print_contents (hdr); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 566 | return 0; |
| 567 | #endif |
| 568 | default: |
| 569 | puts ("Unknown image format!\n"); |
| 570 | break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 571 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 572 | |
| 573 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 574 | } |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 575 | |
| 576 | U_BOOT_CMD( |
| 577 | iminfo, CFG_MAXARGS, 1, do_iminfo, |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 578 | "iminfo - print header information for application image\n", |
| 579 | "addr [addr ...]\n" |
| 580 | " - print header information for application image starting at\n" |
| 581 | " address 'addr' in memory; this includes verification of the\n" |
| 582 | " image contents (magic number, header and payload checksums)\n" |
| 583 | ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 584 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 585 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 586 | |
| 587 | /*******************************************************************/ |
| 588 | /* imls - list all images found in flash */ |
| 589 | /*******************************************************************/ |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 590 | #if defined(CONFIG_CMD_IMLS) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 591 | int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 592 | { |
| 593 | flash_info_t *info; |
| 594 | int i, j; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 595 | void *hdr; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 596 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 597 | for (i = 0, info = &flash_info[0]; |
| 598 | i < CFG_MAX_FLASH_BANKS; ++i, ++info) { |
| 599 | |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 600 | if (info->flash_id == FLASH_UNKNOWN) |
| 601 | goto next_bank; |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 602 | for (j = 0; j < info->sector_count; ++j) { |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 603 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 604 | hdr = (void *)info->start[j]; |
| 605 | if (!hdr) |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 606 | goto next_sector; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 607 | |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 608 | switch (genimg_get_format (hdr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 609 | case IMAGE_FORMAT_LEGACY: |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 610 | if (!image_check_hcrc (hdr)) |
| 611 | goto next_sector; |
wdenk | c6abb7e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 612 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 613 | printf ("Legacy Image at %08lX:\n", (ulong)hdr); |
| 614 | image_print_contents (hdr); |
| 615 | |
| 616 | puts (" Verifying Checksum ... "); |
| 617 | if (!image_check_dcrc (hdr)) { |
| 618 | puts ("Bad Data CRC\n"); |
| 619 | } else { |
| 620 | puts ("OK\n"); |
| 621 | } |
| 622 | break; |
| 623 | #if defined(CONFIG_FIT) |
| 624 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | cc1fd91 | 2008-03-11 12:35:20 +0100 | [diff] [blame^] | 625 | if (!fit_check_format (hdr)) |
| 626 | goto next_sector; |
| 627 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 628 | printf ("FIT Image at %08lX:\n", (ulong)hdr); |
Marian Balakowicz | cc1fd91 | 2008-03-11 12:35:20 +0100 | [diff] [blame^] | 629 | fit_print_contents (hdr); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 630 | break; |
| 631 | #endif |
| 632 | default: |
| 633 | goto next_sector; |
wdenk | c6abb7e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 634 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 635 | |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 636 | next_sector: ; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 637 | } |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 638 | next_bank: ; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | return (0); |
| 642 | } |
| 643 | |
| 644 | U_BOOT_CMD( |
| 645 | imls, 1, 1, do_imls, |
| 646 | "imls - list all images found in flash\n", |
| 647 | "\n" |
| 648 | " - Prints information about all images found at sector\n" |
| 649 | " boundaries in flash.\n" |
| 650 | ); |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 651 | #endif |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 652 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 653 | /*******************************************************************/ |
Marian Balakowicz | c40032c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 654 | /* helper routines */ |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 655 | /*******************************************************************/ |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 656 | #ifdef CONFIG_SILENT_CONSOLE |
| 657 | static void fixup_silent_linux () |
| 658 | { |
| 659 | char buf[256], *start, *end; |
| 660 | char *cmdline = getenv ("bootargs"); |
| 661 | |
| 662 | /* Only fix cmdline when requested */ |
| 663 | if (!(gd->flags & GD_FLG_SILENT)) |
| 664 | return; |
| 665 | |
| 666 | debug ("before silent fix-up: %s\n", cmdline); |
| 667 | if (cmdline) { |
| 668 | if ((start = strstr (cmdline, "console=")) != NULL) { |
| 669 | end = strchr (start, ' '); |
| 670 | strncpy (buf, cmdline, (start - cmdline + 8)); |
| 671 | if (end) |
| 672 | strcpy (buf + (start - cmdline + 8), end); |
| 673 | else |
| 674 | buf[start - cmdline + 8] = '\0'; |
| 675 | } else { |
| 676 | strcpy (buf, cmdline); |
| 677 | strcat (buf, " console="); |
| 678 | } |
| 679 | } else { |
| 680 | strcpy (buf, "console="); |
| 681 | } |
| 682 | |
| 683 | setenv ("bootargs", buf); |
| 684 | debug ("after silent fix-up: %s\n", buf); |
| 685 | } |
| 686 | #endif /* CONFIG_SILENT_CONSOLE */ |
| 687 | |
| 688 | |
| 689 | /*******************************************************************/ |
| 690 | /* OS booting routines */ |
| 691 | /*******************************************************************/ |
| 692 | |
| 693 | static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 694 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 695 | bootm_headers_t *images) |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 696 | { |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 697 | void (*loader)(bd_t *, image_header_t *, char *, char *); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 698 | image_header_t *os_hdr, *hdr; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 699 | ulong kernel_data, kernel_len; |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 700 | char *consdev; |
| 701 | char *cmdline; |
| 702 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 703 | #if defined(CONFIG_FIT) |
| 704 | if (!images->legacy_hdr_valid) { |
| 705 | fit_unsupported_reset ("NetBSD"); |
| 706 | do_reset (cmdtp, flag, argc, argv); |
| 707 | } |
| 708 | #endif |
| 709 | hdr = images->legacy_hdr_os; |
| 710 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 711 | /* |
| 712 | * Booting a (NetBSD) kernel image |
| 713 | * |
| 714 | * This process is pretty similar to a standalone application: |
| 715 | * The (first part of an multi-) image must be a stage-2 loader, |
| 716 | * which in turn is responsible for loading & invoking the actual |
| 717 | * kernel. The only differences are the parameters being passed: |
| 718 | * besides the board info strucure, the loader expects a command |
| 719 | * line, the name of the console device, and (optionally) the |
| 720 | * address of the original image header. |
| 721 | */ |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 722 | os_hdr = NULL; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 723 | if (image_check_type (hdr, IH_TYPE_MULTI)) { |
| 724 | image_multi_getimg (hdr, 1, &kernel_data, &kernel_len); |
| 725 | if (kernel_len) |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 726 | os_hdr = hdr; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 727 | } |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 728 | |
| 729 | consdev = ""; |
| 730 | #if defined (CONFIG_8xx_CONS_SMC1) |
| 731 | consdev = "smc1"; |
| 732 | #elif defined (CONFIG_8xx_CONS_SMC2) |
| 733 | consdev = "smc2"; |
| 734 | #elif defined (CONFIG_8xx_CONS_SCC2) |
| 735 | consdev = "scc2"; |
| 736 | #elif defined (CONFIG_8xx_CONS_SCC3) |
| 737 | consdev = "scc3"; |
| 738 | #endif |
| 739 | |
| 740 | if (argc > 2) { |
| 741 | ulong len; |
| 742 | int i; |
| 743 | |
| 744 | for (i = 2, len = 0; i < argc; i += 1) |
| 745 | len += strlen (argv[i]) + 1; |
| 746 | cmdline = malloc (len); |
| 747 | |
| 748 | for (i = 2, len = 0; i < argc; i += 1) { |
| 749 | if (i > 2) |
| 750 | cmdline[len++] = ' '; |
| 751 | strcpy (&cmdline[len], argv[i]); |
| 752 | len += strlen (argv[i]); |
| 753 | } |
| 754 | } else if ((cmdline = getenv ("bootargs")) == NULL) { |
| 755 | cmdline = ""; |
| 756 | } |
| 757 | |
| 758 | loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr); |
| 759 | |
| 760 | printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n", |
| 761 | (ulong)loader); |
| 762 | |
| 763 | show_boot_progress (15); |
| 764 | |
| 765 | /* |
| 766 | * NetBSD Stage-2 Loader Parameters: |
| 767 | * r3: ptr to board info data |
| 768 | * r4: image address |
| 769 | * r5: console device |
| 770 | * r6: boot args string |
| 771 | */ |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 772 | (*loader) (gd->bd, os_hdr, consdev, cmdline); |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | #ifdef CONFIG_LYNXKDI |
| 776 | static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag, |
| 777 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 778 | bootm_headers_t *images) |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 779 | { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 780 | image_header_t *hdr = images->legacy_hdr_os; |
| 781 | |
| 782 | #if defined(CONFIG_FIT) |
| 783 | if (!images->legacy_hdr_valid) { |
| 784 | fit_unsupported_reset ("Lynx"); |
| 785 | do_reset (cmdtp, flag, argc, argv); |
| 786 | } |
| 787 | #endif |
| 788 | |
| 789 | lynxkdi_boot ((image_header_t *)hdr); |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 790 | } |
| 791 | #endif /* CONFIG_LYNXKDI */ |
| 792 | |
| 793 | static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, |
| 794 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 795 | bootm_headers_t *images) |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 796 | { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 797 | image_header_t *hdr = images->legacy_hdr_os; |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 798 | void (*entry_point)(bd_t *); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 799 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 800 | #if defined(CONFIG_FIT) |
| 801 | if (!images->legacy_hdr_valid) { |
| 802 | fit_unsupported_reset ("RTEMS"); |
| 803 | do_reset (cmdtp, flag, argc, argv); |
| 804 | } |
| 805 | #endif |
| 806 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 807 | entry_point = (void (*)(bd_t *))image_get_ep (hdr); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 808 | |
| 809 | printf ("## Transferring control to RTEMS (at address %08lx) ...\n", |
| 810 | (ulong)entry_point); |
| 811 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 812 | show_boot_progress (15); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 813 | |
| 814 | /* |
| 815 | * RTEMS Parameters: |
| 816 | * r3: ptr to board info data |
| 817 | */ |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 818 | (*entry_point)(gd->bd); |
wdenk | 92bbe3f | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Jon Loeliger | 54324d0 | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 821 | #if defined(CONFIG_CMD_ELF) |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 822 | static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, |
| 823 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 824 | bootm_headers_t *images) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 825 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 826 | char str[80]; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 827 | image_header_t *hdr = images->legacy_hdr_os; |
| 828 | |
| 829 | #if defined(CONFIG_FIT) |
| 830 | if (hdr == NULL) { |
| 831 | fit_unsupported_reset ("VxWorks"); |
| 832 | do_reset (cmdtp, flag, argc, argv); |
| 833 | } |
| 834 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 835 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 836 | sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 837 | setenv("loadaddr", str); |
| 838 | do_bootvx(cmdtp, 0, 0, NULL); |
| 839 | } |
| 840 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 841 | static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag, |
| 842 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 843 | bootm_headers_t *images) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 844 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 845 | char *local_args[2]; |
| 846 | char str[16]; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 847 | image_header_t *hdr = images->legacy_hdr_os; |
| 848 | |
| 849 | #if defined(CONFIG_FIT) |
| 850 | if (!images->legacy_hdr_valid) { |
| 851 | fit_unsupported_reset ("QNX"); |
| 852 | do_reset (cmdtp, flag, argc, argv); |
| 853 | } |
| 854 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 855 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 856 | sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 857 | local_args[0] = argv[0]; |
| 858 | local_args[1] = str; /* and provide it via the arguments */ |
| 859 | do_bootelf(cmdtp, 0, 2, local_args); |
| 860 | } |
Jon Loeliger | d704d91 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 861 | #endif |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 862 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 863 | #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC) |
| 864 | static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag, |
| 865 | int argc, char *argv[], |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 866 | bootm_headers_t *images) |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 867 | { |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 868 | ulong top; |
| 869 | char *s, *cmdline; |
| 870 | char **fwenv, **ss; |
| 871 | int i, j, nxt, len, envno, envsz; |
| 872 | bd_t *kbd; |
| 873 | void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 874 | image_header_t *hdr = images->legacy_hdr_os; |
| 875 | |
| 876 | #if defined(CONFIG_FIT) |
| 877 | if (!images->legacy_hdr_valid) { |
| 878 | fit_unsupported_reset ("ARTOS"); |
| 879 | do_reset (cmdtp, flag, argc, argv); |
| 880 | } |
| 881 | #endif |
wdenk | e58b0dc | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 882 | |
Marian Balakowicz | 2df645e | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 883 | /* |
| 884 | * Booting an ARTOS kernel image + application |
| 885 | */ |
| 886 | |
| 887 | /* this used to be the top of memory, but was wrong... */ |
| 888 | #ifdef CONFIG_PPC |
| 889 | /* get stack pointer */ |
| 890 | asm volatile ("mr %0,1" : "=r"(top) ); |
| 891 | #endif |
| 892 | debug ("## Current stack ends at 0x%08lX ", top); |
| 893 | |
| 894 | top -= 2048; /* just to be sure */ |
| 895 | if (top > CFG_BOOTMAPSZ) |
| 896 | top = CFG_BOOTMAPSZ; |
| 897 | top &= ~0xF; |
| 898 | |
| 899 | debug ("=> set upper limit to 0x%08lX\n", top); |
| 900 | |
| 901 | /* first check the artos specific boot args, then the linux args*/ |
| 902 | if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL) |
| 903 | s = ""; |
| 904 | |
| 905 | /* get length of cmdline, and place it */ |
| 906 | len = strlen (s); |
| 907 | top = (top - (len + 1)) & ~0xF; |
| 908 | cmdline = (char *)top; |
| 909 | debug ("## cmdline at 0x%08lX ", top); |
| 910 | strcpy (cmdline, s); |
| 911 | |
| 912 | /* copy bdinfo */ |
| 913 | top = (top - sizeof (bd_t)) & ~0xF; |
| 914 | debug ("## bd at 0x%08lX ", top); |
| 915 | kbd = (bd_t *)top; |
| 916 | memcpy (kbd, gd->bd, sizeof (bd_t)); |
| 917 | |
| 918 | /* first find number of env entries, and their size */ |
| 919 | envno = 0; |
| 920 | envsz = 0; |
| 921 | for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) { |
| 922 | for (nxt = i; env_get_char (nxt) != '\0'; ++nxt) |
| 923 | ; |
| 924 | envno++; |
| 925 | envsz += (nxt - i) + 1; /* plus trailing zero */ |
| 926 | } |
| 927 | envno++; /* plus the terminating zero */ |
| 928 | debug ("## %u envvars total size %u ", envno, envsz); |
| 929 | |
| 930 | top = (top - sizeof (char **) * envno) & ~0xF; |
| 931 | fwenv = (char **)top; |
| 932 | debug ("## fwenv at 0x%08lX ", top); |
| 933 | |
| 934 | top = (top - envsz) & ~0xF; |
| 935 | s = (char *)top; |
| 936 | ss = fwenv; |
| 937 | |
| 938 | /* now copy them */ |
| 939 | for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) { |
| 940 | for (nxt = i; env_get_char (nxt) != '\0'; ++nxt) |
| 941 | ; |
| 942 | *ss++ = s; |
| 943 | for (j = i; j < nxt; ++j) |
| 944 | *s++ = env_get_char (j); |
| 945 | *s++ = '\0'; |
| 946 | } |
| 947 | *ss++ = NULL; /* terminate */ |
| 948 | |
| 949 | entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr); |
| 950 | (*entry) (kbd, cmdline, fwenv, top); |
| 951 | } |
| 952 | #endif |