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