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