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