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; |
Marian Balakowicz | 9541850 | 2008-01-31 13:55:39 +0100 | [diff] [blame^] | 71 | ulong rd_data_start, rd_data_end, rd_len; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 72 | |
| 73 | ulong cmd_start, cmd_end; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 74 | char *cmdline; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 75 | |
| 76 | ulong sp; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 77 | char *s; |
| 78 | bd_t *kbd; |
| 79 | void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 80 | |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 81 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 82 | image_header_t *fdt_hdr; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 83 | char *of_flat_tree = NULL; |
| 84 | ulong of_data = 0; |
| 85 | #endif |
| 86 | |
| 87 | if ((s = getenv ("initrd_high")) != NULL) { |
| 88 | /* a value of "no" or a similar string will act like 0, |
| 89 | * turning the "load high" feature off. This is intentional. |
| 90 | */ |
| 91 | initrd_high = simple_strtoul(s, NULL, 16); |
| 92 | if (initrd_high == ~0) |
| 93 | initrd_copy_to_ram = 0; |
| 94 | } else { /* not set, no restrictions to load high */ |
| 95 | initrd_high = ~0; |
| 96 | } |
| 97 | |
| 98 | #ifdef CONFIG_LOGBUFFER |
| 99 | kbd=gd->bd; |
| 100 | /* Prevent initrd from overwriting logbuffer */ |
| 101 | if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD)) |
| 102 | initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD; |
| 103 | debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN); |
| 104 | #endif |
| 105 | |
| 106 | /* |
| 107 | * Booting a (Linux) kernel image |
| 108 | * |
| 109 | * Allocate space for command line and board info - the |
| 110 | * address should be as high as possible within the reach of |
| 111 | * the kernel (see CFG_BOOTMAPSZ settings), but in unused |
| 112 | * memory, which means far enough below the current stack |
| 113 | * pointer. |
| 114 | */ |
| 115 | |
| 116 | asm( "mr %0,1": "=r"(sp) : ); |
| 117 | |
| 118 | debug ("## Current stack ends at 0x%08lX ", sp); |
| 119 | |
| 120 | sp -= 2048; /* just to be sure */ |
| 121 | if (sp > CFG_BOOTMAPSZ) |
| 122 | sp = CFG_BOOTMAPSZ; |
| 123 | sp &= ~0xF; |
| 124 | |
| 125 | debug ("=> set upper limit to 0x%08lX\n", sp); |
| 126 | |
| 127 | cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF); |
| 128 | kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF); |
| 129 | |
| 130 | if ((s = getenv("bootargs")) == NULL) |
| 131 | s = ""; |
| 132 | |
| 133 | strcpy (cmdline, s); |
| 134 | |
| 135 | cmd_start = (ulong)&cmdline[0]; |
| 136 | cmd_end = cmd_start + strlen(cmdline); |
| 137 | |
| 138 | *kbd = *(gd->bd); |
| 139 | |
| 140 | #ifdef DEBUG |
| 141 | printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end); |
| 142 | |
| 143 | #if defined(CONFIG_CMD_BDI) |
| 144 | do_bdinfo (NULL, 0, 0, NULL); |
| 145 | #endif |
| 146 | #endif |
| 147 | |
| 148 | if ((s = getenv ("clocks_in_mhz")) != NULL) { |
| 149 | /* convert all clock information to MHz */ |
| 150 | kbd->bi_intfreq /= 1000000L; |
| 151 | kbd->bi_busfreq /= 1000000L; |
| 152 | #if defined(CONFIG_MPC8220) |
| 153 | kbd->bi_inpfreq /= 1000000L; |
| 154 | kbd->bi_pcifreq /= 1000000L; |
| 155 | kbd->bi_pevfreq /= 1000000L; |
| 156 | kbd->bi_flbfreq /= 1000000L; |
| 157 | kbd->bi_vcofreq /= 1000000L; |
| 158 | #endif |
| 159 | #if defined(CONFIG_CPM2) |
| 160 | kbd->bi_cpmfreq /= 1000000L; |
| 161 | kbd->bi_brgfreq /= 1000000L; |
| 162 | kbd->bi_sccfreq /= 1000000L; |
| 163 | kbd->bi_vco /= 1000000L; |
| 164 | #endif |
| 165 | #if defined(CONFIG_MPC5xxx) |
| 166 | kbd->bi_ipbfreq /= 1000000L; |
| 167 | kbd->bi_pcifreq /= 1000000L; |
| 168 | #endif /* CONFIG_MPC5xxx */ |
| 169 | } |
| 170 | |
| 171 | kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr); |
| 172 | |
Marian Balakowicz | 9541850 | 2008-01-31 13:55:39 +0100 | [diff] [blame^] | 173 | get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, |
| 174 | IH_ARCH_PPC, &rd_data_start, &rd_data_end); |
| 175 | rd_len = rd_data_end - rd_data_start; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 176 | |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 177 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 178 | if(argc > 3) { |
| 179 | of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 180 | fdt_hdr = (image_header_t *)of_flat_tree; |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 181 | |
Marian Balakowicz | ed68d47 | 2008-01-08 18:11:44 +0100 | [diff] [blame] | 182 | if (fdt_check_header (of_flat_tree) == 0) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 183 | #ifndef CFG_NO_FLASH |
| 184 | if (addr2info((ulong)of_flat_tree) != NULL) |
| 185 | of_data = (ulong)of_flat_tree; |
| 186 | #endif |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 187 | } else if (image_check_magic (fdt_hdr)) { |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 188 | ulong image_start, image_end; |
| 189 | ulong load_start, load_end; |
| 190 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 191 | printf ("## Flat Device Tree at %08lX\n", fdt_hdr); |
| 192 | print_image_hdr (fdt_hdr); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 193 | |
Marian Balakowicz | f92332b | 2008-01-31 13:20:06 +0100 | [diff] [blame] | 194 | image_start = (ulong)fdt_hdr; |
| 195 | image_end = image_get_image_end (fdt_hdr); |
| 196 | |
| 197 | load_start = image_get_load (fdt_hdr); |
| 198 | load_end = load_start + image_get_data_size (fdt_hdr); |
| 199 | |
| 200 | if ((load_start < image_end) && (load_end > image_start)) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 201 | fdt_error ("fdt overwritten"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 202 | do_reset (cmdtp, flag, argc, argv); |
| 203 | } |
| 204 | |
| 205 | puts (" Verifying Checksum ... "); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 206 | if (!image_check_hcrc (fdt_hdr)) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 207 | fdt_error ("fdt header checksum invalid"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 208 | do_reset (cmdtp, flag, argc, argv); |
| 209 | } |
| 210 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 211 | if (!image_check_dcrc (fdt_hdr)) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 212 | fdt_error ("fdt checksum invalid"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 213 | do_reset (cmdtp, flag, argc, argv); |
| 214 | } |
| 215 | puts ("OK\n"); |
| 216 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 217 | if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 218 | fdt_error ("uImage is not a fdt"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 219 | do_reset (cmdtp, flag, argc, argv); |
| 220 | } |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 221 | if (image_get_comp (fdt_hdr) != IH_COMP_NONE) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 222 | fdt_error ("uImage is compressed"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 223 | do_reset (cmdtp, flag, argc, argv); |
| 224 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 225 | if (fdt_check_header (of_flat_tree + image_get_header_size ()) != 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 226 | fdt_error ("uImage data is not a fdt"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 227 | do_reset (cmdtp, flag, argc, argv); |
| 228 | } |
| 229 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 230 | memmove ((void *)image_get_load (fdt_hdr), |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 231 | (void *)(of_flat_tree + image_get_header_size ()), |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 232 | image_get_data_size (fdt_hdr)); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 233 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 234 | of_flat_tree = (char *)image_get_load (fdt_hdr); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 235 | } else { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 236 | fdt_error ("Did not find a Flattened Device Tree"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 237 | do_reset (cmdtp, flag, argc, argv); |
| 238 | } |
| 239 | printf (" Booting using the fdt at 0x%x\n", |
| 240 | of_flat_tree); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 241 | } else if (image_check_type (hdr, IH_TYPE_MULTI)) { |
| 242 | ulong fdt_data, fdt_len; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 243 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 244 | image_multi_getimg (hdr, 2, &fdt_data, &fdt_len); |
| 245 | if (fdt_len) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 246 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 247 | of_flat_tree = (char *)fdt_data; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 248 | |
| 249 | #ifndef CFG_NO_FLASH |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 250 | /* move the blob if it is in flash (set of_data to !null) */ |
| 251 | if (addr2info ((ulong)of_flat_tree) != NULL) |
| 252 | of_data = (ulong)of_flat_tree; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 253 | #endif |
| 254 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 255 | if (fdt_check_header (of_flat_tree) != 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 256 | fdt_error ("image is not a fdt"); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 257 | do_reset (cmdtp, flag, argc, argv); |
| 258 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 259 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 260 | if (be32_to_cpu (fdt_totalsize (of_flat_tree)) != fdt_len) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 261 | fdt_error ("fdt size != image size"); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 262 | do_reset (cmdtp, flag, argc, argv); |
| 263 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | #endif |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 267 | |
Marian Balakowicz | 9541850 | 2008-01-31 13:55:39 +0100 | [diff] [blame^] | 268 | if (rd_data_start) { |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 269 | if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ |
Marian Balakowicz | 9541850 | 2008-01-31 13:55:39 +0100 | [diff] [blame^] | 270 | initrd_start = rd_data_start; |
| 271 | initrd_end = rd_data_end; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 272 | } else { |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 273 | initrd_start = (ulong)kbd - rd_len; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 274 | initrd_start &= ~(4096 - 1); /* align on page */ |
| 275 | |
| 276 | if (initrd_high) { |
| 277 | ulong nsp; |
| 278 | |
| 279 | /* |
| 280 | * the inital ramdisk does not need to be within |
| 281 | * CFG_BOOTMAPSZ as it is not accessed until after |
| 282 | * the mm system is initialised. |
| 283 | * |
| 284 | * do the stack bottom calculation again and see if |
| 285 | * the initrd will fit just below the monitor stack |
| 286 | * bottom without overwriting the area allocated |
| 287 | * above for command line args and board info. |
| 288 | */ |
| 289 | asm( "mr %0,1": "=r"(nsp) : ); |
| 290 | nsp -= 2048; /* just to be sure */ |
| 291 | nsp &= ~0xF; |
| 292 | if (nsp > initrd_high) /* limit as specified */ |
| 293 | nsp = initrd_high; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 294 | nsp -= rd_len; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 295 | nsp &= ~(4096 - 1); /* align on page */ |
| 296 | if (nsp >= sp) |
| 297 | initrd_start = nsp; |
| 298 | } |
| 299 | |
| 300 | show_boot_progress (12); |
| 301 | |
| 302 | debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", |
Marian Balakowicz | 9541850 | 2008-01-31 13:55:39 +0100 | [diff] [blame^] | 303 | rd_data_start, rd_data_end - 1, rd_len, rd_len); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 304 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 305 | initrd_end = initrd_start + rd_len; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 306 | printf (" Loading Ramdisk to %08lx, end %08lx ... ", |
| 307 | initrd_start, initrd_end); |
Marian Balakowicz | f9a67bd | 2008-01-08 18:11:45 +0100 | [diff] [blame] | 308 | |
| 309 | memmove_wd((void *)initrd_start, |
Marian Balakowicz | 9541850 | 2008-01-31 13:55:39 +0100 | [diff] [blame^] | 310 | (void *)rd_data_start, rd_len, CHUNKSZ); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 311 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 312 | puts ("OK\n"); |
| 313 | } |
| 314 | } else { |
| 315 | initrd_start = 0; |
| 316 | initrd_end = 0; |
| 317 | } |
| 318 | |
| 319 | #if defined(CONFIG_OF_LIBFDT) |
| 320 | |
| 321 | #ifdef CFG_BOOTMAPSZ |
| 322 | /* |
| 323 | * The blob must be within CFG_BOOTMAPSZ, |
| 324 | * so we flag it to be copied if it is not. |
| 325 | */ |
| 326 | if (of_flat_tree >= (char *)CFG_BOOTMAPSZ) |
| 327 | of_data = (ulong)of_flat_tree; |
| 328 | #endif |
| 329 | |
| 330 | /* move of_flat_tree if needed */ |
| 331 | if (of_data) { |
| 332 | int err; |
| 333 | ulong of_start, of_len; |
| 334 | |
| 335 | of_len = be32_to_cpu(fdt_totalsize(of_data)); |
| 336 | |
| 337 | /* position on a 4K boundary before the kbd */ |
| 338 | of_start = (ulong)kbd - of_len; |
| 339 | of_start &= ~(4096 - 1); /* align on page */ |
| 340 | debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", |
| 341 | of_data, of_data + of_len - 1, of_len, of_len); |
| 342 | |
| 343 | of_flat_tree = (char *)of_start; |
| 344 | printf (" Loading Device Tree to %08lx, end %08lx ... ", |
| 345 | of_start, of_start + of_len - 1); |
| 346 | err = fdt_open_into((void *)of_data, (void *)of_start, of_len); |
| 347 | if (err != 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 348 | fdt_error ("fdt move failed"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 349 | do_reset (cmdtp, flag, argc, argv); |
| 350 | } |
| 351 | puts ("OK\n"); |
| 352 | } |
| 353 | /* |
| 354 | * Add the chosen node if it doesn't exist, add the env and bd_t |
| 355 | * if the user wants it (the logic is in the subroutines). |
| 356 | */ |
| 357 | if (of_flat_tree) { |
| 358 | if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 359 | fdt_error ("/chosen node create failed"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 360 | do_reset (cmdtp, flag, argc, argv); |
| 361 | } |
| 362 | #ifdef CONFIG_OF_HAS_UBOOT_ENV |
| 363 | if (fdt_env(of_flat_tree) < 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 364 | fdt_error ("/u-boot-env node create failed"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 365 | do_reset (cmdtp, flag, argc, argv); |
| 366 | } |
| 367 | #endif |
| 368 | #ifdef CONFIG_OF_HAS_BD_T |
| 369 | if (fdt_bd_t(of_flat_tree) < 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 370 | fdt_error ("/bd_t node create failed"); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 371 | do_reset (cmdtp, flag, argc, argv); |
| 372 | } |
| 373 | #endif |
| 374 | #ifdef CONFIG_OF_BOARD_SETUP |
| 375 | /* Call the board-specific fixup routine */ |
| 376 | ft_board_setup(of_flat_tree, gd->bd); |
| 377 | #endif |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 378 | } |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 379 | #endif /* CONFIG_OF_LIBFDT */ |
Marian Balakowicz | 751b2b8 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 380 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 381 | debug ("## Transferring control to Linux (at address %08lx) ...\n", |
| 382 | (ulong)kernel); |
| 383 | |
| 384 | show_boot_progress (15); |
| 385 | |
| 386 | #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) |
| 387 | unlock_ram_in_cache(); |
| 388 | #endif |
| 389 | |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 390 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 391 | if (of_flat_tree) { /* device tree; boot new style */ |
| 392 | /* |
| 393 | * Linux Kernel Parameters (passing device tree): |
| 394 | * r3: pointer to the fdt, followed by the board info data |
| 395 | * r4: physical pointer to the kernel itself |
| 396 | * r5: NULL |
| 397 | * r6: NULL |
| 398 | * r7: NULL |
| 399 | */ |
| 400 | (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0); |
| 401 | /* does not return */ |
| 402 | } |
| 403 | #endif |
| 404 | /* |
| 405 | * Linux Kernel Parameters (passing board info data): |
| 406 | * r3: ptr to board info data |
| 407 | * r4: initrd_start or 0 if no initrd |
| 408 | * r5: initrd_end - unused if r4 is 0 |
| 409 | * r6: Start of command line string |
| 410 | * r7: End of command line string |
| 411 | */ |
| 412 | (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); |
| 413 | /* does not return */ |
| 414 | } |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 415 | |
| 416 | #if defined(CONFIG_OF_LIBFDT) |
| 417 | static void fdt_error (const char *msg) |
| 418 | { |
| 419 | puts ("ERROR: "); |
| 420 | puts (msg); |
| 421 | puts (" - must RESET the board to recover.\n"); |
| 422 | } |
| 423 | #endif |