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 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 27 | #include <common.h> |
| 28 | #include <watchdog.h> |
| 29 | #include <command.h> |
| 30 | #include <image.h> |
| 31 | #include <malloc.h> |
| 32 | #include <zlib.h> |
| 33 | #include <bzlib.h> |
| 34 | #include <environment.h> |
| 35 | #include <asm/byteorder.h> |
| 36 | |
| 37 | #if defined(CONFIG_OF_LIBFDT) |
| 38 | #include <fdt.h> |
| 39 | #include <libfdt.h> |
| 40 | #include <fdt_support.h> |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 41 | |
| 42 | static void fdt_error (const char *msg); |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 43 | static int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 44 | bootm_headers_t *images, char **of_flat_tree, ulong *of_size); |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 45 | static int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base, |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 46 | cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 47 | char **of_flat_tree, ulong *of_size); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 48 | #endif |
| 49 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 50 | #ifdef CFG_INIT_RAM_LOCK |
| 51 | #include <asm/cache.h> |
| 52 | #endif |
| 53 | |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 54 | #ifndef CFG_FDT_PAD |
| 55 | #define CFG_FDT_PAD 0x3000 |
| 56 | #endif |
| 57 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 58 | DECLARE_GLOBAL_DATA_PTR; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 59 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 60 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 61 | extern ulong get_effective_memsize(void); |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 62 | static ulong get_sp (void); |
Marian Balakowicz | 2efc264 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 63 | static void set_clocks_in_mhz (bd_t *kbd); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 64 | |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 65 | #ifndef CFG_LINUX_LOWMEM_MAX_SIZE |
| 66 | #define CFG_LINUX_LOWMEM_MAX_SIZE (768*1024*1024) |
| 67 | #endif |
| 68 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 69 | void __attribute__((noinline)) |
Marian Balakowicz | 61fde55 | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 70 | do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 71 | bootm_headers_t *images) |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 72 | { |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 73 | ulong sp; |
Marian Balakowicz | 2efc264 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 74 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 75 | ulong initrd_start, initrd_end; |
Kumar Gala | fffb143 | 2008-08-15 08:24:37 -0500 | [diff] [blame^] | 76 | ulong rd_len; |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 77 | ulong size; |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 78 | phys_size_t bootm_size; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 79 | |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 80 | ulong cmd_start, cmd_end, bootmap_base; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 81 | bd_t *kbd; |
Kumar Gala | dcdcfea | 2008-08-15 08:24:31 -0500 | [diff] [blame] | 82 | void (*kernel)(bd_t *, ulong r4, ulong r5, ulong r6, |
| 83 | ulong r7, ulong r8, ulong r9); |
Kumar Gala | 56bdf1d | 2008-02-27 21:51:45 -0600 | [diff] [blame] | 84 | int ret; |
Kumar Gala | a56d7d5 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 85 | ulong of_size = 0; |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 86 | struct lmb *lmb = images->lmb; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 87 | |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 88 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 89 | char *of_flat_tree = NULL; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 90 | #endif |
| 91 | |
Kumar Gala | 93467bc | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 92 | kernel = (void (*)(bd_t *, ulong, ulong, ulong, |
| 93 | ulong, ulong, ulong))images->ep; |
| 94 | |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 95 | bootmap_base = getenv_bootm_low(); |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 96 | bootm_size = getenv_bootm_size(); |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 97 | |
| 98 | #ifdef DEBUG |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 99 | if (((u64)bootmap_base + bootm_size) > |
| 100 | (CFG_SDRAM_BASE + (u64)gd->ram_size)) |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 101 | puts("WARNING: bootm_low + bootm_size exceed total memory\n"); |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 102 | if ((bootmap_base + bootm_size) > get_effective_memsize()) |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 103 | puts("WARNING: bootm_low + bootm_size exceed eff. memory\n"); |
| 104 | #endif |
| 105 | |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 106 | size = min(bootm_size, get_effective_memsize()); |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 107 | size = min(size, CFG_LINUX_LOWMEM_MAX_SIZE); |
| 108 | |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 109 | if (size < bootm_size) { |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 110 | ulong base = bootmap_base + size; |
Andrew Klossner | e4ad454 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 111 | printf("WARNING: adjusting available memory to %lx\n", size); |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 112 | lmb_reserve(lmb, base, bootm_size - size); |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 113 | } |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 114 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 115 | /* |
| 116 | * Booting a (Linux) kernel image |
| 117 | * |
| 118 | * Allocate space for command line and board info - the |
| 119 | * address should be as high as possible within the reach of |
| 120 | * the kernel (see CFG_BOOTMAPSZ settings), but in unused |
| 121 | * memory, which means far enough below the current stack |
| 122 | * pointer. |
| 123 | */ |
Marian Balakowicz | 2efc264 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 124 | sp = get_sp(); |
Kumar Gala | c5bacfd | 2008-02-27 21:51:50 -0600 | [diff] [blame] | 125 | debug ("## Current stack ends at 0x%08lx\n", sp); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 126 | |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 127 | /* adjust sp by 1K to be safe */ |
| 128 | sp -= 1024; |
| 129 | lmb_reserve(lmb, sp, (CFG_SDRAM_BASE + get_effective_memsize() - sp)); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 130 | |
Kumar Gala | a56d7d5 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 131 | #if defined(CONFIG_OF_LIBFDT) |
| 132 | /* find flattened device tree */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 133 | ret = boot_get_fdt (cmdtp, flag, argc, argv, images, &of_flat_tree, &of_size); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 134 | |
| 135 | if (ret) |
| 136 | goto error; |
Kumar Gala | a56d7d5 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 137 | #endif |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 138 | |
Kumar Gala | a56d7d5 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 139 | if (!of_size) { |
| 140 | /* allocate space and init command line */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 141 | ret = boot_get_cmdline (lmb, &cmd_start, &cmd_end, bootmap_base); |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 142 | if (ret) { |
| 143 | puts("ERROR with allocation of cmdline\n"); |
| 144 | goto error; |
| 145 | } |
Kumar Gala | a56d7d5 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 146 | |
| 147 | /* allocate space for kernel copy of board info */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 148 | ret = boot_get_kbd (lmb, &kbd, bootmap_base); |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 149 | if (ret) { |
| 150 | puts("ERROR with allocation of kernel bd\n"); |
| 151 | goto error; |
| 152 | } |
Kumar Gala | a56d7d5 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 153 | set_clocks_in_mhz(kbd); |
| 154 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 155 | |
Kumar Gala | fffb143 | 2008-08-15 08:24:37 -0500 | [diff] [blame^] | 156 | rd_len = images->rd_end - images->rd_start; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 157 | |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 158 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 159 | ret = boot_relocate_fdt (lmb, bootmap_base, |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 160 | cmdtp, flag, argc, argv, &of_flat_tree, &of_size); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 161 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 162 | /* |
| 163 | * Add the chosen node if it doesn't exist, add the env and bd_t |
| 164 | * if the user wants it (the logic is in the subroutines). |
| 165 | */ |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 166 | if (of_size) { |
Kumar Gala | 56bdf1d | 2008-02-27 21:51:45 -0600 | [diff] [blame] | 167 | /* pass in dummy initrd info, we'll fix up later */ |
Kumar Gala | fffb143 | 2008-08-15 08:24:37 -0500 | [diff] [blame^] | 168 | if (fdt_chosen(of_flat_tree, images->rd_start, images->rd_end, 0) < 0) { |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 169 | fdt_error ("/chosen node create failed"); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 170 | goto error; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 171 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 172 | #ifdef CONFIG_OF_BOARD_SETUP |
| 173 | /* Call the board-specific fixup routine */ |
| 174 | ft_board_setup(of_flat_tree, gd->bd); |
| 175 | #endif |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 176 | } |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 177 | |
| 178 | /* Fixup the fdt memreserve now that we know how big it is */ |
| 179 | if (of_flat_tree) { |
| 180 | int j; |
| 181 | uint64_t addr, size; |
| 182 | int total = fdt_num_mem_rsv(of_flat_tree); |
| 183 | uint actualsize; |
| 184 | |
| 185 | for (j = 0; j < total; j++) { |
| 186 | fdt_get_mem_rsv(of_flat_tree, j, &addr, &size); |
Kumar Gala | 3fddff1 | 2008-07-07 09:39:06 -0500 | [diff] [blame] | 187 | if (addr == (uint64_t)(u32)of_flat_tree) { |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 188 | fdt_del_mem_rsv(of_flat_tree, j); |
| 189 | break; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /* Delete the old LMB reservation */ |
Andy Fleming | 09d2a71 | 2008-07-07 14:24:39 -0500 | [diff] [blame] | 194 | lmb_free(lmb, (phys_addr_t)(u32)of_flat_tree, |
| 195 | (phys_size_t)fdt_totalsize(of_flat_tree)); |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 196 | |
| 197 | /* Calculate the actual size of the fdt */ |
| 198 | actualsize = fdt_off_dt_strings(of_flat_tree) + |
| 199 | fdt_size_dt_strings(of_flat_tree); |
| 200 | |
| 201 | /* Make it so the fdt ends on a page boundary */ |
| 202 | actualsize = ALIGN(actualsize, 0x1000); |
| 203 | actualsize = actualsize - ((uint)of_flat_tree & 0xfff); |
| 204 | |
| 205 | /* Change the fdt header to reflect the correct size */ |
| 206 | fdt_set_totalsize(of_flat_tree, actualsize); |
| 207 | of_size = actualsize; |
| 208 | |
| 209 | /* Add the new reservation */ |
| 210 | ret = fdt_add_mem_rsv(of_flat_tree, (uint)of_flat_tree, |
| 211 | of_size); |
| 212 | |
| 213 | /* Create a new LMB reservation */ |
| 214 | lmb_reserve(lmb, (ulong)of_flat_tree, of_size); |
| 215 | } |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 216 | #endif /* CONFIG_OF_LIBFDT */ |
Marian Balakowicz | 751b2b8 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 217 | |
Kumar Gala | fffb143 | 2008-08-15 08:24:37 -0500 | [diff] [blame^] | 218 | ret = boot_ramdisk_high (lmb, images->rd_start, rd_len, &initrd_start, &initrd_end); |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 219 | if (ret) |
| 220 | goto error; |
Kumar Gala | 56bdf1d | 2008-02-27 21:51:45 -0600 | [diff] [blame] | 221 | |
| 222 | #if defined(CONFIG_OF_LIBFDT) |
| 223 | /* fixup the initrd now that we know where it should be */ |
| 224 | if ((of_flat_tree) && (initrd_start && initrd_end)) { |
| 225 | uint64_t addr, size; |
| 226 | int total = fdt_num_mem_rsv(of_flat_tree); |
| 227 | int j; |
| 228 | |
| 229 | /* Look for the dummy entry and delete it */ |
| 230 | for (j = 0; j < total; j++) { |
| 231 | fdt_get_mem_rsv(of_flat_tree, j, &addr, &size); |
Kumar Gala | fffb143 | 2008-08-15 08:24:37 -0500 | [diff] [blame^] | 232 | if (addr == images->rd_start) { |
Kumar Gala | 56bdf1d | 2008-02-27 21:51:45 -0600 | [diff] [blame] | 233 | fdt_del_mem_rsv(of_flat_tree, j); |
| 234 | break; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | ret = fdt_add_mem_rsv(of_flat_tree, initrd_start, |
| 239 | initrd_end - initrd_start + 1); |
| 240 | if (ret < 0) { |
| 241 | printf("fdt_chosen: %s\n", fdt_strerror(ret)); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 242 | goto error; |
Kumar Gala | 56bdf1d | 2008-02-27 21:51:45 -0600 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | do_fixup_by_path_u32(of_flat_tree, "/chosen", |
| 246 | "linux,initrd-start", initrd_start, 0); |
| 247 | do_fixup_by_path_u32(of_flat_tree, "/chosen", |
| 248 | "linux,initrd-end", initrd_end, 0); |
| 249 | } |
| 250 | #endif |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 251 | debug ("## Transferring control to Linux (at address %08lx) ...\n", |
| 252 | (ulong)kernel); |
| 253 | |
| 254 | show_boot_progress (15); |
| 255 | |
| 256 | #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) |
| 257 | unlock_ram_in_cache(); |
| 258 | #endif |
| 259 | |
Marian Balakowicz | d216085 | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 260 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 261 | if (of_flat_tree) { /* device tree; boot new style */ |
| 262 | /* |
| 263 | * Linux Kernel Parameters (passing device tree): |
Kumar Gala | dcdcfea | 2008-08-15 08:24:31 -0500 | [diff] [blame] | 264 | * r3: pointer to the fdt |
| 265 | * r4: 0 |
| 266 | * r5: 0 |
| 267 | * r6: epapr magic |
| 268 | * r7: size of IMA in bytes |
| 269 | * r8: 0 |
| 270 | * r9: 0 |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 271 | */ |
Kumar Gala | dcdcfea | 2008-08-15 08:24:31 -0500 | [diff] [blame] | 272 | #if defined(CONFIG_85xx) || defined(CONFIG_440) |
| 273 | #define EPAPR_MAGIC (0x45504150) |
| 274 | #else |
| 275 | #define EPAPR_MAGIC (0x65504150) |
| 276 | #endif |
| 277 | |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 278 | debug (" Booting using OF flat tree...\n"); |
Kumar Gala | dcdcfea | 2008-08-15 08:24:31 -0500 | [diff] [blame] | 279 | (*kernel) ((bd_t *)of_flat_tree, 0, 0, EPAPR_MAGIC, |
| 280 | CFG_BOOTMAPSZ, 0, 0); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 281 | /* does not return */ |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 282 | } else |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 283 | #endif |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 284 | { |
| 285 | /* |
| 286 | * Linux Kernel Parameters (passing board info data): |
| 287 | * r3: ptr to board info data |
| 288 | * r4: initrd_start or 0 if no initrd |
| 289 | * r5: initrd_end - unused if r4 is 0 |
| 290 | * r6: Start of command line string |
| 291 | * r7: End of command line string |
Kumar Gala | dcdcfea | 2008-08-15 08:24:31 -0500 | [diff] [blame] | 292 | * r8: 0 |
| 293 | * r9: 0 |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 294 | */ |
| 295 | debug (" Booting using board info...\n"); |
Kumar Gala | dcdcfea | 2008-08-15 08:24:31 -0500 | [diff] [blame] | 296 | (*kernel) (kbd, initrd_start, initrd_end, |
| 297 | cmd_start, cmd_end, 0, 0); |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 298 | /* does not return */ |
| 299 | } |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 300 | return ; |
| 301 | |
| 302 | error: |
Kumar Gala | 026e4ac | 2008-08-11 09:20:53 -0500 | [diff] [blame] | 303 | do_reset (cmdtp, flag, argc, argv); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 304 | return ; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 305 | } |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 306 | |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 307 | static ulong get_sp (void) |
| 308 | { |
| 309 | ulong sp; |
| 310 | |
| 311 | asm( "mr %0,1": "=r"(sp) : ); |
| 312 | return sp; |
| 313 | } |
| 314 | |
Marian Balakowicz | 2efc264 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 315 | static void set_clocks_in_mhz (bd_t *kbd) |
| 316 | { |
| 317 | char *s; |
| 318 | |
| 319 | if ((s = getenv ("clocks_in_mhz")) != NULL) { |
| 320 | /* convert all clock information to MHz */ |
| 321 | kbd->bi_intfreq /= 1000000L; |
| 322 | kbd->bi_busfreq /= 1000000L; |
| 323 | #if defined(CONFIG_MPC8220) |
| 324 | kbd->bi_inpfreq /= 1000000L; |
| 325 | kbd->bi_pcifreq /= 1000000L; |
| 326 | kbd->bi_pevfreq /= 1000000L; |
| 327 | kbd->bi_flbfreq /= 1000000L; |
| 328 | kbd->bi_vcofreq /= 1000000L; |
| 329 | #endif |
| 330 | #if defined(CONFIG_CPM2) |
| 331 | kbd->bi_cpmfreq /= 1000000L; |
| 332 | kbd->bi_brgfreq /= 1000000L; |
| 333 | kbd->bi_sccfreq /= 1000000L; |
Wolfgang Denk | 8f702ad | 2008-03-26 11:48:46 +0100 | [diff] [blame] | 334 | kbd->bi_vco /= 1000000L; |
Marian Balakowicz | 2efc264 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 335 | #endif |
| 336 | #if defined(CONFIG_MPC5xxx) |
| 337 | kbd->bi_ipbfreq /= 1000000L; |
| 338 | kbd->bi_pcifreq /= 1000000L; |
| 339 | #endif /* CONFIG_MPC5xxx */ |
| 340 | } |
| 341 | } |
| 342 | |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 343 | #if defined(CONFIG_OF_LIBFDT) |
| 344 | static void fdt_error (const char *msg) |
| 345 | { |
| 346 | puts ("ERROR: "); |
| 347 | puts (msg); |
| 348 | puts (" - must RESET the board to recover.\n"); |
| 349 | } |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 350 | |
Marian Balakowicz | 351d3e3 | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 351 | static image_header_t *image_get_fdt (ulong fdt_addr) |
| 352 | { |
| 353 | image_header_t *fdt_hdr = (image_header_t *)fdt_addr; |
| 354 | |
| 355 | image_print_contents (fdt_hdr); |
| 356 | |
| 357 | puts (" Verifying Checksum ... "); |
| 358 | if (!image_check_hcrc (fdt_hdr)) { |
| 359 | fdt_error ("fdt header checksum invalid"); |
| 360 | return NULL; |
| 361 | } |
| 362 | |
| 363 | if (!image_check_dcrc (fdt_hdr)) { |
| 364 | fdt_error ("fdt checksum invalid"); |
| 365 | return NULL; |
| 366 | } |
| 367 | puts ("OK\n"); |
| 368 | |
| 369 | if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) { |
| 370 | fdt_error ("uImage is not a fdt"); |
| 371 | return NULL; |
| 372 | } |
| 373 | if (image_get_comp (fdt_hdr) != IH_COMP_NONE) { |
| 374 | fdt_error ("uImage is compressed"); |
| 375 | return NULL; |
| 376 | } |
| 377 | if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) { |
| 378 | fdt_error ("uImage data is not a fdt"); |
| 379 | return NULL; |
| 380 | } |
| 381 | return fdt_hdr; |
| 382 | } |
| 383 | |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 384 | /** |
| 385 | * fit_check_fdt - verify FIT format FDT subimage |
| 386 | * @fit_hdr: pointer to the FIT header |
| 387 | * fdt_noffset: FDT subimage node offset within FIT image |
| 388 | * @verify: data CRC verification flag |
| 389 | * |
| 390 | * fit_check_fdt() verifies integrity of the FDT subimage and from |
| 391 | * specified FIT image. |
| 392 | * |
| 393 | * returns: |
| 394 | * 1, on success |
| 395 | * 0, on failure |
| 396 | */ |
| 397 | #if defined(CONFIG_FIT) |
| 398 | static int fit_check_fdt (const void *fit, int fdt_noffset, int verify) |
| 399 | { |
| 400 | fit_image_print (fit, fdt_noffset, " "); |
| 401 | |
| 402 | if (verify) { |
| 403 | puts (" Verifying Hash Integrity ... "); |
| 404 | if (!fit_image_check_hashes (fit, fdt_noffset)) { |
| 405 | fdt_error ("Bad Data Hash"); |
| 406 | return 0; |
| 407 | } |
| 408 | puts ("OK\n"); |
| 409 | } |
| 410 | |
| 411 | if (!fit_image_check_type (fit, fdt_noffset, IH_TYPE_FLATDT)) { |
| 412 | fdt_error ("Not a FDT image"); |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | if (!fit_image_check_comp (fit, fdt_noffset, IH_COMP_NONE)) { |
| 417 | fdt_error ("FDT image is compressed"); |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | return 1; |
| 422 | } |
| 423 | #endif /* CONFIG_FIT */ |
| 424 | |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 425 | static int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 426 | bootm_headers_t *images, char **of_flat_tree, ulong *of_size) |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 427 | { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 428 | ulong fdt_addr; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 429 | image_header_t *fdt_hdr; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 430 | char *fdt_blob = NULL; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 431 | ulong image_start, image_end; |
| 432 | ulong load_start, load_end; |
| 433 | #if defined(CONFIG_FIT) |
Wolfgang Denk | 8f702ad | 2008-03-26 11:48:46 +0100 | [diff] [blame] | 434 | void *fit_hdr; |
| 435 | const char *fit_uname_config = NULL; |
| 436 | const char *fit_uname_fdt = NULL; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 437 | ulong default_addr; |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 438 | int cfg_noffset; |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 439 | int fdt_noffset; |
| 440 | const void *data; |
| 441 | size_t size; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 442 | #endif |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 443 | |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 444 | *of_flat_tree = NULL; |
| 445 | *of_size = 0; |
| 446 | |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 447 | if (argc > 3 || genimg_has_config (images)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 448 | #if defined(CONFIG_FIT) |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 449 | if (argc > 3) { |
| 450 | /* |
| 451 | * If the FDT blob comes from the FIT image and the |
| 452 | * FIT image address is omitted in the command line |
| 453 | * argument, try to use ramdisk or os FIT image |
| 454 | * address or default load address. |
| 455 | */ |
| 456 | if (images->fit_uname_rd) |
| 457 | default_addr = (ulong)images->fit_hdr_rd; |
| 458 | else if (images->fit_uname_os) |
| 459 | default_addr = (ulong)images->fit_hdr_os; |
| 460 | else |
| 461 | default_addr = load_addr; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 462 | |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 463 | if (fit_parse_conf (argv[3], default_addr, |
| 464 | &fdt_addr, &fit_uname_config)) { |
| 465 | debug ("* fdt: config '%s' from image at 0x%08lx\n", |
| 466 | fit_uname_config, fdt_addr); |
| 467 | } else if (fit_parse_subimage (argv[3], default_addr, |
| 468 | &fdt_addr, &fit_uname_fdt)) { |
| 469 | debug ("* fdt: subimage '%s' from image at 0x%08lx\n", |
| 470 | fit_uname_fdt, fdt_addr); |
| 471 | } else |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 472 | #endif |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 473 | { |
| 474 | fdt_addr = simple_strtoul(argv[3], NULL, 16); |
| 475 | debug ("* fdt: cmdline image address = 0x%08lx\n", |
| 476 | fdt_addr); |
| 477 | } |
| 478 | #if defined(CONFIG_FIT) |
| 479 | } else { |
| 480 | /* use FIT configuration provided in first bootm |
| 481 | * command argument |
| 482 | */ |
| 483 | fdt_addr = (ulong)images->fit_hdr_os; |
| 484 | fit_uname_config = images->fit_uname_cfg; |
| 485 | debug ("* fdt: using config '%s' from image at 0x%08lx\n", |
| 486 | fit_uname_config, fdt_addr); |
| 487 | |
| 488 | /* |
| 489 | * Check whether configuration has FDT blob defined, |
| 490 | * if not quit silently. |
| 491 | */ |
| 492 | fit_hdr = (void *)fdt_addr; |
| 493 | cfg_noffset = fit_conf_get_node (fit_hdr, |
| 494 | fit_uname_config); |
| 495 | if (cfg_noffset < 0) { |
| 496 | debug ("* fdt: no such config\n"); |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | fdt_noffset = fit_conf_get_fdt_node (fit_hdr, |
| 501 | cfg_noffset); |
| 502 | if (fdt_noffset < 0) { |
| 503 | debug ("* fdt: no fdt in config\n"); |
| 504 | return 0; |
| 505 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 506 | } |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 507 | #endif |
Marian Balakowicz | c536d6f | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 508 | |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 509 | debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n", |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 510 | fdt_addr); |
Marian Balakowicz | c536d6f | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 511 | |
| 512 | /* copy from dataflash if needed */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 513 | fdt_addr = genimg_get_image (fdt_addr); |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 514 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 515 | /* |
| 516 | * Check if there is an FDT image at the |
| 517 | * address provided in the second bootm argument |
| 518 | * check image type, for FIT images get a FIT node. |
| 519 | */ |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 520 | switch (genimg_get_format ((void *)fdt_addr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 521 | case IMAGE_FORMAT_LEGACY: |
Marian Balakowicz | 351d3e3 | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 522 | /* verify fdt_addr points to a valid image header */ |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 523 | printf ("## Flattened Device Tree from Legacy Image at %08lx\n", |
Marian Balakowicz | 351d3e3 | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 524 | fdt_addr); |
| 525 | fdt_hdr = image_get_fdt (fdt_addr); |
| 526 | if (!fdt_hdr) |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 527 | goto error; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 528 | |
Marian Balakowicz | 351d3e3 | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 529 | /* |
| 530 | * move image data to the load address, |
| 531 | * make sure we don't overwrite initial image |
| 532 | */ |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 533 | image_start = (ulong)fdt_hdr; |
| 534 | image_end = image_get_image_end (fdt_hdr); |
| 535 | |
| 536 | load_start = image_get_load (fdt_hdr); |
| 537 | load_end = load_start + image_get_data_size (fdt_hdr); |
| 538 | |
| 539 | if ((load_start < image_end) && (load_end > image_start)) { |
| 540 | fdt_error ("fdt overwritten"); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 541 | goto error; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 542 | } |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 543 | |
| 544 | debug (" Loading FDT from 0x%08lx to 0x%08lx\n", |
| 545 | image_get_data (fdt_hdr), load_start); |
| 546 | |
| 547 | memmove ((void *)load_start, |
Marian Balakowicz | 351d3e3 | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 548 | (void *)image_get_data (fdt_hdr), |
| 549 | image_get_data_size (fdt_hdr)); |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 550 | |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 551 | fdt_blob = (char *)load_start; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 552 | break; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 553 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | 1256068 | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 554 | /* |
| 555 | * This case will catch both: new uImage format |
| 556 | * (libfdt based) and raw FDT blob (also libfdt |
| 557 | * based). |
| 558 | */ |
| 559 | #if defined(CONFIG_FIT) |
| 560 | /* check FDT blob vs FIT blob */ |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 561 | if (fit_check_format ((const void *)fdt_addr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 562 | /* |
| 563 | * FIT image |
| 564 | */ |
| 565 | fit_hdr = (void *)fdt_addr; |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 566 | printf ("## Flattened Device Tree from FIT Image at %08lx\n", |
| 567 | fdt_addr); |
| 568 | |
| 569 | if (!fit_uname_fdt) { |
| 570 | /* |
| 571 | * no FDT blob image node unit name, |
| 572 | * try to get config node first. If |
| 573 | * config unit node name is NULL |
| 574 | * fit_conf_get_node() will try to |
| 575 | * find default config node |
| 576 | */ |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 577 | cfg_noffset = fit_conf_get_node (fit_hdr, |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 578 | fit_uname_config); |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 579 | |
| 580 | if (cfg_noffset < 0) { |
| 581 | fdt_error ("Could not find configuration node\n"); |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 582 | goto error; |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | fit_uname_config = fdt_get_name (fit_hdr, |
| 586 | cfg_noffset, NULL); |
| 587 | printf (" Using '%s' configuration\n", |
| 588 | fit_uname_config); |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 589 | |
| 590 | fdt_noffset = fit_conf_get_fdt_node (fit_hdr, |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 591 | cfg_noffset); |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 592 | fit_uname_fdt = fit_get_name (fit_hdr, |
| 593 | fdt_noffset, NULL); |
| 594 | } else { |
| 595 | /* get FDT component image node offset */ |
| 596 | fdt_noffset = fit_image_get_node (fit_hdr, |
| 597 | fit_uname_fdt); |
| 598 | } |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 599 | if (fdt_noffset < 0) { |
| 600 | fdt_error ("Could not find subimage node\n"); |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 601 | goto error; |
Marian Balakowicz | 0cd4f3d | 2008-03-12 10:35:46 +0100 | [diff] [blame] | 602 | } |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 603 | |
| 604 | printf (" Trying '%s' FDT blob subimage\n", |
| 605 | fit_uname_fdt); |
| 606 | |
| 607 | if (!fit_check_fdt (fit_hdr, fdt_noffset, |
| 608 | images->verify)) |
| 609 | goto error; |
| 610 | |
| 611 | /* get ramdisk image data address and length */ |
| 612 | if (fit_image_get_data (fit_hdr, fdt_noffset, |
| 613 | &data, &size)) { |
| 614 | fdt_error ("Could not find FDT subimage data"); |
| 615 | goto error; |
| 616 | } |
| 617 | |
| 618 | /* verift that image data is a proper FDT blob */ |
| 619 | if (fdt_check_header ((char *)data) != 0) { |
| 620 | fdt_error ("Subimage data is not a FTD"); |
| 621 | goto error; |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * move image data to the load address, |
| 626 | * make sure we don't overwrite initial image |
| 627 | */ |
| 628 | image_start = (ulong)fit_hdr; |
| 629 | image_end = fit_get_end (fit_hdr); |
| 630 | |
| 631 | if (fit_image_get_load (fit_hdr, fdt_noffset, |
| 632 | &load_start) == 0) { |
| 633 | load_end = load_start + size; |
| 634 | |
| 635 | if ((load_start < image_end) && |
| 636 | (load_end > image_start)) { |
| 637 | fdt_error ("FDT overwritten"); |
| 638 | goto error; |
| 639 | } |
| 640 | |
| 641 | printf (" Loading FDT from 0x%08lx to 0x%08lx\n", |
| 642 | (ulong)data, load_start); |
| 643 | |
| 644 | memmove ((void *)load_start, |
| 645 | (void *)data, size); |
| 646 | |
| 647 | fdt_blob = (char *)load_start; |
| 648 | } else { |
| 649 | fdt_blob = (char *)data; |
| 650 | } |
| 651 | |
| 652 | images->fit_hdr_fdt = fit_hdr; |
| 653 | images->fit_uname_fdt = fit_uname_fdt; |
Marian Balakowicz | 61c1ad5 | 2008-03-12 10:32:59 +0100 | [diff] [blame] | 654 | images->fit_noffset_fdt = fdt_noffset; |
Marian Balakowicz | 0d87136 | 2008-03-12 10:32:53 +0100 | [diff] [blame] | 655 | break; |
Marian Balakowicz | 1256068 | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 656 | } else |
| 657 | #endif |
| 658 | { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 659 | /* |
| 660 | * FDT blob |
| 661 | */ |
Marian Balakowicz | e5d63b7 | 2008-04-11 11:07:43 +0200 | [diff] [blame] | 662 | fdt_blob = (char *)fdt_addr; |
Marian Balakowicz | 1256068 | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 663 | debug ("* fdt: raw FDT blob\n"); |
Andrew Klossner | e4ad454 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 664 | printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 665 | } |
| 666 | break; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 667 | default: |
| 668 | fdt_error ("Did not find a cmdline Flattened Device Tree"); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 669 | goto error; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 670 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 671 | |
Andrew Klossner | e4ad454 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 672 | printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 673 | |
| 674 | } else if (images->legacy_hdr_valid && |
Marian Balakowicz | ab00e02 | 2008-04-11 11:07:49 +0200 | [diff] [blame] | 675 | image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 676 | |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 677 | ulong fdt_data, fdt_len; |
| 678 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 679 | /* |
| 680 | * Now check if we have a legacy multi-component image, |
| 681 | * get second entry data start address and len. |
| 682 | */ |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 683 | printf ("## Flattened Device Tree from multi " |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 684 | "component Image at %08lX\n", |
| 685 | (ulong)images->legacy_hdr_os); |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 686 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 687 | image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len); |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 688 | if (fdt_len) { |
| 689 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 690 | fdt_blob = (char *)fdt_data; |
Andrew Klossner | e4ad454 | 2008-07-07 06:41:14 -0700 | [diff] [blame] | 691 | printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob); |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 692 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 693 | if (fdt_check_header (fdt_blob) != 0) { |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 694 | fdt_error ("image is not a fdt"); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 695 | goto error; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 696 | } |
| 697 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 698 | if (be32_to_cpu (fdt_totalsize (fdt_blob)) != fdt_len) { |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 699 | fdt_error ("fdt size != image size"); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 700 | goto error; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 701 | } |
| 702 | } else { |
Nick Spence | 5bcd410 | 2008-05-08 22:32:22 -0700 | [diff] [blame] | 703 | debug ("## No Flattened Device Tree\n"); |
| 704 | return 0; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 705 | } |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 706 | } else { |
| 707 | debug ("## No Flattened Device Tree\n"); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 708 | return 0; |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | *of_flat_tree = fdt_blob; |
| 712 | *of_size = be32_to_cpu (fdt_totalsize (fdt_blob)); |
| 713 | debug (" of_flat_tree at 0x%08lx size 0x%08lx\n", |
| 714 | *of_flat_tree, *of_size); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 715 | |
| 716 | return 0; |
| 717 | |
| 718 | error: |
| 719 | do_reset (cmdtp, flag, argc, argv); |
| 720 | return 1; |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 721 | } |
| 722 | |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 723 | static int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base, |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 724 | cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 725 | char **of_flat_tree, ulong *of_size) |
| 726 | { |
| 727 | char *fdt_blob = *of_flat_tree; |
| 728 | ulong relocate = 0; |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 729 | ulong of_len = 0; |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 730 | |
| 731 | /* nothing to do */ |
| 732 | if (*of_size == 0) |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 733 | return 0; |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 734 | |
| 735 | if (fdt_check_header (fdt_blob) != 0) { |
| 736 | fdt_error ("image is not a fdt"); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 737 | goto error; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 738 | } |
| 739 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 740 | #ifndef CFG_NO_FLASH |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 741 | /* move the blob if it is in flash (set relocate) */ |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 742 | if (addr2info ((ulong)fdt_blob) != NULL) |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 743 | relocate = 1; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 744 | #endif |
| 745 | |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 746 | /* |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 747 | * The blob needs to be inside the boot mapping. |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 748 | */ |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 749 | if (fdt_blob < (char *)bootmap_base) |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 750 | relocate = 1; |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 751 | |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 752 | if ((fdt_blob + *of_size + CFG_FDT_PAD) >= |
| 753 | ((char *)CFG_BOOTMAPSZ + bootmap_base)) |
| 754 | relocate = 1; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 755 | |
| 756 | /* move flattend device tree if needed */ |
Marian Balakowicz | 6881dae | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 757 | if (relocate) { |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 758 | int err; |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 759 | ulong of_start = 0; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 760 | |
| 761 | /* position on a 4K boundary before the alloc_current */ |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 762 | /* Pad the FDT by a specified amount */ |
| 763 | of_len = *of_size + CFG_FDT_PAD; |
Becky Bruce | d26d67c | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 764 | of_start = (unsigned long)lmb_alloc_base(lmb, of_len, 0x1000, |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 765 | (CFG_BOOTMAPSZ + bootmap_base)); |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 766 | |
| 767 | if (of_start == 0) { |
| 768 | puts("device tree - allocation error\n"); |
| 769 | goto error; |
| 770 | } |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 771 | |
| 772 | debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 773 | (ulong)fdt_blob, (ulong)fdt_blob + *of_size - 1, |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 774 | of_len, of_len); |
| 775 | |
| 776 | printf (" Loading Device Tree to %08lx, end %08lx ... ", |
| 777 | of_start, of_start + of_len - 1); |
| 778 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 779 | err = fdt_open_into (fdt_blob, (void *)of_start, of_len); |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 780 | if (err != 0) { |
| 781 | fdt_error ("fdt move failed"); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 782 | goto error; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 783 | } |
| 784 | puts ("OK\n"); |
| 785 | |
| 786 | *of_flat_tree = (char *)of_start; |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 787 | *of_size = of_len; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 788 | } else { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 789 | *of_flat_tree = fdt_blob; |
Andy Fleming | 7d32ae3 | 2008-06-16 13:58:56 -0500 | [diff] [blame] | 790 | of_len = (CFG_BOOTMAPSZ + bootmap_base) - (ulong)fdt_blob; |
| 791 | lmb_reserve(lmb, (ulong)fdt_blob, of_len); |
| 792 | fdt_set_totalsize(*of_flat_tree, of_len); |
| 793 | |
| 794 | *of_size = of_len; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 795 | } |
| 796 | |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 797 | return 0; |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 798 | |
| 799 | error: |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 800 | return 1; |
Marian Balakowicz | 25154b6 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 801 | } |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 802 | #endif |