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