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