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 | #define DEBUG |
| 27 | |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 28 | #include <common.h> |
| 29 | #include <watchdog.h> |
| 30 | #include <command.h> |
| 31 | #include <image.h> |
| 32 | #include <malloc.h> |
| 33 | #include <zlib.h> |
| 34 | #include <bzlib.h> |
| 35 | #include <environment.h> |
| 36 | #include <asm/byteorder.h> |
| 37 | |
| 38 | #if defined(CONFIG_OF_LIBFDT) |
| 39 | #include <fdt.h> |
| 40 | #include <libfdt.h> |
| 41 | #include <fdt_support.h> |
Marian Balakowicz | d3c5eb6 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 42 | |
| 43 | static void fdt_error (const char *msg); |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 44 | static void get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 45 | bootm_headers_t *images, char **of_flat_tree, ulong *of_size); |
| 46 | static ulong fdt_relocate (ulong alloc_current, |
| 47 | cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 48 | char **of_flat_tree, ulong *of_size); |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 49 | #endif |
| 50 | |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 51 | #ifdef CFG_INIT_RAM_LOCK |
| 52 | #include <asm/cache.h> |
| 53 | #endif |
| 54 | |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 55 | DECLARE_GLOBAL_DATA_PTR; |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 56 | |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 57 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
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 | |
| 61 | void __attribute__((noinline)) |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 62 | do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 63 | bootm_headers_t *images) |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 64 | { |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 65 | ulong sp, sp_limit, alloc_current; |
| 66 | |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 67 | ulong initrd_start, initrd_end; |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 68 | ulong rd_data_start, rd_data_end, rd_len; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 69 | |
| 70 | ulong cmd_start, cmd_end; |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 71 | bd_t *kbd; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 72 | ulong ep = 0; |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 73 | void (*kernel)(bd_t *, ulong, ulong, ulong, ulong); |
Kumar Gala | d2bc095 | 2008-02-27 21:51:45 -0600 | [diff] [blame^] | 74 | int ret; |
Kumar Gala | 2795349 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 75 | ulong of_size = 0; |
Marian Balakowicz | f13e7b2 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 76 | |
Marian Balakowicz | 4a2ad5f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 77 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 78 | char *of_flat_tree = NULL; |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 79 | #endif |
| 80 | |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 81 | /* |
| 82 | * Booting a (Linux) kernel image |
| 83 | * |
| 84 | * Allocate space for command line and board info - the |
| 85 | * address should be as high as possible within the reach of |
| 86 | * the kernel (see CFG_BOOTMAPSZ settings), but in unused |
| 87 | * memory, which means far enough below the current stack |
| 88 | * pointer. |
| 89 | */ |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 90 | sp = get_sp(); |
| 91 | debug ("## Current stack ends at 0x%08lx ", sp); |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 92 | |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 93 | alloc_current = sp_limit = get_boot_sp_limit(sp); |
| 94 | debug ("=> set upper limit to 0x%08lx\n", sp_limit); |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 95 | |
Kumar Gala | 2795349 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 96 | #if defined(CONFIG_OF_LIBFDT) |
| 97 | /* find flattened device tree */ |
| 98 | get_fdt (cmdtp, flag, argc, argv, images, &of_flat_tree, &of_size); |
| 99 | #endif |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 100 | |
Kumar Gala | 2795349 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 101 | if (!of_size) { |
| 102 | /* allocate space and init command line */ |
| 103 | alloc_current = get_boot_cmdline (alloc_current, &cmd_start, &cmd_end); |
| 104 | |
| 105 | /* allocate space for kernel copy of board info */ |
| 106 | alloc_current = get_boot_kbd (alloc_current, &kbd); |
| 107 | set_clocks_in_mhz(kbd); |
| 108 | } |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 109 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 110 | /* find kernel entry point */ |
| 111 | if (images->legacy_hdr_valid) { |
| 112 | ep = image_get_ep (images->legacy_hdr_os); |
| 113 | #if defined(CONFIG_FIT) |
| 114 | } else if (images->fit_uname_os) { |
| 115 | fit_unsupported_reset ("PPC linux bootm"); |
| 116 | do_reset (cmdtp, flag, argc, argv); |
| 117 | #endif |
| 118 | } else { |
| 119 | puts ("Could not find kernel entry point!\n"); |
| 120 | do_reset (cmdtp, flag, argc, argv); |
| 121 | } |
| 122 | kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep; |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 123 | |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 124 | /* find ramdisk */ |
Marian Balakowicz | 8a5ea3e | 2008-02-27 11:01:04 +0100 | [diff] [blame] | 125 | get_ramdisk (cmdtp, flag, argc, argv, images, |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 126 | IH_ARCH_PPC, &rd_data_start, &rd_data_end); |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 127 | |
Marian Balakowicz | 5ad03eb | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 128 | rd_len = rd_data_end - rd_data_start; |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 129 | |
Marian Balakowicz | 4a2ad5f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 130 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 131 | alloc_current = fdt_relocate (alloc_current, |
| 132 | cmdtp, flag, argc, argv, &of_flat_tree, &of_size); |
Marian Balakowicz | 4a2ad5f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 133 | |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 134 | /* |
| 135 | * Add the chosen node if it doesn't exist, add the env and bd_t |
| 136 | * if the user wants it (the logic is in the subroutines). |
| 137 | */ |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 138 | if (of_size) { |
Kumar Gala | d2bc095 | 2008-02-27 21:51:45 -0600 | [diff] [blame^] | 139 | /* pass in dummy initrd info, we'll fix up later */ |
| 140 | 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] | 141 | fdt_error ("/chosen node create failed"); |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 142 | do_reset (cmdtp, flag, argc, argv); |
| 143 | } |
| 144 | #ifdef CONFIG_OF_HAS_UBOOT_ENV |
| 145 | if (fdt_env(of_flat_tree) < 0) { |
Marian Balakowicz | d3c5eb6 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 146 | fdt_error ("/u-boot-env node create failed"); |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 147 | do_reset (cmdtp, flag, argc, argv); |
| 148 | } |
| 149 | #endif |
| 150 | #ifdef CONFIG_OF_HAS_BD_T |
| 151 | if (fdt_bd_t(of_flat_tree) < 0) { |
Marian Balakowicz | d3c5eb6 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 152 | fdt_error ("/bd_t node create failed"); |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 153 | do_reset (cmdtp, flag, argc, argv); |
| 154 | } |
| 155 | #endif |
| 156 | #ifdef CONFIG_OF_BOARD_SETUP |
| 157 | /* Call the board-specific fixup routine */ |
| 158 | ft_board_setup(of_flat_tree, gd->bd); |
| 159 | #endif |
| 160 | } |
Marian Balakowicz | 4a2ad5f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 161 | #endif /* CONFIG_OF_LIBFDT */ |
Marian Balakowicz | d45d5a1 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 162 | |
Kumar Gala | d2bc095 | 2008-02-27 21:51:45 -0600 | [diff] [blame^] | 163 | alloc_current = ramdisk_high (alloc_current, rd_data_start, rd_len, |
| 164 | sp_limit, get_sp (), &initrd_start, &initrd_end); |
| 165 | |
| 166 | #if defined(CONFIG_OF_LIBFDT) |
| 167 | /* fixup the initrd now that we know where it should be */ |
| 168 | if ((of_flat_tree) && (initrd_start && initrd_end)) { |
| 169 | uint64_t addr, size; |
| 170 | int total = fdt_num_mem_rsv(of_flat_tree); |
| 171 | int j; |
| 172 | |
| 173 | /* Look for the dummy entry and delete it */ |
| 174 | for (j = 0; j < total; j++) { |
| 175 | fdt_get_mem_rsv(of_flat_tree, j, &addr, &size); |
| 176 | if (addr == rd_data_start) { |
| 177 | fdt_del_mem_rsv(of_flat_tree, j); |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | ret = fdt_add_mem_rsv(of_flat_tree, initrd_start, |
| 183 | initrd_end - initrd_start + 1); |
| 184 | if (ret < 0) { |
| 185 | printf("fdt_chosen: %s\n", fdt_strerror(ret)); |
| 186 | do_reset (cmdtp, flag, argc, argv); |
| 187 | } |
| 188 | |
| 189 | do_fixup_by_path_u32(of_flat_tree, "/chosen", |
| 190 | "linux,initrd-start", initrd_start, 0); |
| 191 | do_fixup_by_path_u32(of_flat_tree, "/chosen", |
| 192 | "linux,initrd-end", initrd_end, 0); |
| 193 | } |
| 194 | #endif |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 195 | debug ("## Transferring control to Linux (at address %08lx) ...\n", |
| 196 | (ulong)kernel); |
| 197 | |
| 198 | show_boot_progress (15); |
| 199 | |
| 200 | #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) |
| 201 | unlock_ram_in_cache(); |
| 202 | #endif |
| 203 | |
Marian Balakowicz | 4a2ad5f | 2008-01-31 13:20:07 +0100 | [diff] [blame] | 204 | #if defined(CONFIG_OF_LIBFDT) |
Marian Balakowicz | 5d3cc55 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 205 | if (of_flat_tree) { /* device tree; boot new style */ |
| 206 | /* |
| 207 | * Linux Kernel Parameters (passing device tree): |
| 208 | * r3: pointer to the fdt, followed by the board info data |
| 209 | * r4: physical pointer to the kernel itself |
| 210 | * r5: NULL |
| 211 | * r6: NULL |
| 212 | * r7: NULL |
| 213 | */ |
| 214 | (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0); |
| 215 | /* does not return */ |
| 216 | } |
| 217 | #endif |
| 218 | /* |
| 219 | * Linux Kernel Parameters (passing board info data): |
| 220 | * r3: ptr to board info data |
| 221 | * r4: initrd_start or 0 if no initrd |
| 222 | * r5: initrd_end - unused if r4 is 0 |
| 223 | * r6: Start of command line string |
| 224 | * r7: End of command line string |
| 225 | */ |
| 226 | (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); |
| 227 | /* does not return */ |
| 228 | } |
Marian Balakowicz | d3c5eb6 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 229 | |
Marian Balakowicz | ceaed2b | 2008-01-31 13:57:17 +0100 | [diff] [blame] | 230 | static ulong get_sp (void) |
| 231 | { |
| 232 | ulong sp; |
| 233 | |
| 234 | asm( "mr %0,1": "=r"(sp) : ); |
| 235 | return sp; |
| 236 | } |
| 237 | |
Marian Balakowicz | b6b0fe6 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 238 | static void set_clocks_in_mhz (bd_t *kbd) |
| 239 | { |
| 240 | char *s; |
| 241 | |
| 242 | if ((s = getenv ("clocks_in_mhz")) != NULL) { |
| 243 | /* convert all clock information to MHz */ |
| 244 | kbd->bi_intfreq /= 1000000L; |
| 245 | kbd->bi_busfreq /= 1000000L; |
| 246 | #if defined(CONFIG_MPC8220) |
| 247 | kbd->bi_inpfreq /= 1000000L; |
| 248 | kbd->bi_pcifreq /= 1000000L; |
| 249 | kbd->bi_pevfreq /= 1000000L; |
| 250 | kbd->bi_flbfreq /= 1000000L; |
| 251 | kbd->bi_vcofreq /= 1000000L; |
| 252 | #endif |
| 253 | #if defined(CONFIG_CPM2) |
| 254 | kbd->bi_cpmfreq /= 1000000L; |
| 255 | kbd->bi_brgfreq /= 1000000L; |
| 256 | kbd->bi_sccfreq /= 1000000L; |
| 257 | kbd->bi_vco /= 1000000L; |
| 258 | #endif |
| 259 | #if defined(CONFIG_MPC5xxx) |
| 260 | kbd->bi_ipbfreq /= 1000000L; |
| 261 | kbd->bi_pcifreq /= 1000000L; |
| 262 | #endif /* CONFIG_MPC5xxx */ |
| 263 | } |
| 264 | } |
| 265 | |
Marian Balakowicz | d3c5eb6 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 266 | #if defined(CONFIG_OF_LIBFDT) |
| 267 | static void fdt_error (const char *msg) |
| 268 | { |
| 269 | puts ("ERROR: "); |
| 270 | puts (msg); |
| 271 | puts (" - must RESET the board to recover.\n"); |
| 272 | } |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 273 | |
Marian Balakowicz | ff0734c | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 274 | static image_header_t *image_get_fdt (ulong fdt_addr) |
| 275 | { |
| 276 | image_header_t *fdt_hdr = (image_header_t *)fdt_addr; |
| 277 | |
| 278 | image_print_contents (fdt_hdr); |
| 279 | |
| 280 | puts (" Verifying Checksum ... "); |
| 281 | if (!image_check_hcrc (fdt_hdr)) { |
| 282 | fdt_error ("fdt header checksum invalid"); |
| 283 | return NULL; |
| 284 | } |
| 285 | |
| 286 | if (!image_check_dcrc (fdt_hdr)) { |
| 287 | fdt_error ("fdt checksum invalid"); |
| 288 | return NULL; |
| 289 | } |
| 290 | puts ("OK\n"); |
| 291 | |
| 292 | if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) { |
| 293 | fdt_error ("uImage is not a fdt"); |
| 294 | return NULL; |
| 295 | } |
| 296 | if (image_get_comp (fdt_hdr) != IH_COMP_NONE) { |
| 297 | fdt_error ("uImage is compressed"); |
| 298 | return NULL; |
| 299 | } |
| 300 | if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) { |
| 301 | fdt_error ("uImage data is not a fdt"); |
| 302 | return NULL; |
| 303 | } |
| 304 | return fdt_hdr; |
| 305 | } |
| 306 | |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 307 | static void get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 308 | bootm_headers_t *images, char **of_flat_tree, ulong *of_size) |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 309 | { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 310 | ulong fdt_addr; |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 311 | image_header_t *fdt_hdr; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 312 | char *fdt_blob = NULL; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 313 | ulong image_start, image_end; |
| 314 | ulong load_start, load_end; |
| 315 | #if defined(CONFIG_FIT) |
| 316 | void *fit_hdr; |
| 317 | const char *fit_uname_config = NULL; |
| 318 | const char *fit_uname_fdt = NULL; |
| 319 | ulong default_addr; |
| 320 | #endif |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 321 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 322 | if (argc > 3) { |
| 323 | #if defined(CONFIG_FIT) |
| 324 | /* |
| 325 | * If the FDT blob comes from the FIT image and the FIT image |
| 326 | * address is omitted in the command line argument, try to use |
| 327 | * ramdisk or os FIT image address or default load address. |
| 328 | */ |
| 329 | if (images->fit_uname_rd) |
| 330 | default_addr = (ulong)images->fit_hdr_rd; |
| 331 | else if (images->fit_uname_os) |
| 332 | default_addr = (ulong)images->fit_hdr_os; |
| 333 | else |
| 334 | default_addr = load_addr; |
Marian Balakowicz | fff888a1 | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 335 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 336 | if (fit_parse_conf (argv[3], default_addr, |
| 337 | &fdt_addr, &fit_uname_config)) { |
| 338 | debug ("* fdt: config '%s' from image at 0x%08lx\n", |
| 339 | fit_uname_config, fdt_addr); |
| 340 | } else if (fit_parse_subimage (argv[3], default_addr, |
| 341 | &fdt_addr, &fit_uname_fdt)) { |
| 342 | debug ("* fdt: subimage '%s' from image at 0x%08lx\n", |
| 343 | fit_uname_fdt, fdt_addr); |
| 344 | } else |
| 345 | #endif |
| 346 | { |
| 347 | fdt_addr = simple_strtoul(argv[3], NULL, 16); |
| 348 | debug ("* fdt: cmdline image address = 0x%08lx\n", |
| 349 | fdt_addr); |
| 350 | } |
| 351 | |
| 352 | debug ("## Checking for 'FDT'/'FDT image' at %08lx\n", |
| 353 | fdt_addr); |
Marian Balakowicz | fff888a1 | 2008-02-21 17:20:19 +0100 | [diff] [blame] | 354 | |
| 355 | /* copy from dataflash if needed */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 356 | fdt_addr = gen_get_image (fdt_addr); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 357 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 358 | /* |
| 359 | * Check if there is an FDT image at the |
| 360 | * address provided in the second bootm argument |
| 361 | * check image type, for FIT images get a FIT node. |
| 362 | */ |
| 363 | switch (gen_image_get_format ((void *)fdt_addr)) { |
| 364 | case IMAGE_FORMAT_LEGACY: |
| 365 | debug ("* fdt: legacy format image\n"); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 366 | |
Marian Balakowicz | ff0734c | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 367 | /* verify fdt_addr points to a valid image header */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 368 | printf ("## Flattened Device Tree Legacy Image at %08lx\n", |
Marian Balakowicz | ff0734c | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 369 | fdt_addr); |
| 370 | fdt_hdr = image_get_fdt (fdt_addr); |
| 371 | if (!fdt_hdr) |
| 372 | do_reset (cmdtp, flag, argc, argv); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 373 | |
Marian Balakowicz | ff0734c | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 374 | /* |
| 375 | * move image data to the load address, |
| 376 | * make sure we don't overwrite initial image |
| 377 | */ |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 378 | image_start = (ulong)fdt_hdr; |
| 379 | image_end = image_get_image_end (fdt_hdr); |
| 380 | |
| 381 | load_start = image_get_load (fdt_hdr); |
| 382 | load_end = load_start + image_get_data_size (fdt_hdr); |
| 383 | |
| 384 | if ((load_start < image_end) && (load_end > image_start)) { |
| 385 | fdt_error ("fdt overwritten"); |
| 386 | do_reset (cmdtp, flag, argc, argv); |
| 387 | } |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 388 | memmove ((void *)image_get_load (fdt_hdr), |
Marian Balakowicz | ff0734c | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 389 | (void *)image_get_data (fdt_hdr), |
| 390 | image_get_data_size (fdt_hdr)); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 391 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 392 | fdt_blob = (char *)image_get_load (fdt_hdr); |
| 393 | break; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 394 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | 4efbe9d | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 395 | /* |
| 396 | * This case will catch both: new uImage format |
| 397 | * (libfdt based) and raw FDT blob (also libfdt |
| 398 | * based). |
| 399 | */ |
| 400 | #if defined(CONFIG_FIT) |
| 401 | /* check FDT blob vs FIT blob */ |
| 402 | if (0) { /* FIXME: call FIT format verification */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 403 | /* |
| 404 | * FIT image |
| 405 | */ |
| 406 | fit_hdr = (void *)fdt_addr; |
| 407 | debug ("* fdt: FIT format image\n"); |
| 408 | fit_unsupported_reset ("PPC fdt"); |
| 409 | do_reset (cmdtp, flag, argc, argv); |
Marian Balakowicz | 4efbe9d | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 410 | } else |
| 411 | #endif |
| 412 | { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 413 | /* |
| 414 | * FDT blob |
| 415 | */ |
Marian Balakowicz | 4efbe9d | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 416 | debug ("* fdt: raw FDT blob\n"); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 417 | printf ("## Flattened Device Tree blob at %08lx\n", fdt_blob); |
| 418 | fdt_blob = (char *)fdt_addr; |
| 419 | } |
| 420 | break; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 421 | default: |
| 422 | fdt_error ("Did not find a cmdline Flattened Device Tree"); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 423 | do_reset (cmdtp, flag, argc, argv); |
| 424 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 425 | |
| 426 | printf (" Booting using the fdt blob at 0x%x\n", fdt_blob); |
| 427 | |
| 428 | } else if (images->legacy_hdr_valid && |
| 429 | image_check_type (images->legacy_hdr_os, IH_TYPE_MULTI)) { |
| 430 | |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 431 | ulong fdt_data, fdt_len; |
| 432 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 433 | /* |
| 434 | * Now check if we have a legacy multi-component image, |
| 435 | * get second entry data start address and len. |
| 436 | */ |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 437 | printf ("## Flattened Device Tree from multi " |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 438 | "component Image at %08lX\n", |
| 439 | (ulong)images->legacy_hdr_os); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 440 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 441 | image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 442 | if (fdt_len) { |
| 443 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 444 | fdt_blob = (char *)fdt_data; |
| 445 | printf (" Booting using the fdt at 0x%x\n", fdt_blob); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 446 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 447 | if (fdt_check_header (fdt_blob) != 0) { |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 448 | fdt_error ("image is not a fdt"); |
| 449 | do_reset (cmdtp, flag, argc, argv); |
| 450 | } |
| 451 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 452 | if (be32_to_cpu (fdt_totalsize (fdt_blob)) != fdt_len) { |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 453 | fdt_error ("fdt size != image size"); |
| 454 | do_reset (cmdtp, flag, argc, argv); |
| 455 | } |
| 456 | } else { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 457 | fdt_error ("Did not find a Flattened Device Tree " |
| 458 | "in a legacy multi-component image"); |
| 459 | do_reset (cmdtp, flag, argc, argv); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 460 | } |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 461 | } else { |
| 462 | debug ("## No Flattened Device Tree\n"); |
| 463 | *of_flat_tree = NULL; |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 464 | *of_size = 0; |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | *of_flat_tree = fdt_blob; |
| 469 | *of_size = be32_to_cpu (fdt_totalsize (fdt_blob)); |
| 470 | debug (" of_flat_tree at 0x%08lx size 0x%08lx\n", |
| 471 | *of_flat_tree, *of_size); |
| 472 | } |
| 473 | |
| 474 | static ulong fdt_relocate (ulong alloc_current, |
| 475 | cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 476 | char **of_flat_tree, ulong *of_size) |
| 477 | { |
| 478 | char *fdt_blob = *of_flat_tree; |
| 479 | ulong relocate = 0; |
| 480 | ulong new_alloc_current; |
| 481 | |
| 482 | /* nothing to do */ |
| 483 | if (*of_size == 0) |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 484 | return alloc_current; |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 485 | |
| 486 | if (fdt_check_header (fdt_blob) != 0) { |
| 487 | fdt_error ("image is not a fdt"); |
| 488 | do_reset (cmdtp, flag, argc, argv); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 489 | } |
| 490 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 491 | #ifndef CFG_NO_FLASH |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 492 | /* move the blob if it is in flash (set relocate) */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 493 | if (addr2info ((ulong)fdt_blob) != NULL) |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 494 | relocate = 1; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 495 | #endif |
| 496 | |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 497 | #ifdef CFG_BOOTMAPSZ |
| 498 | /* |
| 499 | * The blob must be within CFG_BOOTMAPSZ, |
| 500 | * so we flag it to be copied if it is not. |
| 501 | */ |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 502 | if (fdt_blob >= (char *)CFG_BOOTMAPSZ) |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 503 | relocate = 1; |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 504 | #endif |
| 505 | |
| 506 | /* move flattend device tree if needed */ |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 507 | if (relocate) { |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 508 | int err; |
| 509 | ulong of_start, of_len; |
| 510 | |
Marian Balakowicz | d2ced9e | 2008-02-04 08:28:17 +0100 | [diff] [blame] | 511 | of_len = *of_size; |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 512 | |
| 513 | /* position on a 4K boundary before the alloc_current */ |
| 514 | of_start = alloc_current - of_len; |
| 515 | of_start &= ~(4096 - 1); /* align on page */ |
| 516 | |
| 517 | 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] | 518 | (ulong)fdt_blob, (ulong)fdt_blob + of_len - 1, |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 519 | of_len, of_len); |
| 520 | |
| 521 | printf (" Loading Device Tree to %08lx, end %08lx ... ", |
| 522 | of_start, of_start + of_len - 1); |
| 523 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 524 | err = fdt_open_into (fdt_blob, (void *)of_start, of_len); |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 525 | if (err != 0) { |
| 526 | fdt_error ("fdt move failed"); |
| 527 | do_reset (cmdtp, flag, argc, argv); |
| 528 | } |
| 529 | puts ("OK\n"); |
| 530 | |
| 531 | *of_flat_tree = (char *)of_start; |
| 532 | new_alloc_current = of_start; |
| 533 | } else { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 534 | *of_flat_tree = fdt_blob; |
Marian Balakowicz | 7b32545 | 2008-01-31 13:58:20 +0100 | [diff] [blame] | 535 | new_alloc_current = alloc_current; |
| 536 | } |
| 537 | |
| 538 | return new_alloc_current; |
| 539 | } |
Marian Balakowicz | d3c5eb6 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 540 | #endif |