Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 Semihalf |
| 3 | * |
| 4 | * (C) Copyright 2000-2006 |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 26 | #define DEBUG |
| 27 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 28 | #include <common.h> |
| 29 | #include <watchdog.h> |
| 30 | #include <command.h> |
| 31 | #include <image.h> |
| 32 | #include <malloc.h> |
| 33 | #include <zlib.h> |
| 34 | #include <bzlib.h> |
| 35 | #include <environment.h> |
| 36 | #include <asm/byteorder.h> |
| 37 | |
| 38 | #if defined(CONFIG_OF_LIBFDT) |
| 39 | #include <fdt.h> |
| 40 | #include <libfdt.h> |
| 41 | #include <fdt_support.h> |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 42 | |
| 43 | static void fdt_error (const char *msg); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 44 | #endif |
| 45 | |
| 46 | #ifdef CONFIG_LOGBUFFER |
| 47 | #include <logbuff.h> |
| 48 | #endif |
| 49 | |
| 50 | #ifdef CFG_INIT_RAM_LOCK |
| 51 | #include <asm/cache.h> |
| 52 | #endif |
| 53 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 54 | DECLARE_GLOBAL_DATA_PTR; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 55 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 56 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 57 | |
| 58 | #if defined(CONFIG_CMD_BDI) |
| 59 | extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 60 | #endif |
| 61 | |
| 62 | void __attribute__((noinline)) |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 63 | do_bootm_linux(cmd_tbl_t *cmdtp, int flag, |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 64 | int argc, char *argv[], |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 65 | image_header_t *hdr, |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 66 | int verify) |
| 67 | { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 68 | ulong initrd_high; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 69 | int initrd_copy_to_ram = 1; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 70 | ulong initrd_start, initrd_end; |
| 71 | ulong rd_data, rd_len; |
| 72 | image_header_t *rd_hdr; |
| 73 | |
| 74 | ulong cmd_start, cmd_end; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 75 | char *cmdline; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 76 | |
| 77 | ulong sp; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 78 | char *s; |
| 79 | bd_t *kbd; |
| 80 | void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 81 | |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 82 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 83 | image_header_t *fdt_hdr; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 84 | char *of_flat_tree = NULL; |
| 85 | ulong of_data = 0; |
| 86 | #endif |
| 87 | |
| 88 | if ((s = getenv ("initrd_high")) != NULL) { |
| 89 | /* a value of "no" or a similar string will act like 0, |
| 90 | * turning the "load high" feature off. This is intentional. |
| 91 | */ |
| 92 | initrd_high = simple_strtoul(s, NULL, 16); |
| 93 | if (initrd_high == ~0) |
| 94 | initrd_copy_to_ram = 0; |
| 95 | } else { /* not set, no restrictions to load high */ |
| 96 | initrd_high = ~0; |
| 97 | } |
| 98 | |
| 99 | #ifdef CONFIG_LOGBUFFER |
| 100 | kbd=gd->bd; |
| 101 | /* Prevent initrd from overwriting logbuffer */ |
| 102 | if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD)) |
| 103 | initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD; |
| 104 | debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN); |
| 105 | #endif |
| 106 | |
| 107 | /* |
| 108 | * Booting a (Linux) kernel image |
| 109 | * |
| 110 | * Allocate space for command line and board info - the |
| 111 | * address should be as high as possible within the reach of |
| 112 | * the kernel (see CFG_BOOTMAPSZ settings), but in unused |
| 113 | * memory, which means far enough below the current stack |
| 114 | * pointer. |
| 115 | */ |
| 116 | |
| 117 | asm( "mr %0,1": "=r"(sp) : ); |
| 118 | |
| 119 | debug ("## Current stack ends at 0x%08lX ", sp); |
| 120 | |
| 121 | sp -= 2048; /* just to be sure */ |
| 122 | if (sp > CFG_BOOTMAPSZ) |
| 123 | sp = CFG_BOOTMAPSZ; |
| 124 | sp &= ~0xF; |
| 125 | |
| 126 | debug ("=> set upper limit to 0x%08lX\n", sp); |
| 127 | |
| 128 | cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF); |
| 129 | kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF); |
| 130 | |
| 131 | if ((s = getenv("bootargs")) == NULL) |
| 132 | s = ""; |
| 133 | |
| 134 | strcpy (cmdline, s); |
| 135 | |
| 136 | cmd_start = (ulong)&cmdline[0]; |
| 137 | cmd_end = cmd_start + strlen(cmdline); |
| 138 | |
| 139 | *kbd = *(gd->bd); |
| 140 | |
| 141 | #ifdef DEBUG |
| 142 | printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end); |
| 143 | |
| 144 | #if defined(CONFIG_CMD_BDI) |
| 145 | do_bdinfo (NULL, 0, 0, NULL); |
| 146 | #endif |
| 147 | #endif |
| 148 | |
| 149 | if ((s = getenv ("clocks_in_mhz")) != NULL) { |
| 150 | /* convert all clock information to MHz */ |
| 151 | kbd->bi_intfreq /= 1000000L; |
| 152 | kbd->bi_busfreq /= 1000000L; |
| 153 | #if defined(CONFIG_MPC8220) |
| 154 | kbd->bi_inpfreq /= 1000000L; |
| 155 | kbd->bi_pcifreq /= 1000000L; |
| 156 | kbd->bi_pevfreq /= 1000000L; |
| 157 | kbd->bi_flbfreq /= 1000000L; |
| 158 | kbd->bi_vcofreq /= 1000000L; |
| 159 | #endif |
| 160 | #if defined(CONFIG_CPM2) |
| 161 | kbd->bi_cpmfreq /= 1000000L; |
| 162 | kbd->bi_brgfreq /= 1000000L; |
| 163 | kbd->bi_sccfreq /= 1000000L; |
| 164 | kbd->bi_vco /= 1000000L; |
| 165 | #endif |
| 166 | #if defined(CONFIG_MPC5xxx) |
| 167 | kbd->bi_ipbfreq /= 1000000L; |
| 168 | kbd->bi_pcifreq /= 1000000L; |
| 169 | #endif /* CONFIG_MPC5xxx */ |
| 170 | } |
| 171 | |
| 172 | kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr); |
| 173 | |
| 174 | /* |
| 175 | * Check if there is an initrd image |
| 176 | */ |
| 177 | |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 178 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 179 | /* Look for a '-' which indicates to ignore the ramdisk argument */ |
| 180 | if (argc >= 3 && strcmp(argv[2], "-") == 0) { |
| 181 | debug ("Skipping initrd\n"); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 182 | rd_len = rd_data = 0; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 183 | } |
| 184 | else |
| 185 | #endif |
| 186 | if (argc >= 3) { |
| 187 | debug ("Not skipping initrd\n"); |
| 188 | show_boot_progress (9); |
| 189 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 190 | rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); |
| 191 | printf ("## Loading RAMDisk Image at %08lx ...\n", (ulong)rd_hdr); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 192 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 193 | if (!image_check_magic (rd_hdr)) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 194 | puts ("Bad Magic Number\n"); |
| 195 | show_boot_progress (-10); |
| 196 | do_reset (cmdtp, flag, argc, argv); |
| 197 | } |
| 198 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 199 | if (!image_check_hcrc (rd_hdr)) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 200 | puts ("Bad Header Checksum\n"); |
| 201 | show_boot_progress (-11); |
| 202 | do_reset (cmdtp, flag, argc, argv); |
| 203 | } |
| 204 | show_boot_progress (10); |
| 205 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 206 | print_image_hdr (rd_hdr); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 207 | |
| 208 | if (verify) { |
| 209 | puts (" Verifying Checksum ... "); |
| 210 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 211 | if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 212 | puts ("Bad Data CRC\n"); |
| 213 | show_boot_progress (-12); |
| 214 | do_reset (cmdtp, flag, argc, argv); |
| 215 | } |
| 216 | puts ("OK\n"); |
| 217 | } |
| 218 | |
| 219 | show_boot_progress (11); |
| 220 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 221 | if (!image_check_os (rd_hdr, IH_OS_LINUX) || |
| 222 | !image_check_arch (rd_hdr, IH_ARCH_PPC) || |
| 223 | !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 224 | puts ("No Linux PPC Ramdisk Image\n"); |
| 225 | show_boot_progress (-13); |
| 226 | do_reset (cmdtp, flag, argc, argv); |
| 227 | } |
| 228 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 229 | rd_data = image_get_data (rd_hdr); |
| 230 | rd_len = image_get_data_size (rd_hdr); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 231 | |
| 232 | /* |
| 233 | * Now check if we have a multifile image |
| 234 | */ |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 235 | } else if (image_check_type (hdr, IH_TYPE_MULTI)) { |
| 236 | /* |
| 237 | * Get second entry data start address and len |
| 238 | */ |
| 239 | image_multi_getimg (hdr, 1, &rd_data, &rd_len); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 240 | show_boot_progress (13); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 241 | } else { |
| 242 | /* |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 243 | * No initrd image |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 244 | */ |
| 245 | show_boot_progress (14); |
| 246 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 247 | rd_len = rd_data = 0; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 250 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 251 | if(argc > 3) { |
| 252 | of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 253 | fdt_hdr = (image_header_t *)of_flat_tree; |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 254 | |
Marian Balakowicz | ed68d47 | 2008-01-08 18:11:44 +0100 | [diff] [blame] | 255 | if (fdt_check_header (of_flat_tree) == 0) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 256 | #ifndef CFG_NO_FLASH |
| 257 | if (addr2info((ulong)of_flat_tree) != NULL) |
| 258 | of_data = (ulong)of_flat_tree; |
| 259 | #endif |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 260 | } else if (image_check_magic (fdt_hdr)) { |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 261 | ulong image_start, image_end; |
| 262 | ulong load_start, load_end; |
| 263 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 264 | printf ("## Flat Device Tree at %08lX\n", fdt_hdr); |
| 265 | print_image_hdr (fdt_hdr); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 266 | |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 267 | image_start = (ulong)fdt_hdr; |
| 268 | image_end = image_get_image_end (fdt_hdr); |
| 269 | |
| 270 | load_start = image_get_load (fdt_hdr); |
| 271 | load_end = load_start + image_get_data_size (fdt_hdr); |
| 272 | |
| 273 | if ((load_start < image_end) && (load_end > image_start)) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 274 | fdt_error ("fdt overwritten"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 275 | do_reset (cmdtp, flag, argc, argv); |
| 276 | } |
| 277 | |
| 278 | puts (" Verifying Checksum ... "); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 279 | if (!image_check_hcrc (fdt_hdr)) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 280 | fdt_error ("fdt header checksum invalid"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 281 | do_reset (cmdtp, flag, argc, argv); |
| 282 | } |
| 283 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 284 | if (!image_check_dcrc (fdt_hdr)) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 285 | fdt_error ("fdt checksum invalid"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 286 | do_reset (cmdtp, flag, argc, argv); |
| 287 | } |
| 288 | puts ("OK\n"); |
| 289 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 290 | if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 291 | fdt_error ("uImage is not a fdt"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 292 | do_reset (cmdtp, flag, argc, argv); |
| 293 | } |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 294 | if (image_get_comp (fdt_hdr) != IH_COMP_NONE) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 295 | fdt_error ("uImage is compressed"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 296 | do_reset (cmdtp, flag, argc, argv); |
| 297 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 298 | if (fdt_check_header (of_flat_tree + image_get_header_size ()) != 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 299 | fdt_error ("uImage data is not a fdt"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 300 | do_reset (cmdtp, flag, argc, argv); |
| 301 | } |
| 302 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 303 | memmove ((void *)image_get_load (fdt_hdr), |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 304 | (void *)(of_flat_tree + image_get_header_size ()), |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 305 | image_get_data_size (fdt_hdr)); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 306 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 307 | of_flat_tree = (char *)image_get_load (fdt_hdr); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 308 | } else { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 309 | fdt_error ("Did not find a Flattened Device Tree"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 310 | do_reset (cmdtp, flag, argc, argv); |
| 311 | } |
| 312 | printf (" Booting using the fdt at 0x%x\n", |
| 313 | of_flat_tree); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 314 | } else if (image_check_type (hdr, IH_TYPE_MULTI)) { |
| 315 | ulong fdt_data, fdt_len; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 316 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 317 | image_multi_getimg (hdr, 2, &fdt_data, &fdt_len); |
| 318 | if (fdt_len) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 319 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 320 | of_flat_tree = (char *)fdt_data; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 321 | |
| 322 | #ifndef CFG_NO_FLASH |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 323 | /* move the blob if it is in flash (set of_data to !null) */ |
| 324 | if (addr2info ((ulong)of_flat_tree) != NULL) |
| 325 | of_data = (ulong)of_flat_tree; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 326 | #endif |
| 327 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 328 | if (fdt_check_header (of_flat_tree) != 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 329 | fdt_error ("image is not a fdt"); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 330 | do_reset (cmdtp, flag, argc, argv); |
| 331 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 332 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 333 | if (be32_to_cpu (fdt_totalsize (of_flat_tree)) != fdt_len) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 334 | fdt_error ("fdt size != image size"); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 335 | do_reset (cmdtp, flag, argc, argv); |
| 336 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | #endif |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 340 | if (!rd_data) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 341 | debug ("No initrd\n"); |
| 342 | } |
| 343 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 344 | if (rd_data) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 345 | if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 346 | initrd_start = rd_data; |
| 347 | initrd_end = initrd_start + rd_len; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 348 | } else { |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 349 | initrd_start = (ulong)kbd - rd_len; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 350 | initrd_start &= ~(4096 - 1); /* align on page */ |
| 351 | |
| 352 | if (initrd_high) { |
| 353 | ulong nsp; |
| 354 | |
| 355 | /* |
| 356 | * the inital ramdisk does not need to be within |
| 357 | * CFG_BOOTMAPSZ as it is not accessed until after |
| 358 | * the mm system is initialised. |
| 359 | * |
| 360 | * do the stack bottom calculation again and see if |
| 361 | * the initrd will fit just below the monitor stack |
| 362 | * bottom without overwriting the area allocated |
| 363 | * above for command line args and board info. |
| 364 | */ |
| 365 | asm( "mr %0,1": "=r"(nsp) : ); |
| 366 | nsp -= 2048; /* just to be sure */ |
| 367 | nsp &= ~0xF; |
| 368 | if (nsp > initrd_high) /* limit as specified */ |
| 369 | nsp = initrd_high; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 370 | nsp -= rd_len; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 371 | nsp &= ~(4096 - 1); /* align on page */ |
| 372 | if (nsp >= sp) |
| 373 | initrd_start = nsp; |
| 374 | } |
| 375 | |
| 376 | show_boot_progress (12); |
| 377 | |
| 378 | debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 379 | rd_data, rd_data + rd_len - 1, rd_len, rd_len); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 380 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 381 | initrd_end = initrd_start + rd_len; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 382 | printf (" Loading Ramdisk to %08lx, end %08lx ... ", |
| 383 | initrd_start, initrd_end); |
Marian Balakowicz | f9a67bd | 2008-01-08 18:11:45 +0100 | [diff] [blame] | 384 | |
| 385 | memmove_wd((void *)initrd_start, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 386 | (void *)rd_data, rd_len, CHUNKSZ); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 387 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 388 | puts ("OK\n"); |
| 389 | } |
| 390 | } else { |
| 391 | initrd_start = 0; |
| 392 | initrd_end = 0; |
| 393 | } |
| 394 | |
| 395 | #if defined(CONFIG_OF_LIBFDT) |
| 396 | |
| 397 | #ifdef CFG_BOOTMAPSZ |
| 398 | /* |
| 399 | * The blob must be within CFG_BOOTMAPSZ, |
| 400 | * so we flag it to be copied if it is not. |
| 401 | */ |
| 402 | if (of_flat_tree >= (char *)CFG_BOOTMAPSZ) |
| 403 | of_data = (ulong)of_flat_tree; |
| 404 | #endif |
| 405 | |
| 406 | /* move of_flat_tree if needed */ |
| 407 | if (of_data) { |
| 408 | int err; |
| 409 | ulong of_start, of_len; |
| 410 | |
| 411 | of_len = be32_to_cpu(fdt_totalsize(of_data)); |
| 412 | |
| 413 | /* position on a 4K boundary before the kbd */ |
| 414 | of_start = (ulong)kbd - of_len; |
| 415 | of_start &= ~(4096 - 1); /* align on page */ |
| 416 | debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", |
| 417 | of_data, of_data + of_len - 1, of_len, of_len); |
| 418 | |
| 419 | of_flat_tree = (char *)of_start; |
| 420 | printf (" Loading Device Tree to %08lx, end %08lx ... ", |
| 421 | of_start, of_start + of_len - 1); |
| 422 | err = fdt_open_into((void *)of_data, (void *)of_start, of_len); |
| 423 | if (err != 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 424 | fdt_error ("fdt move failed"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 425 | do_reset (cmdtp, flag, argc, argv); |
| 426 | } |
| 427 | puts ("OK\n"); |
| 428 | } |
| 429 | /* |
| 430 | * Add the chosen node if it doesn't exist, add the env and bd_t |
| 431 | * if the user wants it (the logic is in the subroutines). |
| 432 | */ |
| 433 | if (of_flat_tree) { |
| 434 | if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 435 | fdt_error ("/chosen node create failed"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 436 | do_reset (cmdtp, flag, argc, argv); |
| 437 | } |
| 438 | #ifdef CONFIG_OF_HAS_UBOOT_ENV |
| 439 | if (fdt_env(of_flat_tree) < 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 440 | fdt_error ("/u-boot-env node create failed"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 441 | do_reset (cmdtp, flag, argc, argv); |
| 442 | } |
| 443 | #endif |
| 444 | #ifdef CONFIG_OF_HAS_BD_T |
| 445 | if (fdt_bd_t(of_flat_tree) < 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 446 | fdt_error ("/bd_t node create failed"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 447 | do_reset (cmdtp, flag, argc, argv); |
| 448 | } |
| 449 | #endif |
| 450 | #ifdef CONFIG_OF_BOARD_SETUP |
| 451 | /* Call the board-specific fixup routine */ |
| 452 | ft_board_setup(of_flat_tree, gd->bd); |
| 453 | #endif |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 454 | } |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 455 | #endif /* CONFIG_OF_LIBFDT */ |
Marian Balakowicz | 751b2b8 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 456 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 457 | debug ("## Transferring control to Linux (at address %08lx) ...\n", |
| 458 | (ulong)kernel); |
| 459 | |
| 460 | show_boot_progress (15); |
| 461 | |
| 462 | #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) |
| 463 | unlock_ram_in_cache(); |
| 464 | #endif |
| 465 | |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 466 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 467 | if (of_flat_tree) { /* device tree; boot new style */ |
| 468 | /* |
| 469 | * Linux Kernel Parameters (passing device tree): |
| 470 | * r3: pointer to the fdt, followed by the board info data |
| 471 | * r4: physical pointer to the kernel itself |
| 472 | * r5: NULL |
| 473 | * r6: NULL |
| 474 | * r7: NULL |
| 475 | */ |
| 476 | (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0); |
| 477 | /* does not return */ |
| 478 | } |
| 479 | #endif |
| 480 | /* |
| 481 | * Linux Kernel Parameters (passing board info data): |
| 482 | * r3: ptr to board info data |
| 483 | * r4: initrd_start or 0 if no initrd |
| 484 | * r5: initrd_end - unused if r4 is 0 |
| 485 | * r6: Start of command line string |
| 486 | * r7: End of command line string |
| 487 | */ |
| 488 | (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); |
| 489 | /* does not return */ |
| 490 | } |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame^] | 491 | |
| 492 | #if defined(CONFIG_OF_LIBFDT) |
| 493 | static void fdt_error (const char *msg) |
| 494 | { |
| 495 | puts ("ERROR: "); |
| 496 | puts (msg); |
| 497 | puts (" - must RESET the board to recover.\n"); |
| 498 | } |
| 499 | #endif |