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