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