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