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