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