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