wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 26 | #include <image.h> |
| 27 | #include <zlib.h> |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 28 | #include <bzlib.h> |
TsiChungLiew | 890adcb | 2007-10-25 17:14:00 -0500 | [diff] [blame] | 29 | #include <watchdog.h> |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 30 | #include <environment.h> |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 31 | #include <asm/byteorder.h> |
| 32 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 35 | #define PHYSADDR(x) x |
| 36 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 37 | #define LINUX_MAX_ENVS 256 |
| 38 | #define LINUX_MAX_ARGS 256 |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 39 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 40 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 41 | # include <status_led.h> |
| 42 | # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg) |
| 43 | #else |
| 44 | # define SHOW_BOOT_PROGRESS(arg) |
| 45 | #endif |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 46 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 47 | int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 48 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 49 | void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, |
| 50 | int argc, char *argv[], |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 51 | image_header_t *hdr, int verify) |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 52 | { |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 53 | ulong sp; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 54 | |
| 55 | ulong rd_data, rd_len; |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 56 | ulong initrd_high; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 57 | ulong initrd_start, initrd_end; |
| 58 | image_header_t *rd_hdr; |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 59 | int initrd_copy_to_ram = 1; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 60 | |
| 61 | ulong cmd_start, cmd_end; |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 62 | char *cmdline; |
| 63 | char *s; |
| 64 | bd_t *kbd; |
| 65 | void (*kernel) (bd_t *, ulong, ulong, ulong, ulong); |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 66 | |
| 67 | if ((s = getenv("initrd_high")) != NULL) { |
| 68 | /* a value of "no" or a similar string will act like 0, |
| 69 | * turning the "load high" feature off. This is intentional. |
| 70 | */ |
| 71 | initrd_high = simple_strtoul(s, NULL, 16); |
| 72 | if (initrd_high == ~0) |
| 73 | initrd_copy_to_ram = 0; |
| 74 | } else { /* not set, no restrictions to load high */ |
| 75 | initrd_high = ~0; |
| 76 | } |
| 77 | |
| 78 | #ifdef CONFIG_LOGBUFFER |
| 79 | kbd = gd->bd; |
| 80 | /* Prevent initrd from overwriting logbuffer */ |
| 81 | if (initrd_high < (kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD)) |
| 82 | initrd_high = kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD; |
| 83 | debug("## Logbuffer at 0x%08lX ", kbd->bi_memsize - LOGBUFF_LEN); |
| 84 | #endif |
| 85 | |
| 86 | /* |
| 87 | * Booting a (Linux) kernel image |
| 88 | * |
| 89 | * Allocate space for command line and board info - the |
| 90 | * address should be as high as possible within the reach of |
| 91 | * the kernel (see CFG_BOOTMAPSZ settings), but in unused |
| 92 | * memory, which means far enough below the current stack |
| 93 | * pointer. |
| 94 | */ |
| 95 | asm("movel %%a7, %%d0\n" |
| 96 | "movel %%d0, %0\n": "=d"(sp): :"%d0"); |
Stefan Roese | fe9dae6 | 2007-08-18 14:33:02 +0200 | [diff] [blame] | 97 | |
| 98 | debug("## Current stack ends at 0x%08lX ", sp); |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 99 | |
| 100 | sp -= 2048; /* just to be sure */ |
| 101 | if (sp > CFG_BOOTMAPSZ) |
| 102 | sp = CFG_BOOTMAPSZ; |
| 103 | sp &= ~0xF; |
| 104 | |
| 105 | debug("=> set upper limit to 0x%08lX\n", sp); |
| 106 | |
| 107 | cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF); |
| 108 | kbd = (bd_t *) (((ulong) cmdline - sizeof(bd_t)) & ~0xF); |
| 109 | |
| 110 | if ((s = getenv("bootargs")) == NULL) |
| 111 | s = ""; |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 112 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 113 | strcpy(cmdline, s); |
| 114 | |
| 115 | cmd_start = (ulong) & cmdline[0]; |
| 116 | cmd_end = cmd_start + strlen(cmdline); |
| 117 | |
| 118 | *kbd = *(gd->bd); |
| 119 | |
| 120 | #ifdef DEBUG |
| 121 | printf("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end); |
| 122 | |
| 123 | do_bdinfo(NULL, 0, 0, NULL); |
| 124 | #endif |
| 125 | |
| 126 | if ((s = getenv("clocks_in_mhz")) != NULL) { |
| 127 | /* convert all clock information to MHz */ |
| 128 | kbd->bi_intfreq /= 1000000L; |
| 129 | kbd->bi_busfreq /= 1000000L; |
| 130 | } |
| 131 | |
| 132 | kernel = |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 133 | (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Check if there is an initrd image |
| 137 | */ |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 138 | |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 139 | if (argc >= 3) { |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 140 | debug("Not skipping initrd\n"); |
| 141 | SHOW_BOOT_PROGRESS(9); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 142 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 143 | rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16); |
| 144 | printf ("## Loading RAMDisk Image at %08lx ...\n", rd_hdr); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 145 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 146 | if (!image_check_magic (rd_hdr)) { |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 147 | puts("Bad Magic Number\n"); |
| 148 | SHOW_BOOT_PROGRESS(-10); |
| 149 | do_reset(cmdtp, flag, argc, argv); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 152 | if (!image_check_hcrc (rd_hdr)) { |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 153 | puts("Bad Header Checksum\n"); |
| 154 | SHOW_BOOT_PROGRESS(-11); |
| 155 | do_reset(cmdtp, flag, argc, argv); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 156 | } |
| 157 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 158 | SHOW_BOOT_PROGRESS(10); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 159 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 160 | print_image_hdr (rd_hdr); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 161 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 162 | rd_data = image_get_data (rd_hdr); |
| 163 | rd_len = image_get_data_size (rd_hdr); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 164 | |
| 165 | if (verify) { |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 166 | puts(" Verifying Checksum ... "); |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 167 | if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 168 | puts("Bad Data CRC\n"); |
| 169 | SHOW_BOOT_PROGRESS(-12); |
| 170 | do_reset(cmdtp, flag, argc, argv); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 171 | } |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 172 | puts("OK\n"); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 173 | } |
| 174 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 175 | SHOW_BOOT_PROGRESS(11); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 176 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 177 | if (!image_check_os (rd_hdr, IH_OS_LINUX) || |
| 178 | !image_check_arch (rd_hdr, IH_ARCH_M68K) || |
| 179 | !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 180 | puts("No Linux ColdFire Ramdisk Image\n"); |
| 181 | SHOW_BOOT_PROGRESS(-13); |
| 182 | do_reset(cmdtp, flag, argc, argv); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /* |
| 186 | * Now check if we have a multifile image |
| 187 | */ |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 188 | } else if (image_check_type (hdr, IH_TYPE_MULTI)) { |
| 189 | /* |
| 190 | * Get second entry data start address and len |
| 191 | */ |
| 192 | SHOW_BOOT_PROGRESS (13); |
| 193 | image_multi_getimg (hdr, 1, &rd_data, &rd_len); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 194 | } else { |
| 195 | /* |
| 196 | * no initrd image |
| 197 | */ |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 198 | SHOW_BOOT_PROGRESS(14); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 199 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 200 | rd_len = rd_data = 0; |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 203 | if (!rd_data) { |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 204 | debug("No initrd\n"); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 205 | } |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 206 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 207 | if (rd_data) { |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 208 | if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */ |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 209 | initrd_start = rd_data; |
| 210 | initrd_end = initrd_start + rd_len; |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 211 | } else { |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 212 | initrd_start = (ulong) kbd - rd_len; |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 213 | initrd_start &= ~(4096 - 1); /* align on page */ |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 214 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 215 | if (initrd_high) { |
| 216 | ulong nsp; |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 217 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 218 | /* |
| 219 | * the inital ramdisk does not need to be within |
| 220 | * CFG_BOOTMAPSZ as it is not accessed until after |
| 221 | * the mm system is initialised. |
| 222 | * |
| 223 | * do the stack bottom calculation again and see if |
| 224 | * the initrd will fit just below the monitor stack |
| 225 | * bottom without overwriting the area allocated |
| 226 | * above for command line args and board info. |
| 227 | */ |
| 228 | asm("movel %%a7, %%d0\n" |
| 229 | "movel %%d0, %0\n": "=d"(nsp): :"%d0"); |
Stefan Roese | fe9dae6 | 2007-08-18 14:33:02 +0200 | [diff] [blame] | 230 | |
| 231 | nsp -= 2048; /* just to be sure */ |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 232 | nsp &= ~0xF; |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 233 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 234 | if (nsp > initrd_high) /* limit as specified */ |
| 235 | nsp = initrd_high; |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 236 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 237 | nsp -= rd_len; |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 238 | nsp &= ~(4096 - 1); /* align on page */ |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 239 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 240 | if (nsp >= sp) |
| 241 | initrd_start = nsp; |
| 242 | } |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 243 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 244 | SHOW_BOOT_PROGRESS(12); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 245 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 246 | debug |
| 247 | ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n", |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 248 | rd_data, rd_data + rd_len - 1, rd_len, rd_len); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 249 | |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 250 | initrd_end = initrd_start + rd_len; |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 251 | printf(" Loading Ramdisk to %08lx, end %08lx ... ", |
| 252 | initrd_start, initrd_end); |
Marian Balakowicz | f9a67bd | 2008-01-08 18:11:45 +0100 | [diff] [blame] | 253 | |
| 254 | memmove_wd((void *)initrd_start, |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame^] | 255 | (void *)rd_data, rd_len, CHUNKSZ); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 256 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 257 | puts("OK\n"); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 258 | } |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 259 | } else { |
| 260 | initrd_start = 0; |
| 261 | initrd_end = 0; |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 262 | } |
| 263 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 264 | debug("## Transferring control to Linux (at address %08lx) ...\n", |
| 265 | (ulong) kernel); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 266 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 267 | SHOW_BOOT_PROGRESS(15); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 268 | |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 269 | /* |
| 270 | * Linux Kernel Parameters (passing board info data): |
| 271 | * r3: ptr to board info data |
| 272 | * r4: initrd_start or 0 if no initrd |
| 273 | * r5: initrd_end - unused if r4 is 0 |
| 274 | * r6: Start of command line string |
| 275 | * r7: End of command line string |
| 276 | */ |
| 277 | (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); |
| 278 | /* does not return */ |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 279 | } |