wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1 | /* |
Detlev Zundel | ca95c9d | 2009-07-13 16:01:18 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2009 |
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> |
Jean-Christophe PLAGNIOL-VILLARD | a31e091 | 2009-04-04 12:49:11 +0200 | [diff] [blame] | 33 | #include <u-boot/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> |
Simon Glass | 35e7b0f | 2013-05-07 06:12:03 +0000 | [diff] [blame] | 39 | #include <asm/io.h> |
Anatolij Gustschin | 5bf2766 | 2011-11-19 13:12:18 +0000 | [diff] [blame] | 40 | #include <linux/compiler.h> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 41 | |
Stefan Roese | ebb86c4 | 2008-07-30 09:59:51 +0200 | [diff] [blame] | 42 | #if defined(CONFIG_CMD_USB) |
Markus Klotzbücher | 3d71c81 | 2008-07-10 14:47:09 +0200 | [diff] [blame] | 43 | #include <usb.h> |
| 44 | #endif |
| 45 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 46 | #ifdef CONFIG_SYS_HUSH_PARSER |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 47 | #include <hush.h> |
| 48 | #endif |
| 49 | |
Kumar Gala | 54f9c86 | 2008-08-15 08:24:39 -0500 | [diff] [blame] | 50 | #if defined(CONFIG_OF_LIBFDT) |
Kumar Gala | 54f9c86 | 2008-08-15 08:24:39 -0500 | [diff] [blame] | 51 | #include <libfdt.h> |
| 52 | #include <fdt_support.h> |
| 53 | #endif |
| 54 | |
Luigi 'Comio' Mantellini | fc9c172 | 2008-09-08 02:46:13 +0200 | [diff] [blame] | 55 | #ifdef CONFIG_LZMA |
Luigi 'Comio' Mantellini | fc9c172 | 2008-09-08 02:46:13 +0200 | [diff] [blame] | 56 | #include <lzma/LzmaTypes.h> |
Luigi 'Comio' Mantellini | caf72ff | 2009-07-21 10:45:49 +0200 | [diff] [blame] | 57 | #include <lzma/LzmaDec.h> |
Luigi 'Comio' Mantellini | fc9c172 | 2008-09-08 02:46:13 +0200 | [diff] [blame] | 58 | #include <lzma/LzmaTools.h> |
| 59 | #endif /* CONFIG_LZMA */ |
| 60 | |
Peter Korsgaard | 20dde48 | 2009-11-19 11:37:51 +0100 | [diff] [blame] | 61 | #ifdef CONFIG_LZO |
| 62 | #include <linux/lzo.h> |
| 63 | #endif /* CONFIG_LZO */ |
| 64 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 65 | DECLARE_GLOBAL_DATA_PTR; |
| 66 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 67 | #ifndef CONFIG_SYS_BOOTM_LEN |
| 68 | #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 69 | #endif |
| 70 | |
Marian Balakowicz | 321359f | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 71 | #ifdef CONFIG_BZIP2 |
| 72 | extern void bz_internal_error(int); |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 73 | #endif |
| 74 | |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 75 | #if defined(CONFIG_CMD_IMI) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 76 | static int image_info(unsigned long addr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 77 | #endif |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 78 | |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 79 | #if defined(CONFIG_CMD_IMLS) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 80 | #include <flash.h> |
Stefan Roese | ca5def3 | 2010-08-31 10:00:10 +0200 | [diff] [blame] | 81 | #include <mtd/cfi_flash.h> |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 82 | extern flash_info_t flash_info[]; /* info for FLASH chips */ |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 83 | #endif |
| 84 | |
| 85 | #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 86 | static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 87 | #endif |
| 88 | |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 89 | #include <linux/err.h> |
| 90 | #include <nand.h> |
| 91 | |
Joe Hershberger | be2e5a0 | 2013-02-27 10:20:59 +0000 | [diff] [blame] | 92 | #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 93 | static void fixup_silent_linux(void); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 94 | #endif |
| 95 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 96 | static image_header_t *image_get_kernel(ulong img_addr, int verify); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 97 | #if defined(CONFIG_FIT) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 98 | static int fit_check_kernel(const void *fit, int os_noffset, int verify); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 99 | #endif |
| 100 | |
Simon Glass | 35e7b0f | 2013-05-07 06:12:03 +0000 | [diff] [blame] | 101 | static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 102 | char * const argv[], bootm_headers_t *images, |
| 103 | ulong *os_data, ulong *os_len); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 104 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 105 | /* |
| 106 | * Continue booting an OS image; caller already has: |
| 107 | * - copied image header to global variable `header' |
| 108 | * - checked header magic number, checksums (both header & image), |
| 109 | * - verified image architecture (PPC) and type (KERNEL or MULTI), |
| 110 | * - loaded (first part of) image to header load address, |
| 111 | * - disabled interrupts. |
| 112 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 113 | typedef int boot_os_fn(int flag, int argc, char * const argv[], |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 114 | bootm_headers_t *images); /* pointers to os/initrd/fdt */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 115 | |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 116 | #ifdef CONFIG_BOOTM_LINUX |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 117 | extern boot_os_fn do_bootm_linux; |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 118 | #endif |
| 119 | #ifdef CONFIG_BOOTM_NETBSD |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 120 | static boot_os_fn do_bootm_netbsd; |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 121 | #endif |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 122 | #if defined(CONFIG_LYNXKDI) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 123 | static boot_os_fn do_bootm_lynxkdi; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 124 | extern void lynxkdi_boot(image_header_t *); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 125 | #endif |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 126 | #ifdef CONFIG_BOOTM_RTEMS |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 127 | static boot_os_fn do_bootm_rtems; |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 128 | #endif |
Torkel Lundgren | 3df6195 | 2010-09-28 11:05:36 +0200 | [diff] [blame] | 129 | #if defined(CONFIG_BOOTM_OSE) |
| 130 | static boot_os_fn do_bootm_ose; |
| 131 | #endif |
Steven Stallion | 04d4140 | 2013-03-20 06:31:35 +0000 | [diff] [blame] | 132 | #if defined(CONFIG_BOOTM_PLAN9) |
| 133 | static boot_os_fn do_bootm_plan9; |
| 134 | #endif |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 135 | #if defined(CONFIG_CMD_ELF) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 136 | static boot_os_fn do_bootm_vxworks; |
| 137 | static boot_os_fn do_bootm_qnxelf; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 138 | int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 139 | int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 140 | #endif |
Peter Tyser | f5ed9e3 | 2008-09-08 14:56:49 -0500 | [diff] [blame] | 141 | #if defined(CONFIG_INTEGRITY) |
| 142 | static boot_os_fn do_bootm_integrity; |
| 143 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 144 | |
Mike Frysinger | 0008555 | 2009-11-03 11:36:26 -0500 | [diff] [blame] | 145 | static boot_os_fn *boot_os[] = { |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 146 | #ifdef CONFIG_BOOTM_LINUX |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 147 | [IH_OS_LINUX] = do_bootm_linux, |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 148 | #endif |
| 149 | #ifdef CONFIG_BOOTM_NETBSD |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 150 | [IH_OS_NETBSD] = do_bootm_netbsd, |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 151 | #endif |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 152 | #ifdef CONFIG_LYNXKDI |
| 153 | [IH_OS_LYNXOS] = do_bootm_lynxkdi, |
| 154 | #endif |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 155 | #ifdef CONFIG_BOOTM_RTEMS |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 156 | [IH_OS_RTEMS] = do_bootm_rtems, |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 157 | #endif |
Torkel Lundgren | 3df6195 | 2010-09-28 11:05:36 +0200 | [diff] [blame] | 158 | #if defined(CONFIG_BOOTM_OSE) |
| 159 | [IH_OS_OSE] = do_bootm_ose, |
| 160 | #endif |
Steven Stallion | 04d4140 | 2013-03-20 06:31:35 +0000 | [diff] [blame] | 161 | #if defined(CONFIG_BOOTM_PLAN9) |
| 162 | [IH_OS_PLAN9] = do_bootm_plan9, |
| 163 | #endif |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 164 | #if defined(CONFIG_CMD_ELF) |
| 165 | [IH_OS_VXWORKS] = do_bootm_vxworks, |
| 166 | [IH_OS_QNX] = do_bootm_qnxelf, |
| 167 | #endif |
| 168 | #ifdef CONFIG_INTEGRITY |
| 169 | [IH_OS_INTEGRITY] = do_bootm_integrity, |
| 170 | #endif |
| 171 | }; |
| 172 | |
Simon Schwarz | dee1776 | 2011-09-02 00:50:31 +0000 | [diff] [blame] | 173 | bootm_headers_t images; /* pointers to os/initrd/fdt images */ |
Stefan Roese | 15940c9 | 2006-03-13 11:16:36 +0100 | [diff] [blame] | 174 | |
Kumar Gala | 3dfad40 | 2009-08-27 08:23:55 -0500 | [diff] [blame] | 175 | /* Allow for arch specific config before we boot */ |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 176 | static void __arch_preboot_os(void) |
Kumar Gala | 3dfad40 | 2009-08-27 08:23:55 -0500 | [diff] [blame] | 177 | { |
| 178 | /* please define platform specific arch_preboot_os() */ |
| 179 | } |
| 180 | void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os"))); |
| 181 | |
Mike Frysinger | 476af29 | 2011-10-03 14:50:33 +0000 | [diff] [blame] | 182 | #define IH_INITRD_ARCH IH_ARCH_DEFAULT |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 183 | |
Mike Frysinger | a16028d | 2009-11-03 11:35:59 -0500 | [diff] [blame] | 184 | #ifdef CONFIG_LMB |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 185 | static void boot_start_lmb(bootm_headers_t *images) |
| 186 | { |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 187 | ulong mem_start; |
| 188 | phys_size_t mem_size; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 189 | |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 190 | lmb_init(&images->lmb); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 191 | |
Kumar Gala | d3f2fa0 | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 192 | mem_start = getenv_bootm_low(); |
| 193 | mem_size = getenv_bootm_size(); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 194 | |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 195 | lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 196 | |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 197 | arch_lmb_reserve(&images->lmb); |
| 198 | board_lmb_reserve(&images->lmb); |
Mike Frysinger | a16028d | 2009-11-03 11:35:59 -0500 | [diff] [blame] | 199 | } |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 200 | #else |
Marek Vasut | 35cf5fe | 2012-04-01 03:59:46 +0000 | [diff] [blame] | 201 | #define lmb_reserve(lmb, base, size) |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 202 | static inline void boot_start_lmb(bootm_headers_t *images) { } |
| 203 | #endif |
Mike Frysinger | a16028d | 2009-11-03 11:35:59 -0500 | [diff] [blame] | 204 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 205 | static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Mike Frysinger | a16028d | 2009-11-03 11:35:59 -0500 | [diff] [blame] | 206 | { |
Simon Glass | 35e7b0f | 2013-05-07 06:12:03 +0000 | [diff] [blame] | 207 | const void *os_hdr; |
| 208 | int ret; |
Mike Frysinger | a16028d | 2009-11-03 11:35:59 -0500 | [diff] [blame] | 209 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 210 | memset((void *)&images, 0, sizeof(images)); |
| 211 | images.verify = getenv_yesno("verify"); |
Mike Frysinger | a16028d | 2009-11-03 11:35:59 -0500 | [diff] [blame] | 212 | |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 213 | boot_start_lmb(&images); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 214 | |
Simon Glass | 573f14f | 2011-12-10 11:08:06 +0000 | [diff] [blame] | 215 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start"); |
| 216 | |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 217 | /* get kernel image header, start address and length */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 218 | os_hdr = boot_get_kernel(cmdtp, flag, argc, argv, |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 219 | &images, &images.os.image_start, &images.os.image_len); |
| 220 | if (images.os.image_len == 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 221 | puts("ERROR: can't get kernel image!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 222 | return 1; |
| 223 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 224 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 225 | /* get image parameters */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 226 | switch (genimg_get_format(os_hdr)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 227 | case IMAGE_FORMAT_LEGACY: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 228 | images.os.type = image_get_type(os_hdr); |
| 229 | images.os.comp = image_get_comp(os_hdr); |
| 230 | images.os.os = image_get_os(os_hdr); |
Wolfgang Denk | bccae90 | 2005-10-06 01:50:50 +0200 | [diff] [blame] | 231 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 232 | images.os.end = image_get_image_end(os_hdr); |
| 233 | images.os.load = image_get_load(os_hdr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 234 | break; |
| 235 | #if defined(CONFIG_FIT) |
| 236 | case IMAGE_FORMAT_FIT: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 237 | if (fit_image_get_type(images.fit_hdr_os, |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 238 | images.fit_noffset_os, &images.os.type)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 239 | puts("Can't get image type!\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 240 | bootstage_error(BOOTSTAGE_ID_FIT_TYPE); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 241 | return 1; |
| 242 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 243 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 244 | if (fit_image_get_comp(images.fit_hdr_os, |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 245 | images.fit_noffset_os, &images.os.comp)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 246 | puts("Can't get image compression!\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 247 | bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 248 | return 1; |
| 249 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 250 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 251 | if (fit_image_get_os(images.fit_hdr_os, |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 252 | images.fit_noffset_os, &images.os.os)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 253 | puts("Can't get image OS!\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 254 | bootstage_error(BOOTSTAGE_ID_FIT_OS); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 255 | return 1; |
| 256 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 257 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 258 | images.os.end = fit_get_end(images.fit_hdr_os); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 259 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 260 | 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] | 261 | &images.os.load)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 262 | puts("Can't get image load address!\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 263 | bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 264 | return 1; |
wdenk | b13fb01 | 2003-10-30 21:49:38 +0000 | [diff] [blame] | 265 | } |
| 266 | break; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 267 | #endif |
| 268 | default: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 269 | puts("ERROR: unknown image format type!\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 270 | return 1; |
| 271 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 272 | |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 273 | /* find kernel entry point */ |
| 274 | if (images.legacy_hdr_valid) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 275 | images.ep = image_get_ep(&images.legacy_hdr_os_copy); |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 276 | #if defined(CONFIG_FIT) |
| 277 | } else if (images.fit_uname_os) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 278 | ret = fit_image_get_entry(images.fit_hdr_os, |
Simon Glass | c19d13b | 2013-05-08 08:06:02 +0000 | [diff] [blame] | 279 | images.fit_noffset_os, &images.ep); |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 280 | if (ret) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 281 | puts("Can't get entry point property!\n"); |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 282 | return 1; |
| 283 | } |
| 284 | #endif |
| 285 | } else { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 286 | puts("Could not find kernel entry point!\n"); |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 287 | return 1; |
| 288 | } |
| 289 | |
Stephen Warren | b9b50e8 | 2011-11-10 13:17:53 -0700 | [diff] [blame] | 290 | if (images.os.type == IH_TYPE_KERNEL_NOLOAD) { |
| 291 | images.os.load = images.os.image_start; |
| 292 | images.ep += images.os.load; |
| 293 | } |
| 294 | |
Heiko Schocher | 24de2f4 | 2010-03-29 13:15:48 +0200 | [diff] [blame] | 295 | if (((images.os.type == IH_TYPE_KERNEL) || |
Stephen Warren | b9b50e8 | 2011-11-10 13:17:53 -0700 | [diff] [blame] | 296 | (images.os.type == IH_TYPE_KERNEL_NOLOAD) || |
Heiko Schocher | 24de2f4 | 2010-03-29 13:15:48 +0200 | [diff] [blame] | 297 | (images.os.type == IH_TYPE_MULTI)) && |
Detlev Zundel | 8b828a8 | 2009-12-22 12:43:01 +0100 | [diff] [blame] | 298 | (images.os.os == IH_OS_LINUX)) { |
Kumar Gala | c4f9419 | 2008-08-15 08:24:37 -0500 | [diff] [blame] | 299 | /* find ramdisk */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 300 | ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH, |
Kumar Gala | c4f9419 | 2008-08-15 08:24:37 -0500 | [diff] [blame] | 301 | &images.rd_start, &images.rd_end); |
| 302 | if (ret) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 303 | puts("Ramdisk image is corrupt or invalid\n"); |
Kumar Gala | c4f9419 | 2008-08-15 08:24:37 -0500 | [diff] [blame] | 304 | return 1; |
| 305 | } |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 306 | |
| 307 | #if defined(CONFIG_OF_LIBFDT) |
| 308 | /* find flattened device tree */ |
Simon Glass | 53f375f | 2013-05-16 13:53:23 +0000 | [diff] [blame] | 309 | ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images, |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 310 | &images.ft_addr, &images.ft_len); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 311 | if (ret) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 312 | puts("Could not find a valid device tree\n"); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 313 | return 1; |
| 314 | } |
Kumar Gala | 54f9c86 | 2008-08-15 08:24:39 -0500 | [diff] [blame] | 315 | |
| 316 | set_working_fdt_addr(images.ft_addr); |
Kumar Gala | 06a0991 | 2008-08-15 08:24:38 -0500 | [diff] [blame] | 317 | #endif |
Kumar Gala | c4f9419 | 2008-08-15 08:24:37 -0500 | [diff] [blame] | 318 | } |
| 319 | |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 320 | images.os.start = (ulong)os_hdr; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 321 | images.state = BOOTM_STATE_START; |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | #define BOOTM_ERR_RESET -1 |
| 327 | #define BOOTM_ERR_OVERLAP -2 |
| 328 | #define BOOTM_ERR_UNIMPLEMENTED -3 |
| 329 | static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress) |
| 330 | { |
| 331 | uint8_t comp = os.comp; |
| 332 | ulong load = os.load; |
| 333 | ulong blob_start = os.start; |
| 334 | ulong blob_end = os.end; |
| 335 | ulong image_start = os.image_start; |
| 336 | ulong image_len = os.image_len; |
Anatolij Gustschin | 5bf2766 | 2011-11-19 13:12:18 +0000 | [diff] [blame] | 337 | __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN; |
Stephen Warren | d510859 | 2011-11-10 13:17:54 -0700 | [diff] [blame] | 338 | int no_overlap = 0; |
Simon Glass | aed161e | 2013-05-16 13:53:24 +0000 | [diff] [blame^] | 339 | void *load_buf, *image_buf; |
Matthias Weisser | 60fdc5f | 2010-08-05 13:17:30 +0200 | [diff] [blame] | 340 | #if defined(CONFIG_LZMA) || defined(CONFIG_LZO) |
| 341 | int ret; |
| 342 | #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */ |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 343 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 344 | const char *type_name = genimg_get_type_name(os.type); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 345 | |
Simon Glass | aed161e | 2013-05-16 13:53:24 +0000 | [diff] [blame^] | 346 | load_buf = map_sysmem(load, image_len); |
| 347 | image_buf = map_sysmem(image_start, image_len); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 348 | switch (comp) { |
| 349 | case IH_COMP_NONE: |
Lei Wen | 02cf345 | 2011-01-10 18:21:15 +0800 | [diff] [blame] | 350 | if (load == blob_start || load == image_start) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 351 | printf(" XIP %s ... ", type_name); |
Stephen Warren | d510859 | 2011-11-10 13:17:54 -0700 | [diff] [blame] | 352 | no_overlap = 1; |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 353 | } else { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 354 | printf(" Loading %s ... ", type_name); |
Simon Glass | aed161e | 2013-05-16 13:53:24 +0000 | [diff] [blame^] | 355 | memmove_wd(load_buf, image_buf, image_len, CHUNKSZ); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 356 | } |
| 357 | *load_end = load + image_len; |
| 358 | puts("OK\n"); |
| 359 | break; |
Mike Frysinger | 44431ca | 2010-01-21 19:30:36 -0500 | [diff] [blame] | 360 | #ifdef CONFIG_GZIP |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 361 | case IH_COMP_GZIP: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 362 | printf(" Uncompressing %s ... ", type_name); |
Simon Glass | aed161e | 2013-05-16 13:53:24 +0000 | [diff] [blame^] | 363 | if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 364 | puts("GUNZIP: uncompress, out-of-mem or overwrite " |
| 365 | "error - must RESET board to recover\n"); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 366 | if (boot_progress) |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 367 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 368 | return BOOTM_ERR_RESET; |
| 369 | } |
| 370 | |
| 371 | *load_end = load + image_len; |
| 372 | break; |
Mike Frysinger | 44431ca | 2010-01-21 19:30:36 -0500 | [diff] [blame] | 373 | #endif /* CONFIG_GZIP */ |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 374 | #ifdef CONFIG_BZIP2 |
| 375 | case IH_COMP_BZIP2: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 376 | printf(" Uncompressing %s ... ", type_name); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 377 | /* |
| 378 | * If we've got less than 4 MB of malloc() space, |
| 379 | * use slower decompression algorithm which requires |
| 380 | * at most 2300 KB of memory. |
| 381 | */ |
Simon Glass | aed161e | 2013-05-16 13:53:24 +0000 | [diff] [blame^] | 382 | int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len, |
| 383 | image_buf, image_len, |
| 384 | CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 385 | if (i != BZ_OK) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 386 | printf("BUNZIP2: uncompress or overwrite error %d " |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 387 | "- must RESET board to recover\n", i); |
| 388 | if (boot_progress) |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 389 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 390 | return BOOTM_ERR_RESET; |
| 391 | } |
| 392 | |
| 393 | *load_end = load + unc_len; |
| 394 | break; |
| 395 | #endif /* CONFIG_BZIP2 */ |
Luigi 'Comio' Mantellini | fc9c172 | 2008-09-08 02:46:13 +0200 | [diff] [blame] | 396 | #ifdef CONFIG_LZMA |
Mike Frysinger | 78e1e84 | 2010-07-25 15:54:17 -0400 | [diff] [blame] | 397 | case IH_COMP_LZMA: { |
| 398 | SizeT lzma_len = unc_len; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 399 | printf(" Uncompressing %s ... ", type_name); |
Luigi 'Comio' Mantellini | fc9c172 | 2008-09-08 02:46:13 +0200 | [diff] [blame] | 400 | |
Simon Glass | aed161e | 2013-05-16 13:53:24 +0000 | [diff] [blame^] | 401 | ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len, |
| 402 | image_buf, image_len); |
Mike Frysinger | 78e1e84 | 2010-07-25 15:54:17 -0400 | [diff] [blame] | 403 | unc_len = lzma_len; |
Luigi 'Comio' Mantellini | caf72ff | 2009-07-21 10:45:49 +0200 | [diff] [blame] | 404 | if (ret != SZ_OK) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 405 | printf("LZMA: uncompress or overwrite error %d " |
Luigi 'Comio' Mantellini | fc9c172 | 2008-09-08 02:46:13 +0200 | [diff] [blame] | 406 | "- must RESET board to recover\n", ret); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 407 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
Luigi 'Comio' Mantellini | fc9c172 | 2008-09-08 02:46:13 +0200 | [diff] [blame] | 408 | return BOOTM_ERR_RESET; |
| 409 | } |
| 410 | *load_end = load + unc_len; |
| 411 | break; |
Mike Frysinger | 78e1e84 | 2010-07-25 15:54:17 -0400 | [diff] [blame] | 412 | } |
Luigi 'Comio' Mantellini | fc9c172 | 2008-09-08 02:46:13 +0200 | [diff] [blame] | 413 | #endif /* CONFIG_LZMA */ |
Peter Korsgaard | 20dde48 | 2009-11-19 11:37:51 +0100 | [diff] [blame] | 414 | #ifdef CONFIG_LZO |
| 415 | case IH_COMP_LZO: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 416 | printf(" Uncompressing %s ... ", type_name); |
Peter Korsgaard | 20dde48 | 2009-11-19 11:37:51 +0100 | [diff] [blame] | 417 | |
Simon Glass | aed161e | 2013-05-16 13:53:24 +0000 | [diff] [blame^] | 418 | ret = lzop_decompress(image_buf, image_len, load_buf, |
| 419 | &unc_len); |
Peter Korsgaard | 20dde48 | 2009-11-19 11:37:51 +0100 | [diff] [blame] | 420 | if (ret != LZO_E_OK) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 421 | printf("LZO: uncompress or overwrite error %d " |
Peter Korsgaard | 20dde48 | 2009-11-19 11:37:51 +0100 | [diff] [blame] | 422 | "- must RESET board to recover\n", ret); |
| 423 | if (boot_progress) |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 424 | bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE); |
Peter Korsgaard | 20dde48 | 2009-11-19 11:37:51 +0100 | [diff] [blame] | 425 | return BOOTM_ERR_RESET; |
| 426 | } |
| 427 | |
| 428 | *load_end = load + unc_len; |
| 429 | break; |
| 430 | #endif /* CONFIG_LZO */ |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 431 | default: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 432 | printf("Unimplemented compression type %d\n", comp); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 433 | return BOOTM_ERR_UNIMPLEMENTED; |
| 434 | } |
Diana CRACIUN | 99ffccb | 2011-08-31 02:45:23 +0000 | [diff] [blame] | 435 | |
| 436 | flush_cache(load, (*load_end - load) * sizeof(ulong)); |
| 437 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 438 | puts("OK\n"); |
| 439 | debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 440 | bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 441 | |
Stephen Warren | d510859 | 2011-11-10 13:17:54 -0700 | [diff] [blame] | 442 | if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 443 | debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n", |
| 444 | blob_start, blob_end); |
| 445 | debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load, |
| 446 | *load_end); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 447 | |
| 448 | return BOOTM_ERR_OVERLAP; |
| 449 | } |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 454 | static int bootm_start_standalone(ulong iflag, int argc, char * const argv[]) |
Detlev Zundel | f97ec30 | 2009-07-13 16:01:19 +0200 | [diff] [blame] | 455 | { |
| 456 | char *s; |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 457 | int (*appl)(int, char * const []); |
Detlev Zundel | f97ec30 | 2009-07-13 16:01:19 +0200 | [diff] [blame] | 458 | |
| 459 | /* Don't start if "autostart" is set to "no" */ |
| 460 | if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) { |
Simon Glass | 41ef372 | 2013-02-24 17:33:22 +0000 | [diff] [blame] | 461 | setenv_hex("filesize", images.os.image_len); |
Detlev Zundel | f97ec30 | 2009-07-13 16:01:19 +0200 | [diff] [blame] | 462 | return 0; |
| 463 | } |
Simon Glass | 6d6f123 | 2011-10-07 13:53:40 +0000 | [diff] [blame] | 464 | appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep); |
Detlev Zundel | f97ec30 | 2009-07-13 16:01:19 +0200 | [diff] [blame] | 465 | (*appl)(argc-1, &argv[1]); |
Detlev Zundel | f97ec30 | 2009-07-13 16:01:19 +0200 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 469 | /* we overload the cmd field with our state machine info instead of a |
| 470 | * function pointer */ |
Frans Meulenbroeks | f74d9bd | 2010-02-25 10:12:13 +0100 | [diff] [blame] | 471 | static cmd_tbl_t cmd_bootm_sub[] = { |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 472 | U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""), |
| 473 | U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""), |
John Rigby | fca43cc | 2010-10-13 13:57:35 -0600 | [diff] [blame] | 474 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 475 | U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""), |
| 476 | #endif |
| 477 | #ifdef CONFIG_OF_LIBFDT |
| 478 | U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""), |
| 479 | #endif |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 480 | U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""), |
Peter Tyser | 224c90d | 2009-11-18 19:08:59 -0600 | [diff] [blame] | 481 | U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""), |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 482 | U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""), |
| 483 | U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""), |
| 484 | }; |
| 485 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 486 | static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc, |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 487 | char * const argv[]) |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 488 | { |
| 489 | int ret = 0; |
Simon Glass | 6d6f123 | 2011-10-07 13:53:40 +0000 | [diff] [blame] | 490 | long state; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 491 | cmd_tbl_t *c; |
| 492 | boot_os_fn *boot_fn; |
| 493 | |
| 494 | c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub)); |
| 495 | |
| 496 | if (c) { |
Simon Glass | 6d6f123 | 2011-10-07 13:53:40 +0000 | [diff] [blame] | 497 | state = (long)c->cmd; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 498 | |
| 499 | /* treat start special since it resets the state machine */ |
| 500 | if (state == BOOTM_STATE_START) { |
| 501 | argc--; |
| 502 | argv++; |
| 503 | return bootm_start(cmdtp, flag, argc, argv); |
| 504 | } |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 505 | } else { |
| 506 | /* Unrecognized command */ |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 507 | return CMD_RET_USAGE; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 508 | } |
| 509 | |
Gabor Juhos | 0f30734 | 2013-01-06 23:04:25 +0000 | [diff] [blame] | 510 | if (images.state < BOOTM_STATE_START || |
| 511 | images.state >= state) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 512 | printf("Trying to execute a command out of order\n"); |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 513 | return CMD_RET_USAGE; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | images.state |= state; |
| 517 | boot_fn = boot_os[images.os.os]; |
| 518 | |
| 519 | switch (state) { |
| 520 | ulong load_end; |
| 521 | case BOOTM_STATE_START: |
| 522 | /* should never occur */ |
| 523 | break; |
| 524 | case BOOTM_STATE_LOADOS: |
| 525 | ret = bootm_load_os(images.os, &load_end, 0); |
| 526 | if (ret) |
| 527 | return ret; |
| 528 | |
| 529 | lmb_reserve(&images.lmb, images.os.load, |
| 530 | (load_end - images.os.load)); |
| 531 | break; |
John Rigby | fca43cc | 2010-10-13 13:57:35 -0600 | [diff] [blame] | 532 | #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 533 | case BOOTM_STATE_RAMDISK: |
| 534 | { |
| 535 | ulong rd_len = images.rd_end - images.rd_start; |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 536 | |
| 537 | ret = boot_ramdisk_high(&images.lmb, images.rd_start, |
| 538 | rd_len, &images.initrd_start, &images.initrd_end); |
| 539 | if (ret) |
| 540 | return ret; |
| 541 | |
Simon Glass | 41ef372 | 2013-02-24 17:33:22 +0000 | [diff] [blame] | 542 | setenv_hex("initrd_start", images.initrd_start); |
| 543 | setenv_hex("initrd_end", images.initrd_end); |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 544 | } |
| 545 | break; |
| 546 | #endif |
Simon Glass | 75b3afc | 2012-12-05 14:46:31 +0000 | [diff] [blame] | 547 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB) |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 548 | case BOOTM_STATE_FDT: |
| 549 | { |
Grant Likely | 55b0a39 | 2011-03-28 09:59:01 +0000 | [diff] [blame] | 550 | boot_fdt_add_mem_rsv_regions(&images.lmb, |
| 551 | images.ft_addr); |
Grant Likely | 590d3ca | 2011-03-28 09:58:34 +0000 | [diff] [blame] | 552 | ret = boot_relocate_fdt(&images.lmb, |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 553 | &images.ft_addr, &images.ft_len); |
| 554 | break; |
| 555 | } |
| 556 | #endif |
| 557 | case BOOTM_STATE_OS_CMDLINE: |
| 558 | ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images); |
| 559 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 560 | printf("cmdline subcommand not supported\n"); |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 561 | break; |
| 562 | case BOOTM_STATE_OS_BD_T: |
| 563 | ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images); |
| 564 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 565 | printf("bdt subcommand not supported\n"); |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 566 | break; |
| 567 | case BOOTM_STATE_OS_PREP: |
| 568 | ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images); |
| 569 | if (ret) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 570 | printf("prep subcommand not supported\n"); |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 571 | break; |
| 572 | case BOOTM_STATE_OS_GO: |
| 573 | disable_interrupts(); |
Joe Hershberger | f8be7d6 | 2012-08-03 10:59:08 +0000 | [diff] [blame] | 574 | #ifdef CONFIG_NETCONSOLE |
| 575 | /* |
| 576 | * Stop the ethernet stack if NetConsole could have |
| 577 | * left it up |
| 578 | */ |
| 579 | eth_halt(); |
| 580 | #endif |
Kumar Gala | 3dfad40 | 2009-08-27 08:23:55 -0500 | [diff] [blame] | 581 | arch_preboot_os(); |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 582 | boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images); |
| 583 | break; |
| 584 | } |
| 585 | |
| 586 | return ret; |
| 587 | } |
| 588 | |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 589 | /*******************************************************************/ |
| 590 | /* bootm - boot application image from image in memory */ |
| 591 | /*******************************************************************/ |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 592 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 593 | int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 594 | { |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 595 | ulong iflag; |
| 596 | ulong load_end = 0; |
| 597 | int ret; |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 598 | boot_os_fn *boot_fn; |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 599 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 600 | static int relocated = 0; |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 601 | |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 602 | if (!relocated) { |
| 603 | int i; |
Daniel Schwierzeck | 58bd77d | 2013-01-07 06:54:52 +0000 | [diff] [blame] | 604 | |
| 605 | /* relocate boot function table */ |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 606 | for (i = 0; i < ARRAY_SIZE(boot_os); i++) |
Detlev Zundel | ca95c9d | 2009-07-13 16:01:18 +0200 | [diff] [blame] | 607 | if (boot_os[i] != NULL) |
| 608 | boot_os[i] += gd->reloc_off; |
Daniel Schwierzeck | 58bd77d | 2013-01-07 06:54:52 +0000 | [diff] [blame] | 609 | |
| 610 | /* relocate names of sub-command table */ |
| 611 | for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++) |
| 612 | cmd_bootm_sub[i].name += gd->reloc_off; |
| 613 | |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 614 | relocated = 1; |
| 615 | } |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 616 | #endif |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 617 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 618 | /* determine if we have a sub command */ |
| 619 | if (argc > 1) { |
| 620 | char *endp; |
| 621 | |
| 622 | simple_strtoul(argv[1], &endp, 16); |
| 623 | /* endp pointing to NULL means that argv[1] was just a |
| 624 | * valid number, pass it along to the normal bootm processing |
| 625 | * |
| 626 | * If endp is ':' or '#' assume a FIT identifier so pass |
| 627 | * along for normal processing. |
| 628 | * |
| 629 | * Right now we assume the first arg should never be '-' |
| 630 | */ |
| 631 | if ((*endp != 0) && (*endp != ':') && (*endp != '#')) |
| 632 | return do_bootm_subcommand(cmdtp, flag, argc, argv); |
| 633 | } |
| 634 | |
Anatolij Gustschin | 8e02494 | 2008-08-29 21:04:45 +0200 | [diff] [blame] | 635 | if (bootm_start(cmdtp, flag, argc, argv)) |
| 636 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 637 | |
| 638 | /* |
| 639 | * We have reached the point of no return: we are going to |
| 640 | * overwrite all exception vector code, so we cannot easily |
| 641 | * recover from any failures any more... |
| 642 | */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 643 | iflag = disable_interrupts(); |
| 644 | |
Joe Hershberger | f8be7d6 | 2012-08-03 10:59:08 +0000 | [diff] [blame] | 645 | #ifdef CONFIG_NETCONSOLE |
| 646 | /* Stop the ethernet stack if NetConsole could have left it up */ |
| 647 | eth_halt(); |
| 648 | #endif |
| 649 | |
Stefan Roese | ebb86c4 | 2008-07-30 09:59:51 +0200 | [diff] [blame] | 650 | #if defined(CONFIG_CMD_USB) |
Wolfgang Denk | 699f051 | 2008-07-15 22:22:44 +0200 | [diff] [blame] | 651 | /* |
| 652 | * turn off USB to prevent the host controller from writing to the |
| 653 | * SDRAM while Linux is booting. This could happen (at least for OHCI |
| 654 | * controller), because the HCCA (Host Controller Communication Area) |
| 655 | * lies within the SDRAM and the host controller writes continously to |
| 656 | * this area (as busmaster!). The HccaFrameNumber is for example |
| 657 | * updated every 1 ms within the HCCA structure in SDRAM! For more |
| 658 | * details see the OpenHCI specification. |
| 659 | */ |
Markus Klotzbücher | 3d71c81 | 2008-07-10 14:47:09 +0200 | [diff] [blame] | 660 | usb_stop(); |
| 661 | #endif |
| 662 | |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 663 | ret = bootm_load_os(images.os, &load_end, 1); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 664 | |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 665 | if (ret < 0) { |
| 666 | if (ret == BOOTM_ERR_RESET) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 667 | do_reset(cmdtp, flag, argc, argv); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 668 | if (ret == BOOTM_ERR_OVERLAP) { |
| 669 | if (images.legacy_hdr_valid) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 670 | image_header_t *hdr; |
| 671 | hdr = &images.legacy_hdr_os_copy; |
| 672 | if (image_get_type(hdr) == IH_TYPE_MULTI) |
| 673 | puts("WARNING: legacy format multi " |
| 674 | "component image " |
| 675 | "overwritten\n"); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 676 | } else { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 677 | puts("ERROR: new format image overwritten - " |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 678 | "must RESET the board to recover\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 679 | bootstage_error(BOOTSTAGE_ID_OVERWRITTEN); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 680 | do_reset(cmdtp, flag, argc, argv); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 681 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 682 | } |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 683 | if (ret == BOOTM_ERR_UNIMPLEMENTED) { |
| 684 | if (iflag) |
| 685 | enable_interrupts(); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 686 | bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL); |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 687 | return 1; |
Marian Balakowicz | cb1c489 | 2008-04-11 11:07:49 +0200 | [diff] [blame] | 688 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 689 | } |
Marian Balakowicz | 7582438 | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 690 | |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 691 | lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load)); |
| 692 | |
Detlev Zundel | f97ec30 | 2009-07-13 16:01:19 +0200 | [diff] [blame] | 693 | if (images.os.type == IH_TYPE_STANDALONE) { |
| 694 | if (iflag) |
| 695 | enable_interrupts(); |
| 696 | /* This may return when 'autostart' is 'no' */ |
| 697 | bootm_start_standalone(iflag, argc, argv); |
| 698 | return 0; |
| 699 | } |
| 700 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 701 | bootstage_mark(BOOTSTAGE_ID_CHECK_BOOT_OS); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 702 | |
Joe Hershberger | be2e5a0 | 2013-02-27 10:20:59 +0000 | [diff] [blame] | 703 | #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY) |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 704 | if (images.os.os == IH_OS_LINUX) |
| 705 | fixup_silent_linux(); |
wdenk | 1f4bb37 | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 706 | #endif |
| 707 | |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 708 | boot_fn = boot_os[images.os.os]; |
Detlev Zundel | ca95c9d | 2009-07-13 16:01:18 +0200 | [diff] [blame] | 709 | |
| 710 | if (boot_fn == NULL) { |
| 711 | if (iflag) |
| 712 | enable_interrupts(); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 713 | printf("ERROR: booting os '%s' (%d) is not supported\n", |
Detlev Zundel | ca95c9d | 2009-07-13 16:01:18 +0200 | [diff] [blame] | 714 | genimg_get_os_name(images.os.os), images.os.os); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 715 | bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS); |
Detlev Zundel | ca95c9d | 2009-07-13 16:01:18 +0200 | [diff] [blame] | 716 | return 1; |
| 717 | } |
| 718 | |
Kumar Gala | 3dfad40 | 2009-08-27 08:23:55 -0500 | [diff] [blame] | 719 | arch_preboot_os(); |
| 720 | |
Kumar Gala | be08315 | 2008-10-21 17:25:44 -0500 | [diff] [blame] | 721 | boot_fn(0, argc, argv, &images); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 722 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 723 | bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 724 | #ifdef DEBUG |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 725 | puts("\n## Control returned to monitor - resetting...\n"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 726 | #endif |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 727 | do_reset(cmdtp, flag, argc, argv); |
Marian Balakowicz | a44a269 | 2008-03-12 10:14:57 +0100 | [diff] [blame] | 728 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 729 | return 1; |
| 730 | } |
| 731 | |
Mike Frysinger | 67d668b | 2011-06-05 13:43:02 +0000 | [diff] [blame] | 732 | int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) |
| 733 | { |
| 734 | const char *ep = getenv("autostart"); |
| 735 | |
| 736 | if (ep && !strcmp(ep, "yes")) { |
| 737 | char *local_args[2]; |
| 738 | local_args[0] = (char *)cmd; |
| 739 | local_args[1] = NULL; |
| 740 | printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr); |
| 741 | return do_bootm(cmdtp, 0, 1, local_args); |
| 742 | } |
| 743 | |
| 744 | return 0; |
| 745 | } |
| 746 | |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 747 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 748 | * image_get_kernel - verify legacy format kernel image |
| 749 | * @img_addr: in RAM address of the legacy format image to be verified |
| 750 | * @verify: data CRC verification flag |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 751 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 752 | * image_get_kernel() verifies legacy image integrity and returns pointer to |
| 753 | * legacy image header if image verification was completed successfully. |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 754 | * |
| 755 | * returns: |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 756 | * pointer to a legacy image header if valid image was found |
| 757 | * otherwise return NULL |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 758 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 759 | static image_header_t *image_get_kernel(ulong img_addr, int verify) |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 760 | { |
| 761 | image_header_t *hdr = (image_header_t *)img_addr; |
| 762 | |
| 763 | if (!image_check_magic(hdr)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 764 | puts("Bad Magic Number\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 765 | bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC); |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 766 | return NULL; |
| 767 | } |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 768 | bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER); |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 769 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 770 | if (!image_check_hcrc(hdr)) { |
| 771 | puts("Bad Header Checksum\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 772 | bootstage_error(BOOTSTAGE_ID_CHECK_HEADER); |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 773 | return NULL; |
| 774 | } |
| 775 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 776 | bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 777 | image_print_contents(hdr); |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 778 | |
| 779 | if (verify) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 780 | puts(" Verifying Checksum ... "); |
| 781 | if (!image_check_dcrc(hdr)) { |
| 782 | printf("Bad Data CRC\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 783 | bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM); |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 784 | return NULL; |
| 785 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 786 | puts("OK\n"); |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 787 | } |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 788 | bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH); |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 789 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 790 | if (!image_check_target_arch(hdr)) { |
| 791 | printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr)); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 792 | bootstage_error(BOOTSTAGE_ID_CHECK_ARCH); |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 793 | return NULL; |
| 794 | } |
| 795 | return hdr; |
| 796 | } |
| 797 | |
| 798 | /** |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 799 | * fit_check_kernel - verify FIT format kernel subimage |
| 800 | * @fit_hdr: pointer to the FIT image header |
| 801 | * os_noffset: kernel subimage node offset within FIT image |
| 802 | * @verify: data CRC verification flag |
| 803 | * |
| 804 | * fit_check_kernel() verifies integrity of the kernel subimage and from |
| 805 | * specified FIT image. |
| 806 | * |
| 807 | * returns: |
| 808 | * 1, on success |
| 809 | * 0, on failure |
| 810 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 811 | #if defined(CONFIG_FIT) |
| 812 | static int fit_check_kernel(const void *fit, int os_noffset, int verify) |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 813 | { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 814 | fit_image_print(fit, os_noffset, " "); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 815 | |
| 816 | if (verify) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 817 | puts(" Verifying Hash Integrity ... "); |
Simon Glass | b8da836 | 2013-05-07 06:11:57 +0000 | [diff] [blame] | 818 | if (!fit_image_verify(fit, os_noffset)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 819 | puts("Bad Data Hash\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 820 | bootstage_error(BOOTSTAGE_ID_FIT_CHECK_HASH); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 821 | return 0; |
| 822 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 823 | puts("OK\n"); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 824 | } |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 825 | bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_ARCH); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 826 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 827 | if (!fit_image_check_target_arch(fit, os_noffset)) { |
| 828 | puts("Unsupported Architecture\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 829 | bootstage_error(BOOTSTAGE_ID_FIT_CHECK_ARCH); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 830 | return 0; |
| 831 | } |
| 832 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 833 | bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_KERNEL); |
Stephen Warren | b9b50e8 | 2011-11-10 13:17:53 -0700 | [diff] [blame] | 834 | if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL) && |
| 835 | !fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL_NOLOAD)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 836 | puts("Not a kernel image\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 837 | bootstage_error(BOOTSTAGE_ID_FIT_CHECK_KERNEL); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 838 | return 0; |
| 839 | } |
| 840 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 841 | bootstage_mark(BOOTSTAGE_ID_FIT_CHECKED); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 842 | return 1; |
| 843 | } |
| 844 | #endif /* CONFIG_FIT */ |
| 845 | |
| 846 | /** |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 847 | * boot_get_kernel - find kernel image |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 848 | * @os_data: pointer to a ulong variable, will hold os data start address |
| 849 | * @os_len: pointer to a ulong variable, will hold os data length |
| 850 | * |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 851 | * boot_get_kernel() tries to find a kernel image, verifies its integrity |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 852 | * and locates kernel data. |
| 853 | * |
| 854 | * returns: |
| 855 | * pointer to image header if valid image was found, plus kernel start |
| 856 | * address and length, otherwise NULL |
| 857 | */ |
Simon Glass | 35e7b0f | 2013-05-07 06:12:03 +0000 | [diff] [blame] | 858 | static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc, |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 859 | char * const argv[], bootm_headers_t *images, ulong *os_data, |
| 860 | ulong *os_len) |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 861 | { |
| 862 | image_header_t *hdr; |
| 863 | ulong img_addr; |
Simon Glass | 35e7b0f | 2013-05-07 06:12:03 +0000 | [diff] [blame] | 864 | const void *buf; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 865 | #if defined(CONFIG_FIT) |
Simon Glass | 35e7b0f | 2013-05-07 06:12:03 +0000 | [diff] [blame] | 866 | const void *fit_hdr; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 867 | const char *fit_uname_config = NULL; |
| 868 | const char *fit_uname_kernel = NULL; |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 869 | const void *data; |
| 870 | size_t len; |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 871 | int cfg_noffset; |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 872 | int os_noffset; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 873 | #endif |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 874 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 875 | /* find out kernel image address */ |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 876 | if (argc < 2) { |
| 877 | img_addr = load_addr; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 878 | debug("* kernel: default image load address = 0x%08lx\n", |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 879 | load_addr); |
| 880 | #if defined(CONFIG_FIT) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 881 | } else if (fit_parse_conf(argv[1], load_addr, &img_addr, |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 882 | &fit_uname_config)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 883 | debug("* kernel: config '%s' from image at 0x%08lx\n", |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 884 | fit_uname_config, img_addr); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 885 | } else if (fit_parse_subimage(argv[1], load_addr, &img_addr, |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 886 | &fit_uname_kernel)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 887 | debug("* kernel: subimage '%s' from image at 0x%08lx\n", |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 888 | fit_uname_kernel, img_addr); |
| 889 | #endif |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 890 | } else { |
| 891 | img_addr = simple_strtoul(argv[1], NULL, 16); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 892 | debug("* kernel: cmdline image address = 0x%08lx\n", img_addr); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 893 | } |
| 894 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 895 | bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 896 | |
Marian Balakowicz | fff888a1 | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 897 | /* copy from dataflash if needed */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 898 | img_addr = genimg_get_image(img_addr); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 899 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 900 | /* check image type, for FIT images get FIT kernel node */ |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 901 | *os_data = *os_len = 0; |
Simon Glass | 35e7b0f | 2013-05-07 06:12:03 +0000 | [diff] [blame] | 902 | buf = map_sysmem(img_addr, 0); |
| 903 | switch (genimg_get_format(buf)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 904 | case IMAGE_FORMAT_LEGACY: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 905 | printf("## Booting kernel from Legacy Image at %08lx ...\n", |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 906 | img_addr); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 907 | hdr = image_get_kernel(img_addr, images->verify); |
Marian Balakowicz | 1efd436 | 2008-02-27 11:02:07 +0100 | [diff] [blame] | 908 | if (!hdr) |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 909 | return NULL; |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 910 | bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 911 | |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 912 | /* get os_data and os_len */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 913 | switch (image_get_type(hdr)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 914 | case IH_TYPE_KERNEL: |
Stephen Warren | b9b50e8 | 2011-11-10 13:17:53 -0700 | [diff] [blame] | 915 | case IH_TYPE_KERNEL_NOLOAD: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 916 | *os_data = image_get_data(hdr); |
| 917 | *os_len = image_get_data_size(hdr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 918 | break; |
| 919 | case IH_TYPE_MULTI: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 920 | image_multi_getimg(hdr, 0, os_data, os_len); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 921 | break; |
Detlev Zundel | f97ec30 | 2009-07-13 16:01:19 +0200 | [diff] [blame] | 922 | case IH_TYPE_STANDALONE: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 923 | *os_data = image_get_data(hdr); |
| 924 | *os_len = image_get_data_size(hdr); |
Detlev Zundel | f97ec30 | 2009-07-13 16:01:19 +0200 | [diff] [blame] | 925 | break; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 926 | default: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 927 | printf("Wrong Image Type for %s command\n", |
| 928 | cmdtp->name); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 929 | bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 930 | return NULL; |
| 931 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 932 | |
Marian Balakowicz | cb1c489 | 2008-04-11 11:07:49 +0200 | [diff] [blame] | 933 | /* |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 934 | * copy image header to allow for image overwrites during |
| 935 | * kernel decompression. |
Marian Balakowicz | cb1c489 | 2008-04-11 11:07:49 +0200 | [diff] [blame] | 936 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 937 | memmove(&images->legacy_hdr_os_copy, hdr, |
| 938 | sizeof(image_header_t)); |
Marian Balakowicz | cb1c489 | 2008-04-11 11:07:49 +0200 | [diff] [blame] | 939 | |
| 940 | /* save pointer to image header */ |
| 941 | images->legacy_hdr_os = hdr; |
| 942 | |
| 943 | images->legacy_hdr_valid = 1; |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 944 | bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 945 | break; |
| 946 | #if defined(CONFIG_FIT) |
| 947 | case IMAGE_FORMAT_FIT: |
Simon Glass | 35e7b0f | 2013-05-07 06:12:03 +0000 | [diff] [blame] | 948 | fit_hdr = buf; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 949 | printf("## Booting kernel from FIT Image at %08lx ...\n", |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 950 | img_addr); |
| 951 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 952 | if (!fit_check_format(fit_hdr)) { |
| 953 | puts("Bad FIT kernel image format!\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 954 | bootstage_error(BOOTSTAGE_ID_FIT_FORMAT); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 955 | return NULL; |
| 956 | } |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 957 | bootstage_mark(BOOTSTAGE_ID_FIT_FORMAT); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 958 | |
| 959 | if (!fit_uname_kernel) { |
| 960 | /* |
| 961 | * no kernel image node unit name, try to get config |
| 962 | * node first. If config unit node name is NULL |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 963 | * fit_conf_get_node() will try to find default config |
| 964 | * node |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 965 | */ |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 966 | bootstage_mark(BOOTSTAGE_ID_FIT_NO_UNIT_NAME); |
Gabe Black | d95f6ec | 2012-10-25 16:31:10 +0000 | [diff] [blame] | 967 | #ifdef CONFIG_FIT_BEST_MATCH |
| 968 | if (fit_uname_config) |
| 969 | cfg_noffset = |
| 970 | fit_conf_get_node(fit_hdr, |
| 971 | fit_uname_config); |
| 972 | else |
| 973 | cfg_noffset = |
| 974 | fit_conf_find_compat(fit_hdr, |
| 975 | gd->fdt_blob); |
| 976 | #else |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 977 | cfg_noffset = fit_conf_get_node(fit_hdr, |
| 978 | fit_uname_config); |
Gabe Black | d95f6ec | 2012-10-25 16:31:10 +0000 | [diff] [blame] | 979 | #endif |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 980 | if (cfg_noffset < 0) { |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 981 | bootstage_error(BOOTSTAGE_ID_FIT_NO_UNIT_NAME); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 982 | return NULL; |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 983 | } |
Marian Balakowicz | f773bea | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 984 | /* save configuration uname provided in the first |
| 985 | * bootm argument |
| 986 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 987 | images->fit_uname_cfg = fdt_get_name(fit_hdr, |
| 988 | cfg_noffset, |
| 989 | NULL); |
| 990 | printf(" Using '%s' configuration\n", |
| 991 | images->fit_uname_cfg); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 992 | bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 993 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 994 | os_noffset = fit_conf_get_kernel_node(fit_hdr, |
| 995 | cfg_noffset); |
| 996 | fit_uname_kernel = fit_get_name(fit_hdr, os_noffset, |
| 997 | NULL); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 998 | } else { |
| 999 | /* get kernel component image node offset */ |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 1000 | bootstage_mark(BOOTSTAGE_ID_FIT_UNIT_NAME); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1001 | os_noffset = fit_image_get_node(fit_hdr, |
| 1002 | fit_uname_kernel); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1003 | } |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 1004 | if (os_noffset < 0) { |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 1005 | bootstage_error(BOOTSTAGE_ID_FIT_CONFIG); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1006 | return NULL; |
Marian Balakowicz | 1372cce | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 1007 | } |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1008 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1009 | printf(" Trying '%s' kernel subimage\n", fit_uname_kernel); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1010 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 1011 | bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE); |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1012 | if (!fit_check_kernel(fit_hdr, os_noffset, images->verify)) |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1013 | return NULL; |
| 1014 | |
| 1015 | /* get kernel image data address and length */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1016 | if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) { |
| 1017 | puts("Could not find kernel subimage data!\n"); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 1018 | bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1019 | return NULL; |
| 1020 | } |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 1021 | bootstage_mark(BOOTSTAGE_ID_FIT_KERNEL_INFO); |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1022 | |
| 1023 | *os_len = len; |
| 1024 | *os_data = (ulong)data; |
Simon Glass | 35e7b0f | 2013-05-07 06:12:03 +0000 | [diff] [blame] | 1025 | images->fit_hdr_os = (void *)fit_hdr; |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1026 | images->fit_uname_os = fit_uname_kernel; |
Marian Balakowicz | 3dfe110 | 2008-03-12 10:32:59 +0100 | [diff] [blame] | 1027 | images->fit_noffset_os = os_noffset; |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1028 | break; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1029 | #endif |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 1030 | default: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1031 | printf("Wrong Image Format for %s command\n", cmdtp->name); |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 1032 | bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 1033 | return NULL; |
| 1034 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1035 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1036 | debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n", |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1037 | *os_data, *os_len, *os_len); |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 1038 | |
Simon Glass | 35e7b0f | 2013-05-07 06:12:03 +0000 | [diff] [blame] | 1039 | return buf; |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 1040 | } |
| 1041 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1042 | #ifdef CONFIG_SYS_LONGHELP |
| 1043 | static char bootm_help_text[] = |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1044 | "[addr [arg ...]]\n - boot application image stored in memory\n" |
| 1045 | "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n" |
| 1046 | "\t'arg' can be the address of an initrd image\n" |
Marian Balakowicz | 4a2ad5f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 1047 | #if defined(CONFIG_OF_LIBFDT) |
Matthew McClintock | 98a9c4d | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 1048 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
Detlev Zundel | 5441f61 | 2007-10-19 16:47:26 +0200 | [diff] [blame] | 1049 | "\ta third argument is required which is the address of the\n" |
Matthew McClintock | 98a9c4d | 2006-06-28 10:41:37 -0500 | [diff] [blame] | 1050 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 1051 | "\tuse a '-' for the second argument. If you do not pass a third\n" |
| 1052 | "\ta bd_info struct will be passed instead\n" |
| 1053 | #endif |
Marian Balakowicz | 6986a38 | 2008-03-12 10:01:05 +0100 | [diff] [blame] | 1054 | #if defined(CONFIG_FIT) |
| 1055 | "\t\nFor the new multi component uImage format (FIT) addresses\n" |
| 1056 | "\tmust be extened to include component or configuration unit name:\n" |
| 1057 | "\taddr:<subimg_uname> - direct component image specification\n" |
| 1058 | "\taddr#<conf_uname> - configuration specification\n" |
| 1059 | "\tUse iminfo command to get the list of existing component\n" |
| 1060 | "\timages and configurations.\n" |
| 1061 | #endif |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 1062 | "\nSub-commands to do part of the bootm sequence. The sub-commands " |
| 1063 | "must be\n" |
| 1064 | "issued in the order below (it's ok to not issue all sub-commands):\n" |
| 1065 | "\tstart [addr [arg ...]]\n" |
| 1066 | "\tloados - load OS image\n" |
Daniel Schwierzeck | 59af76d | 2013-02-26 04:54:19 +0000 | [diff] [blame] | 1067 | #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH) |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 1068 | "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n" |
| 1069 | #endif |
| 1070 | #if defined(CONFIG_OF_LIBFDT) |
| 1071 | "\tfdt - relocate flat device tree\n" |
| 1072 | #endif |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 1073 | "\tcmdline - OS specific command line processing/setup\n" |
Peter Tyser | 224c90d | 2009-11-18 19:08:59 -0600 | [diff] [blame] | 1074 | "\tbdt - OS specific bd_t processing\n" |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 1075 | "\tprep - OS specific prep before relocation or go\n" |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1076 | "\tgo - start OS"; |
| 1077 | #endif |
| 1078 | |
| 1079 | U_BOOT_CMD( |
| 1080 | bootm, CONFIG_SYS_MAXARGS, 1, do_bootm, |
| 1081 | "boot application image from memory", bootm_help_text |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1082 | ); |
| 1083 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1084 | /*******************************************************************/ |
| 1085 | /* bootd - boot default image */ |
| 1086 | /*******************************************************************/ |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 1087 | #if defined(CONFIG_CMD_BOOTD) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1088 | int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1089 | { |
| 1090 | int rcode = 0; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1091 | |
Simon Glass | 5307153 | 2012-02-14 19:59:21 +0000 | [diff] [blame] | 1092 | if (run_command(getenv("bootcmd"), flag) < 0) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1093 | rcode = 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1094 | return rcode; |
| 1095 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1096 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1097 | U_BOOT_CMD( |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1098 | boot, 1, 1, do_bootd, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1099 | "boot default, i.e., run 'bootcmd'", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1100 | "" |
wdenk | 9d2b18a | 2003-06-28 23:11:04 +0000 | [diff] [blame] | 1101 | ); |
| 1102 | |
| 1103 | /* keep old command name "bootd" for backward compatibility */ |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1104 | U_BOOT_CMD( |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1105 | bootd, 1, 1, do_bootd, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1106 | "boot default, i.e., run 'bootcmd'", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1107 | "" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1108 | ); |
| 1109 | |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1110 | #endif |
| 1111 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1112 | |
| 1113 | /*******************************************************************/ |
| 1114 | /* iminfo - print header info for a requested image */ |
| 1115 | /*******************************************************************/ |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 1116 | #if defined(CONFIG_CMD_IMI) |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1117 | static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1118 | { |
| 1119 | int arg; |
| 1120 | ulong addr; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1121 | int rcode = 0; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1122 | |
| 1123 | if (argc < 2) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1124 | return image_info(load_addr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1127 | for (arg = 1; arg < argc; ++arg) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1128 | addr = simple_strtoul(argv[arg], NULL, 16); |
| 1129 | if (image_info(addr) != 0) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1130 | rcode = 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1131 | } |
| 1132 | return rcode; |
| 1133 | } |
| 1134 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1135 | static int image_info(ulong addr) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1136 | { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1137 | void *hdr = (void *)addr; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1138 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1139 | printf("\n## Checking Image at %08lx ...\n", addr); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1140 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1141 | switch (genimg_get_format(hdr)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1142 | case IMAGE_FORMAT_LEGACY: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1143 | puts(" Legacy image found\n"); |
| 1144 | if (!image_check_magic(hdr)) { |
| 1145 | puts(" Bad Magic Number\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1146 | return 1; |
| 1147 | } |
| 1148 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1149 | if (!image_check_hcrc(hdr)) { |
| 1150 | puts(" Bad Header Checksum\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1151 | return 1; |
| 1152 | } |
| 1153 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1154 | image_print_contents(hdr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1155 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1156 | puts(" Verifying Checksum ... "); |
| 1157 | if (!image_check_dcrc(hdr)) { |
| 1158 | puts(" Bad Data CRC\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1159 | return 1; |
| 1160 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1161 | puts("OK\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1162 | return 0; |
| 1163 | #if defined(CONFIG_FIT) |
| 1164 | case IMAGE_FORMAT_FIT: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1165 | puts(" FIT image found\n"); |
Marian Balakowicz | e32fea6 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 1166 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1167 | if (!fit_check_format(hdr)) { |
| 1168 | puts("Bad FIT image format!\n"); |
Marian Balakowicz | e32fea6 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 1169 | return 1; |
| 1170 | } |
| 1171 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1172 | fit_print_contents(hdr); |
Bartlomiej Sieka | a4f2434 | 2008-09-09 12:58:16 +0200 | [diff] [blame] | 1173 | |
Simon Glass | b8da836 | 2013-05-07 06:11:57 +0000 | [diff] [blame] | 1174 | if (!fit_all_image_verify(hdr)) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1175 | puts("Bad hash in FIT image!\n"); |
Bartlomiej Sieka | a4f2434 | 2008-09-09 12:58:16 +0200 | [diff] [blame] | 1176 | return 1; |
| 1177 | } |
| 1178 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1179 | return 0; |
| 1180 | #endif |
| 1181 | default: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1182 | puts("Unknown image format!\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1183 | break; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1186 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1187 | } |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1188 | |
| 1189 | U_BOOT_CMD( |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1190 | iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1191 | "print header information for application image", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1192 | "addr [addr ...]\n" |
| 1193 | " - print header information for application image starting at\n" |
| 1194 | " address 'addr' in memory; this includes verification of the\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 1195 | " image contents (magic number, header and payload checksums)" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1196 | ); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 1197 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1198 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1199 | |
| 1200 | /*******************************************************************/ |
| 1201 | /* imls - list all images found in flash */ |
| 1202 | /*******************************************************************/ |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 1203 | #if defined(CONFIG_CMD_IMLS) |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 1204 | static int do_imls_nor(void) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1205 | { |
| 1206 | flash_info_t *info; |
| 1207 | int i, j; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1208 | void *hdr; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1209 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1210 | for (i = 0, info = &flash_info[0]; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1211 | i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) { |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1212 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1213 | if (info->flash_id == FLASH_UNKNOWN) |
| 1214 | goto next_bank; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1215 | for (j = 0; j < info->sector_count; ++j) { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1216 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1217 | hdr = (void *)info->start[j]; |
| 1218 | if (!hdr) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1219 | goto next_sector; |
| 1220 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1221 | switch (genimg_get_format(hdr)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1222 | case IMAGE_FORMAT_LEGACY: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1223 | if (!image_check_hcrc(hdr)) |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1224 | goto next_sector; |
| 1225 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1226 | printf("Legacy Image at %08lX:\n", (ulong)hdr); |
| 1227 | image_print_contents(hdr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1228 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1229 | puts(" Verifying Checksum ... "); |
| 1230 | if (!image_check_dcrc(hdr)) { |
| 1231 | puts("Bad Data CRC\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1232 | } else { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1233 | puts("OK\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1234 | } |
| 1235 | break; |
| 1236 | #if defined(CONFIG_FIT) |
| 1237 | case IMAGE_FORMAT_FIT: |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1238 | if (!fit_check_format(hdr)) |
Marian Balakowicz | e32fea6 | 2008-03-11 12:35:20 +0100 | [diff] [blame] | 1239 | goto next_sector; |
| 1240 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1241 | printf("FIT Image at %08lX:\n", (ulong)hdr); |
| 1242 | fit_print_contents(hdr); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1243 | break; |
| 1244 | #endif |
| 1245 | default: |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1246 | goto next_sector; |
wdenk | 5bb226e | 2003-11-17 21:14:37 +0000 | [diff] [blame] | 1247 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1248 | |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 1249 | next_sector: ; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1250 | } |
wdenk | bdccc4f | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 1251 | next_bank: ; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1252 | } |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 1253 | return 0; |
| 1254 | } |
| 1255 | #endif |
| 1256 | |
| 1257 | #if defined(CONFIG_CMD_IMLS_NAND) |
| 1258 | static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off, |
| 1259 | size_t len) |
| 1260 | { |
| 1261 | void *imgdata; |
| 1262 | int ret; |
| 1263 | |
| 1264 | imgdata = malloc(len); |
| 1265 | if (!imgdata) { |
| 1266 | printf("May be a Legacy Image at NAND device %d offset %08llX:\n", |
| 1267 | nand_dev, off); |
| 1268 | printf(" Low memory(cannot allocate memory for image)\n"); |
| 1269 | return -ENOMEM; |
| 1270 | } |
| 1271 | |
| 1272 | ret = nand_read_skip_bad(nand, off, &len, |
| 1273 | imgdata); |
| 1274 | if (ret < 0 && ret != -EUCLEAN) { |
| 1275 | free(imgdata); |
| 1276 | return ret; |
| 1277 | } |
| 1278 | |
| 1279 | if (!image_check_hcrc(imgdata)) { |
| 1280 | free(imgdata); |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | printf("Legacy Image at NAND device %d offset %08llX:\n", |
| 1285 | nand_dev, off); |
| 1286 | image_print_contents(imgdata); |
| 1287 | |
| 1288 | puts(" Verifying Checksum ... "); |
| 1289 | if (!image_check_dcrc(imgdata)) |
| 1290 | puts("Bad Data CRC\n"); |
| 1291 | else |
| 1292 | puts("OK\n"); |
| 1293 | |
| 1294 | free(imgdata); |
| 1295 | |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
| 1299 | static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off, |
| 1300 | size_t len) |
| 1301 | { |
| 1302 | void *imgdata; |
| 1303 | int ret; |
| 1304 | |
| 1305 | imgdata = malloc(len); |
| 1306 | if (!imgdata) { |
| 1307 | printf("May be a FIT Image at NAND device %d offset %08llX:\n", |
| 1308 | nand_dev, off); |
| 1309 | printf(" Low memory(cannot allocate memory for image)\n"); |
| 1310 | return -ENOMEM; |
| 1311 | } |
| 1312 | |
| 1313 | ret = nand_read_skip_bad(nand, off, &len, |
| 1314 | imgdata); |
| 1315 | if (ret < 0 && ret != -EUCLEAN) { |
| 1316 | free(imgdata); |
| 1317 | return ret; |
| 1318 | } |
| 1319 | |
| 1320 | if (!fit_check_format(imgdata)) { |
| 1321 | free(imgdata); |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off); |
| 1326 | |
| 1327 | fit_print_contents(imgdata); |
| 1328 | free(imgdata); |
| 1329 | |
| 1330 | return 0; |
| 1331 | } |
| 1332 | |
| 1333 | static int do_imls_nand(void) |
| 1334 | { |
| 1335 | nand_info_t *nand; |
| 1336 | int nand_dev = nand_curr_device; |
| 1337 | size_t len; |
| 1338 | loff_t off; |
| 1339 | u32 buffer[16]; |
| 1340 | |
| 1341 | if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) { |
| 1342 | puts("\nNo NAND devices available\n"); |
| 1343 | return -ENODEV; |
| 1344 | } |
| 1345 | |
| 1346 | printf("\n"); |
| 1347 | |
| 1348 | for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) { |
| 1349 | nand = &nand_info[nand_dev]; |
| 1350 | if (!nand->name || !nand->size) |
| 1351 | continue; |
| 1352 | |
| 1353 | for (off = 0; off < nand->size; off += nand->erasesize) { |
| 1354 | const image_header_t *header; |
| 1355 | int ret; |
| 1356 | |
| 1357 | if (nand_block_isbad(nand, off)) |
| 1358 | continue; |
| 1359 | |
| 1360 | len = sizeof(buffer); |
| 1361 | |
| 1362 | ret = nand_read(nand, off, &len, (u8 *)buffer); |
| 1363 | if (ret < 0 && ret != -EUCLEAN) { |
| 1364 | printf("NAND read error %d at offset %08llX\n", |
| 1365 | ret, off); |
| 1366 | continue; |
| 1367 | } |
| 1368 | |
| 1369 | switch (genimg_get_format(buffer)) { |
| 1370 | case IMAGE_FORMAT_LEGACY: |
| 1371 | header = (const image_header_t *)buffer; |
| 1372 | |
| 1373 | len = image_get_image_size(header); |
| 1374 | nand_imls_legacyimage(nand, nand_dev, off, len); |
| 1375 | break; |
| 1376 | #if defined(CONFIG_FIT) |
| 1377 | case IMAGE_FORMAT_FIT: |
| 1378 | len = fit_get_size(buffer); |
| 1379 | nand_imls_fitimage(nand, nand_dev, off, len); |
| 1380 | break; |
| 1381 | #endif |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | return 0; |
| 1387 | } |
| 1388 | #endif |
| 1389 | |
| 1390 | #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND) |
| 1391 | static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 1392 | { |
| 1393 | int ret_nor = 0, ret_nand = 0; |
| 1394 | |
| 1395 | #if defined(CONFIG_CMD_IMLS) |
| 1396 | ret_nor = do_imls_nor(); |
| 1397 | #endif |
| 1398 | |
| 1399 | #if defined(CONFIG_CMD_IMLS_NAND) |
| 1400 | ret_nand = do_imls_nand(); |
| 1401 | #endif |
| 1402 | |
| 1403 | if (ret_nor) |
| 1404 | return ret_nor; |
| 1405 | |
| 1406 | if (ret_nand) |
| 1407 | return ret_nand; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1408 | |
| 1409 | return (0); |
| 1410 | } |
| 1411 | |
| 1412 | U_BOOT_CMD( |
| 1413 | imls, 1, 1, do_imls, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 1414 | "list all images found in flash", |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1415 | "\n" |
Vipin Kumar | 8fdf1e0 | 2012-12-16 22:32:48 +0000 | [diff] [blame] | 1416 | " - Prints information about all images found at sector/block\n" |
| 1417 | " boundaries in nor/nand flash." |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1418 | ); |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 1419 | #endif |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1420 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1421 | /*******************************************************************/ |
Marian Balakowicz | 5cf746c | 2008-01-31 13:59:09 +0100 | [diff] [blame] | 1422 | /* helper routines */ |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1423 | /*******************************************************************/ |
Joe Hershberger | be2e5a0 | 2013-02-27 10:20:59 +0000 | [diff] [blame] | 1424 | #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY) |
Doug Anderson | a558ad7 | 2012-01-17 09:37:41 +0000 | [diff] [blame] | 1425 | |
| 1426 | #define CONSOLE_ARG "console=" |
| 1427 | #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1) |
| 1428 | |
Doug Anderson | 3a8653b | 2011-10-19 12:30:57 +0000 | [diff] [blame] | 1429 | static void fixup_silent_linux(void) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1430 | { |
Doug Anderson | a558ad7 | 2012-01-17 09:37:41 +0000 | [diff] [blame] | 1431 | char *buf; |
| 1432 | const char *env_val; |
Doug Anderson | 3a8653b | 2011-10-19 12:30:57 +0000 | [diff] [blame] | 1433 | char *cmdline = getenv("bootargs"); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1434 | |
| 1435 | /* Only fix cmdline when requested */ |
| 1436 | if (!(gd->flags & GD_FLG_SILENT)) |
| 1437 | return; |
| 1438 | |
Doug Anderson | 3a8653b | 2011-10-19 12:30:57 +0000 | [diff] [blame] | 1439 | debug("before silent fix-up: %s\n", cmdline); |
Doug Anderson | a558ad7 | 2012-01-17 09:37:41 +0000 | [diff] [blame] | 1440 | if (cmdline && (cmdline[0] != '\0')) { |
| 1441 | char *start = strstr(cmdline, CONSOLE_ARG); |
| 1442 | |
| 1443 | /* Allocate space for maximum possible new command line */ |
| 1444 | buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1); |
| 1445 | if (!buf) { |
| 1446 | debug("%s: out of memory\n", __func__); |
| 1447 | return; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1448 | } |
Doug Anderson | a558ad7 | 2012-01-17 09:37:41 +0000 | [diff] [blame] | 1449 | |
| 1450 | if (start) { |
| 1451 | char *end = strchr(start, ' '); |
| 1452 | int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN; |
| 1453 | |
| 1454 | strncpy(buf, cmdline, num_start_bytes); |
| 1455 | if (end) |
| 1456 | strcpy(buf + num_start_bytes, end); |
| 1457 | else |
| 1458 | buf[num_start_bytes] = '\0'; |
| 1459 | } else { |
| 1460 | sprintf(buf, "%s %s", cmdline, CONSOLE_ARG); |
| 1461 | } |
| 1462 | env_val = buf; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1463 | } else { |
Doug Anderson | a558ad7 | 2012-01-17 09:37:41 +0000 | [diff] [blame] | 1464 | buf = NULL; |
| 1465 | env_val = CONSOLE_ARG; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
Doug Anderson | a558ad7 | 2012-01-17 09:37:41 +0000 | [diff] [blame] | 1468 | setenv("bootargs", env_val); |
| 1469 | debug("after silent fix-up: %s\n", env_val); |
| 1470 | free(buf); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1471 | } |
| 1472 | #endif /* CONFIG_SILENT_CONSOLE */ |
| 1473 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1474 | |
| 1475 | /*******************************************************************/ |
| 1476 | /* OS booting routines */ |
| 1477 | /*******************************************************************/ |
| 1478 | |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 1479 | #ifdef CONFIG_BOOTM_NETBSD |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1480 | static int do_bootm_netbsd(int flag, int argc, char * const argv[], |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 1481 | bootm_headers_t *images) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1482 | { |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1483 | void (*loader)(bd_t *, image_header_t *, char *, char *); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1484 | image_header_t *os_hdr, *hdr; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 1485 | ulong kernel_data, kernel_len; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1486 | char *consdev; |
| 1487 | char *cmdline; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1488 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 1489 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 1490 | return 1; |
| 1491 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1492 | #if defined(CONFIG_FIT) |
| 1493 | if (!images->legacy_hdr_valid) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1494 | fit_unsupported_reset("NetBSD"); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 1495 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1496 | } |
| 1497 | #endif |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1498 | hdr = images->legacy_hdr_os; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1499 | |
| 1500 | /* |
| 1501 | * Booting a (NetBSD) kernel image |
| 1502 | * |
| 1503 | * This process is pretty similar to a standalone application: |
| 1504 | * The (first part of an multi-) image must be a stage-2 loader, |
| 1505 | * which in turn is responsible for loading & invoking the actual |
| 1506 | * kernel. The only differences are the parameters being passed: |
| 1507 | * besides the board info strucure, the loader expects a command |
| 1508 | * line, the name of the console device, and (optionally) the |
| 1509 | * address of the original image header. |
| 1510 | */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1511 | os_hdr = NULL; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1512 | if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { |
| 1513 | image_multi_getimg(hdr, 1, &kernel_data, &kernel_len); |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 1514 | if (kernel_len) |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1515 | os_hdr = hdr; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 1516 | } |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1517 | |
| 1518 | consdev = ""; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1519 | #if defined(CONFIG_8xx_CONS_SMC1) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1520 | consdev = "smc1"; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1521 | #elif defined(CONFIG_8xx_CONS_SMC2) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1522 | consdev = "smc2"; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1523 | #elif defined(CONFIG_8xx_CONS_SCC2) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1524 | consdev = "scc2"; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1525 | #elif defined(CONFIG_8xx_CONS_SCC3) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1526 | consdev = "scc3"; |
| 1527 | #endif |
| 1528 | |
| 1529 | if (argc > 2) { |
| 1530 | ulong len; |
| 1531 | int i; |
| 1532 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1533 | for (i = 2, len = 0; i < argc; i += 1) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1534 | len += strlen(argv[i]) + 1; |
| 1535 | cmdline = malloc(len); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1536 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1537 | for (i = 2, len = 0; i < argc; i += 1) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1538 | if (i > 2) |
| 1539 | cmdline[len++] = ' '; |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1540 | strcpy(&cmdline[len], argv[i]); |
| 1541 | len += strlen(argv[i]); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1542 | } |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1543 | } else if ((cmdline = getenv("bootargs")) == NULL) { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1544 | cmdline = ""; |
| 1545 | } |
| 1546 | |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 1547 | loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1548 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1549 | printf("## Transferring control to NetBSD stage-2 loader " |
| 1550 | "(at address %08lx) ...\n", |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1551 | (ulong)loader); |
| 1552 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 1553 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1554 | |
| 1555 | /* |
| 1556 | * NetBSD Stage-2 Loader Parameters: |
| 1557 | * r3: ptr to board info data |
| 1558 | * r4: image address |
| 1559 | * r5: console device |
| 1560 | * r6: boot args string |
| 1561 | */ |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1562 | (*loader)(gd->bd, os_hdr, consdev, cmdline); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 1563 | |
| 1564 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1565 | } |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 1566 | #endif /* CONFIG_BOOTM_NETBSD*/ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1567 | |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1568 | #ifdef CONFIG_LYNXKDI |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1569 | static int do_bootm_lynxkdi(int flag, int argc, char * const argv[], |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 1570 | bootm_headers_t *images) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1571 | { |
Marian Balakowicz | cb1c489 | 2008-04-11 11:07:49 +0200 | [diff] [blame] | 1572 | image_header_t *hdr = &images->legacy_hdr_os_copy; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1573 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 1574 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 1575 | return 1; |
| 1576 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1577 | #if defined(CONFIG_FIT) |
| 1578 | if (!images->legacy_hdr_valid) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1579 | fit_unsupported_reset("Lynx"); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 1580 | return 1; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1581 | } |
| 1582 | #endif |
| 1583 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1584 | lynxkdi_boot((image_header_t *)hdr); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 1585 | |
| 1586 | return 1; |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1587 | } |
| 1588 | #endif /* CONFIG_LYNXKDI */ |
| 1589 | |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 1590 | #ifdef CONFIG_BOOTM_RTEMS |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1591 | static int do_bootm_rtems(int flag, int argc, char * const argv[], |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 1592 | bootm_headers_t *images) |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1593 | { |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1594 | void (*entry_point)(bd_t *); |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 1595 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 1596 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 1597 | return 1; |
| 1598 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1599 | #if defined(CONFIG_FIT) |
| 1600 | if (!images->legacy_hdr_valid) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1601 | fit_unsupported_reset("RTEMS"); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 1602 | return 1; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1603 | } |
| 1604 | #endif |
| 1605 | |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 1606 | entry_point = (void (*)(bd_t *))images->ep; |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 1607 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1608 | printf("## Transferring control to RTEMS (at address %08lx) ...\n", |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 1609 | (ulong)entry_point); |
| 1610 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 1611 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 1612 | |
| 1613 | /* |
| 1614 | * RTEMS Parameters: |
| 1615 | * r3: ptr to board info data |
| 1616 | */ |
Marian Balakowicz | 1ee1180 | 2008-01-08 18:17:10 +0100 | [diff] [blame] | 1617 | (*entry_point)(gd->bd); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 1618 | |
| 1619 | return 1; |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 1620 | } |
Kumar Gala | b1d0db1 | 2008-10-21 17:25:47 -0500 | [diff] [blame] | 1621 | #endif /* CONFIG_BOOTM_RTEMS */ |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 1622 | |
Torkel Lundgren | 3df6195 | 2010-09-28 11:05:36 +0200 | [diff] [blame] | 1623 | #if defined(CONFIG_BOOTM_OSE) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1624 | static int do_bootm_ose(int flag, int argc, char * const argv[], |
Torkel Lundgren | 3df6195 | 2010-09-28 11:05:36 +0200 | [diff] [blame] | 1625 | bootm_headers_t *images) |
| 1626 | { |
| 1627 | void (*entry_point)(void); |
| 1628 | |
| 1629 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 1630 | return 1; |
| 1631 | |
| 1632 | #if defined(CONFIG_FIT) |
| 1633 | if (!images->legacy_hdr_valid) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1634 | fit_unsupported_reset("OSE"); |
Torkel Lundgren | 3df6195 | 2010-09-28 11:05:36 +0200 | [diff] [blame] | 1635 | return 1; |
| 1636 | } |
| 1637 | #endif |
| 1638 | |
| 1639 | entry_point = (void (*)(void))images->ep; |
| 1640 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1641 | printf("## Transferring control to OSE (at address %08lx) ...\n", |
Torkel Lundgren | 3df6195 | 2010-09-28 11:05:36 +0200 | [diff] [blame] | 1642 | (ulong)entry_point); |
| 1643 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 1644 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
Torkel Lundgren | 3df6195 | 2010-09-28 11:05:36 +0200 | [diff] [blame] | 1645 | |
| 1646 | /* |
| 1647 | * OSE Parameters: |
| 1648 | * None |
| 1649 | */ |
| 1650 | (*entry_point)(); |
| 1651 | |
| 1652 | return 1; |
| 1653 | } |
| 1654 | #endif /* CONFIG_BOOTM_OSE */ |
| 1655 | |
Steven Stallion | 04d4140 | 2013-03-20 06:31:35 +0000 | [diff] [blame] | 1656 | #if defined(CONFIG_BOOTM_PLAN9) |
| 1657 | static int do_bootm_plan9(int flag, int argc, char * const argv[], |
| 1658 | bootm_headers_t *images) |
| 1659 | { |
| 1660 | void (*entry_point)(void); |
| 1661 | |
| 1662 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 1663 | return 1; |
| 1664 | |
| 1665 | #if defined(CONFIG_FIT) |
| 1666 | if (!images->legacy_hdr_valid) { |
| 1667 | fit_unsupported_reset("Plan 9"); |
| 1668 | return 1; |
| 1669 | } |
| 1670 | #endif |
| 1671 | |
| 1672 | entry_point = (void (*)(void))images->ep; |
| 1673 | |
| 1674 | printf("## Transferring control to Plan 9 (at address %08lx) ...\n", |
| 1675 | (ulong)entry_point); |
| 1676 | |
| 1677 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 1678 | |
| 1679 | /* |
| 1680 | * Plan 9 Parameters: |
| 1681 | * None |
| 1682 | */ |
| 1683 | (*entry_point)(); |
| 1684 | |
| 1685 | return 1; |
| 1686 | } |
| 1687 | #endif /* CONFIG_BOOTM_PLAN9 */ |
| 1688 | |
Jon Loeliger | baa26db | 2007-07-08 17:51:39 -0500 | [diff] [blame] | 1689 | #if defined(CONFIG_CMD_ELF) |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1690 | static int do_bootm_vxworks(int flag, int argc, char * const argv[], |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 1691 | bootm_headers_t *images) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1692 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1693 | char str[80]; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1694 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 1695 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 1696 | return 1; |
| 1697 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1698 | #if defined(CONFIG_FIT) |
Marian Balakowicz | cb1c489 | 2008-04-11 11:07:49 +0200 | [diff] [blame] | 1699 | if (!images->legacy_hdr_valid) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1700 | fit_unsupported_reset("VxWorks"); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 1701 | return 1; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1702 | } |
| 1703 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1704 | |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 1705 | sprintf(str, "%lx", images->ep); /* write entry-point into string */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1706 | setenv("loadaddr", str); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 1707 | do_bootvx(NULL, 0, 0, NULL); |
| 1708 | |
| 1709 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 1712 | static int do_bootm_qnxelf(int flag, int argc, char * const argv[], |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 1713 | bootm_headers_t *images) |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1714 | { |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1715 | char *local_args[2]; |
| 1716 | char str[16]; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1717 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 1718 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 1719 | return 1; |
| 1720 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1721 | #if defined(CONFIG_FIT) |
| 1722 | if (!images->legacy_hdr_valid) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1723 | fit_unsupported_reset("QNX"); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 1724 | return 1; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1725 | } |
| 1726 | #endif |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1727 | |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 1728 | sprintf(str, "%lx", images->ep); /* write entry-point into string */ |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1729 | local_args[0] = argv[0]; |
| 1730 | local_args[1] = str; /* and provide it via the arguments */ |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 1731 | do_bootelf(NULL, 0, 2, local_args); |
| 1732 | |
| 1733 | return 1; |
wdenk | 47d1a6e | 2002-11-03 00:01:44 +0000 | [diff] [blame] | 1734 | } |
Jon Loeliger | 9025317 | 2007-07-10 11:02:44 -0500 | [diff] [blame] | 1735 | #endif |
Peter Tyser | f5ed9e3 | 2008-09-08 14:56:49 -0500 | [diff] [blame] | 1736 | |
| 1737 | #ifdef CONFIG_INTEGRITY |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1738 | static int do_bootm_integrity(int flag, int argc, char * const argv[], |
Peter Tyser | f5ed9e3 | 2008-09-08 14:56:49 -0500 | [diff] [blame] | 1739 | bootm_headers_t *images) |
| 1740 | { |
| 1741 | void (*entry_point)(void); |
| 1742 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 1743 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 1744 | return 1; |
| 1745 | |
Peter Tyser | f5ed9e3 | 2008-09-08 14:56:49 -0500 | [diff] [blame] | 1746 | #if defined(CONFIG_FIT) |
| 1747 | if (!images->legacy_hdr_valid) { |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1748 | fit_unsupported_reset("INTEGRITY"); |
Peter Tyser | f5ed9e3 | 2008-09-08 14:56:49 -0500 | [diff] [blame] | 1749 | return 1; |
| 1750 | } |
| 1751 | #endif |
| 1752 | |
| 1753 | entry_point = (void (*)(void))images->ep; |
| 1754 | |
Stephen Warren | 712fbcf | 2011-10-18 11:11:49 +0000 | [diff] [blame] | 1755 | printf("## Transferring control to INTEGRITY (at address %08lx) ...\n", |
Peter Tyser | f5ed9e3 | 2008-09-08 14:56:49 -0500 | [diff] [blame] | 1756 | (ulong)entry_point); |
| 1757 | |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 1758 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
Peter Tyser | f5ed9e3 | 2008-09-08 14:56:49 -0500 | [diff] [blame] | 1759 | |
| 1760 | /* |
| 1761 | * INTEGRITY Parameters: |
| 1762 | * None |
| 1763 | */ |
| 1764 | (*entry_point)(); |
| 1765 | |
| 1766 | return 1; |
| 1767 | } |
| 1768 | #endif |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 1769 | |
| 1770 | #ifdef CONFIG_CMD_BOOTZ |
| 1771 | |
| 1772 | static int __bootz_setup(void *image, void **start, void **end) |
| 1773 | { |
| 1774 | /* Please define bootz_setup() for your platform */ |
| 1775 | |
| 1776 | puts("Your platform's zImage format isn't supported yet!\n"); |
| 1777 | return -1; |
| 1778 | } |
| 1779 | int bootz_setup(void *image, void **start, void **end) |
| 1780 | __attribute__((weak, alias("__bootz_setup"))); |
| 1781 | |
| 1782 | /* |
| 1783 | * zImage booting support |
| 1784 | */ |
| 1785 | static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc, |
| 1786 | char * const argv[], bootm_headers_t *images) |
| 1787 | { |
| 1788 | int ret; |
| 1789 | void *zi_start, *zi_end; |
| 1790 | |
| 1791 | memset(images, 0, sizeof(bootm_headers_t)); |
| 1792 | |
| 1793 | boot_start_lmb(images); |
| 1794 | |
| 1795 | /* Setup Linux kernel zImage entry point */ |
| 1796 | if (argc < 2) { |
| 1797 | images->ep = load_addr; |
| 1798 | debug("* kernel: default image load address = 0x%08lx\n", |
| 1799 | load_addr); |
| 1800 | } else { |
| 1801 | images->ep = simple_strtoul(argv[1], NULL, 16); |
| 1802 | debug("* kernel: cmdline image address = 0x%08lx\n", |
| 1803 | images->ep); |
| 1804 | } |
| 1805 | |
| 1806 | ret = bootz_setup((void *)images->ep, &zi_start, &zi_end); |
| 1807 | if (ret != 0) |
| 1808 | return 1; |
| 1809 | |
| 1810 | lmb_reserve(&images->lmb, images->ep, zi_end - zi_start); |
| 1811 | |
| 1812 | /* Find ramdisk */ |
| 1813 | ret = boot_get_ramdisk(argc, argv, images, IH_INITRD_ARCH, |
| 1814 | &images->rd_start, &images->rd_end); |
| 1815 | if (ret) { |
| 1816 | puts("Ramdisk image is corrupt or invalid\n"); |
| 1817 | return 1; |
| 1818 | } |
| 1819 | |
| 1820 | #if defined(CONFIG_OF_LIBFDT) |
| 1821 | /* find flattened device tree */ |
Simon Glass | 53f375f | 2013-05-16 13:53:23 +0000 | [diff] [blame] | 1822 | ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, images, |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 1823 | &images->ft_addr, &images->ft_len); |
| 1824 | if (ret) { |
| 1825 | puts("Could not find a valid device tree\n"); |
| 1826 | return 1; |
| 1827 | } |
| 1828 | |
| 1829 | set_working_fdt_addr(images->ft_addr); |
| 1830 | #endif |
| 1831 | |
| 1832 | return 0; |
| 1833 | } |
| 1834 | |
| 1835 | static int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 1836 | { |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 1837 | bootm_headers_t images; |
| 1838 | |
| 1839 | if (bootz_start(cmdtp, flag, argc, argv, &images)) |
| 1840 | return 1; |
| 1841 | |
| 1842 | /* |
| 1843 | * We have reached the point of no return: we are going to |
| 1844 | * overwrite all exception vector code, so we cannot easily |
| 1845 | * recover from any failures any more... |
| 1846 | */ |
Anatolij Gustschin | a075a79 | 2012-05-19 05:38:19 +0000 | [diff] [blame] | 1847 | disable_interrupts(); |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 1848 | |
Joe Hershberger | f8be7d6 | 2012-08-03 10:59:08 +0000 | [diff] [blame] | 1849 | #ifdef CONFIG_NETCONSOLE |
| 1850 | /* Stop the ethernet stack if NetConsole could have left it up */ |
| 1851 | eth_halt(); |
| 1852 | #endif |
| 1853 | |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 1854 | #if defined(CONFIG_CMD_USB) |
| 1855 | /* |
| 1856 | * turn off USB to prevent the host controller from writing to the |
| 1857 | * SDRAM while Linux is booting. This could happen (at least for OHCI |
| 1858 | * controller), because the HCCA (Host Controller Communication Area) |
| 1859 | * lies within the SDRAM and the host controller writes continously to |
| 1860 | * this area (as busmaster!). The HccaFrameNumber is for example |
| 1861 | * updated every 1 ms within the HCCA structure in SDRAM! For more |
| 1862 | * details see the OpenHCI specification. |
| 1863 | */ |
| 1864 | usb_stop(); |
| 1865 | #endif |
| 1866 | |
Joe Hershberger | be2e5a0 | 2013-02-27 10:20:59 +0000 | [diff] [blame] | 1867 | #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY) |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 1868 | fixup_silent_linux(); |
| 1869 | #endif |
| 1870 | arch_preboot_os(); |
| 1871 | |
| 1872 | do_bootm_linux(0, argc, argv, &images); |
| 1873 | #ifdef DEBUG |
| 1874 | puts("\n## Control returned to monitor - resetting...\n"); |
| 1875 | #endif |
| 1876 | do_reset(cmdtp, flag, argc, argv); |
| 1877 | |
| 1878 | return 1; |
| 1879 | } |
| 1880 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1881 | #ifdef CONFIG_SYS_LONGHELP |
| 1882 | static char bootz_help_text[] = |
Marek Vasut | 017e1f3 | 2012-03-18 11:47:58 +0000 | [diff] [blame] | 1883 | "[addr [initrd[:size]] [fdt]]\n" |
| 1884 | " - boot Linux zImage stored in memory\n" |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 1885 | "\tThe argument 'initrd' is optional and specifies the address\n" |
Marek Vasut | 017e1f3 | 2012-03-18 11:47:58 +0000 | [diff] [blame] | 1886 | "\tof the initrd in memory. The optional argument ':size' allows\n" |
| 1887 | "\tspecifying the size of RAW initrd.\n" |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 1888 | #if defined(CONFIG_OF_LIBFDT) |
| 1889 | "\tWhen booting a Linux kernel which requires a flat device-tree\n" |
| 1890 | "\ta third argument is required which is the address of the\n" |
| 1891 | "\tdevice-tree blob. To boot that kernel without an initrd image,\n" |
| 1892 | "\tuse a '-' for the second argument. If you do not pass a third\n" |
| 1893 | "\ta bd_info struct will be passed instead\n" |
| 1894 | #endif |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 1895 | ""; |
| 1896 | #endif |
| 1897 | |
| 1898 | U_BOOT_CMD( |
| 1899 | bootz, CONFIG_SYS_MAXARGS, 1, do_bootz, |
| 1900 | "boot Linux zImage image from memory", bootz_help_text |
Marek Vasut | 44f074c | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 1901 | ); |
| 1902 | #endif /* CONFIG_CMD_BOOTZ */ |