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