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