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