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 | fc3ca3b6 | 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 | fc3ca3b6 | 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 | fc3ca3b6 | 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 | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 47 | static ulong get_sp (void); |
| 48 | |
TsiChungLiew | fc3ca3b6 | 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 | { |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 53 | ulong sp_limit; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 54 | |
Marian Balakowicz | 9541850 | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 55 | ulong rd_data_start, rd_data_end, rd_len; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 56 | ulong initrd_start, initrd_end; |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 57 | |
| 58 | ulong cmd_start, cmd_end; |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 59 | char *cmdline; |
| 60 | char *s; |
| 61 | bd_t *kbd; |
| 62 | void (*kernel) (bd_t *, ulong, ulong, ulong, ulong); |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 63 | |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 64 | /* |
| 65 | * Booting a (Linux) kernel image |
| 66 | * |
| 67 | * Allocate space for command line and board info - the |
| 68 | * address should be as high as possible within the reach of |
| 69 | * the kernel (see CFG_BOOTMAPSZ settings), but in unused |
| 70 | * memory, which means far enough below the current stack |
| 71 | * pointer. |
| 72 | */ |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 73 | sp_limit = get_sp(); |
Stefan Roese | fe9dae6 | 2007-08-18 14:33:02 +0200 | [diff] [blame] | 74 | |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 75 | debug("## Current stack ends at 0x%08lX ", sp_limit); |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 76 | |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 77 | sp_limit -= 2048; /* just to be sure */ |
| 78 | if (sp_limit > CFG_BOOTMAPSZ) |
| 79 | sp_limit = CFG_BOOTMAPSZ; |
| 80 | sp_limit &= ~0xF; |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 81 | |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 82 | debug("=> set upper limit to 0x%08lX\n", sp_limit); |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 83 | |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 84 | cmdline = (char *)((sp_limit - CFG_BARGSIZE) & ~0xF); |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 85 | kbd = (bd_t *) (((ulong) cmdline - sizeof(bd_t)) & ~0xF); |
| 86 | |
| 87 | if ((s = getenv("bootargs")) == NULL) |
| 88 | s = ""; |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 89 | |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 90 | strcpy(cmdline, s); |
| 91 | |
| 92 | cmd_start = (ulong) & cmdline[0]; |
| 93 | cmd_end = cmd_start + strlen(cmdline); |
| 94 | |
| 95 | *kbd = *(gd->bd); |
| 96 | |
| 97 | #ifdef DEBUG |
| 98 | printf("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end); |
| 99 | |
| 100 | do_bdinfo(NULL, 0, 0, NULL); |
| 101 | #endif |
| 102 | |
| 103 | if ((s = getenv("clocks_in_mhz")) != NULL) { |
| 104 | /* convert all clock information to MHz */ |
| 105 | kbd->bi_intfreq /= 1000000L; |
| 106 | kbd->bi_busfreq /= 1000000L; |
| 107 | } |
| 108 | |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 109 | /* find kernel */ |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 110 | kernel = |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 111 | (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 112 | |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 113 | /* find ramdisk */ |
Marian Balakowicz | 9541850 | 2008-01-31 13:55:39 +0100 | [diff] [blame] | 114 | get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, |
| 115 | IH_ARCH_M68K, &rd_data_start, &rd_data_end); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 116 | |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 117 | rd_len = rd_data_end - rd_data_start; |
| 118 | ramdisk_high (rd_data_start, rd_len, kdb, sp_limit, get_sp (), |
| 119 | &initrd_start, &initrd_end); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 120 | |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 121 | debug("## Transferring control to Linux (at address %08lx) ...\n", |
| 122 | (ulong) kernel); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 123 | |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 124 | SHOW_BOOT_PROGRESS(15); |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 125 | |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 126 | /* |
| 127 | * Linux Kernel Parameters (passing board info data): |
| 128 | * r3: ptr to board info data |
| 129 | * r4: initrd_start or 0 if no initrd |
| 130 | * r5: initrd_end - unused if r4 is 0 |
| 131 | * r6: Start of command line string |
| 132 | * r7: End of command line string |
| 133 | */ |
| 134 | (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); |
| 135 | /* does not return */ |
wdenk | abf7a7c | 2003-12-08 01:34:36 +0000 | [diff] [blame] | 136 | } |
Marian Balakowicz | 9c701e8 | 2008-01-31 13:57:17 +0100 | [diff] [blame^] | 137 | |
| 138 | static ulong get_sp (void) |
| 139 | { |
| 140 | ulong sp; |
| 141 | |
| 142 | asm("movel %%a7, %%d0\n" |
| 143 | "movel %%d0, %0\n": "=d"(sp): :"%d0"); |
| 144 | |
| 145 | return sp; |
| 146 | } |