blob: 3fd38e98d15c1760a22983d55e3cc1f0ec9372fe [file] [log] [blame]
wdenk4e5ca3e2003-12-08 01:34:36 +00001/*
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
wdenkbf9e3b32004-02-12 00:47:09 +000015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk4e5ca3e2003-12-08 01:34:36 +000016 * 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
wdenkbf9e3b32004-02-12 00:47:09 +000020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
wdenk4e5ca3e2003-12-08 01:34:36 +000021 *
22 */
23
24#include <common.h>
25#include <command.h>
wdenk4e5ca3e2003-12-08 01:34:36 +000026#include <image.h>
27#include <zlib.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050028#include <bzlib.h>
TsiChungLiew688e8eb2007-10-25 17:14:00 -050029#include <watchdog.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050030#include <environment.h>
wdenk4e5ca3e2003-12-08 01:34:36 +000031#include <asm/byteorder.h>
32
Wolfgang Denkd87080b2006-03-31 18:32:53 +020033DECLARE_GLOBAL_DATA_PTR;
34
wdenk4e5ca3e2003-12-08 01:34:36 +000035#define PHYSADDR(x) x
36
wdenkbf9e3b32004-02-12 00:47:09 +000037#define LINUX_MAX_ENVS 256
38#define LINUX_MAX_ARGS 256
wdenk4e5ca3e2003-12-08 01:34:36 +000039
TsiChungLiew8ae158c2007-08-16 15:05:11 -050040#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
wdenk4e5ca3e2003-12-08 01:34:36 +000046
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010047static ulong get_sp (void);
48
TsiChungLiew8ae158c2007-08-16 15:05:11 -050049void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
50 int argc, char *argv[],
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010051 image_header_t *hdr, int verify)
wdenk4e5ca3e2003-12-08 01:34:36 +000052{
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010053 ulong sp_limit;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010054
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +010055 ulong rd_data_start, rd_data_end, rd_len;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010056 ulong initrd_start, initrd_end;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010057
58 ulong cmd_start, cmd_end;
TsiChungLiew8ae158c2007-08-16 15:05:11 -050059 char *cmdline;
60 char *s;
61 bd_t *kbd;
62 void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
wdenk4e5ca3e2003-12-08 01:34:36 +000063
TsiChungLiew8ae158c2007-08-16 15:05:11 -050064 /*
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 Balakowiczceaed2b2008-01-31 13:57:17 +010073 sp_limit = get_sp();
Stefan Roese8280f6a2007-08-18 14:33:02 +020074
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010075 debug("## Current stack ends at 0x%08lX ", sp_limit);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050076
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010077 sp_limit -= 2048; /* just to be sure */
78 if (sp_limit > CFG_BOOTMAPSZ)
79 sp_limit = CFG_BOOTMAPSZ;
80 sp_limit &= ~0xF;
TsiChungLiew8ae158c2007-08-16 15:05:11 -050081
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010082 debug("=> set upper limit to 0x%08lX\n", sp_limit);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050083
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010084 cmdline = (char *)((sp_limit - CFG_BARGSIZE) & ~0xF);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050085 kbd = (bd_t *) (((ulong) cmdline - sizeof(bd_t)) & ~0xF);
86
87 if ((s = getenv("bootargs")) == NULL)
88 s = "";
89
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 Balakowiczceaed2b2008-01-31 13:57:17 +0100109 /* find kernel */
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500110 kernel =
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100111 (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
wdenk4e5ca3e2003-12-08 01:34:36 +0000112
Marian Balakowiczceaed2b2008-01-31 13:57:17 +0100113 /* find ramdisk */
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100114 get_ramdisk (cmdtp, flag, argc, argv, hdr, verify,
115 IH_ARCH_M68K, &rd_data_start, &rd_data_end);
Marian Balakowiczceaed2b2008-01-31 13:57:17 +0100116
Marian Balakowicz5ad03eb2008-01-31 13:55:39 +0100117 rd_len = rd_data_end - rd_data_start;
Marian Balakowiczceaed2b2008-01-31 13:57:17 +0100118 ramdisk_high (rd_data_start, rd_len, kdb, sp_limit, get_sp (),
119 &initrd_start, &initrd_end);
wdenk4e5ca3e2003-12-08 01:34:36 +0000120
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500121 debug("## Transferring control to Linux (at address %08lx) ...\n",
122 (ulong) kernel);
wdenk4e5ca3e2003-12-08 01:34:36 +0000123
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500124 SHOW_BOOT_PROGRESS(15);
wdenk4e5ca3e2003-12-08 01:34:36 +0000125
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500126 /*
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 */
wdenk4e5ca3e2003-12-08 01:34:36 +0000136}
Marian Balakowiczceaed2b2008-01-31 13:57:17 +0100137
138static 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}