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