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