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