blob: 804e01dae68b8cf606e237351fab7c98f1c9d497 [file] [log] [blame]
wdenkabf7a7c2003-12-08 01:34:36 +00001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkabf7a7c2003-12-08 01:34:36 +00006 */
7
8#include <common.h>
9#include <command.h>
wdenkabf7a7c2003-12-08 01:34:36 +000010#include <image.h>
Jean-Christophe PLAGNIOL-VILLARD6bb94492009-04-04 12:49:11 +020011#include <u-boot/zlib.h>
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050012#include <bzlib.h>
TsiChungLiew890adcb2007-10-25 17:14:00 -050013#include <watchdog.h>
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050014#include <environment.h>
wdenkabf7a7c2003-12-08 01:34:36 +000015#include <asm/byteorder.h>
Marian Balakowicz2efc2642008-01-31 13:58:13 +010016#ifdef CONFIG_SHOW_BOOT_PROGRESS
17# include <status_led.h>
18#endif
wdenkabf7a7c2003-12-08 01:34:36 +000019
Wolfgang Denk6405a152006-03-31 18:32:53 +020020DECLARE_GLOBAL_DATA_PTR;
21
wdenkabf7a7c2003-12-08 01:34:36 +000022#define PHYSADDR(x) x
23
wdenke65527f2004-02-12 00:47:09 +000024#define LINUX_MAX_ENVS 256
25#define LINUX_MAX_ARGS 256
wdenkabf7a7c2003-12-08 01:34:36 +000026
Marian Balakowicz9c701e82008-01-31 13:57:17 +010027static ulong get_sp (void);
Marian Balakowicz2efc2642008-01-31 13:58:13 +010028static void set_clocks_in_mhz (bd_t *kbd);
Marian Balakowicz9c701e82008-01-31 13:57:17 +010029
Kumar Galab02d7222008-10-16 21:52:08 -050030void arch_lmb_reserve(struct lmb *lmb)
wdenkabf7a7c2003-12-08 01:34:36 +000031{
Kumar Galab937bb72008-02-27 21:51:49 -060032 ulong sp;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +010033
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050034 /*
35 * Booting a (Linux) kernel image
36 *
37 * Allocate space for command line and board info - the
38 * address should be as high as possible within the reach of
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020039 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050040 * memory, which means far enough below the current stack
41 * pointer.
42 */
Marian Balakowicz2efc2642008-01-31 13:58:13 +010043 sp = get_sp();
44 debug ("## Current stack ends at 0x%08lx ", sp);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050045
Kumar Galab937bb72008-02-27 21:51:49 -060046 /* adjust sp by 1K to be safe */
47 sp -= 1024;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020048 lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
Kumar Galab02d7222008-10-16 21:52:08 -050049}
50
Wolfgang Denk6262d0212010-06-28 22:00:46 +020051int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images)
Kumar Galab02d7222008-10-16 21:52:08 -050052{
53 ulong rd_len;
54 ulong initrd_start, initrd_end;
55 int ret;
56
57 ulong cmd_start, cmd_end;
Kumar Galab02d7222008-10-16 21:52:08 -050058 bd_t *kbd;
59 void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
60 struct lmb *lmb = &images->lmb;
61
Andreas Bießmannda233ce2013-07-02 13:57:44 +020062 /*
63 * allow the PREP bootm subcommand, it is required for bootm to work
64 */
65 if (flag & BOOTM_STATE_OS_PREP)
66 return 0;
67
Kumar Gala18178bc2008-10-21 17:25:45 -050068 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
69 return 1;
70
Marian Balakowicz2efc2642008-01-31 13:58:13 +010071 /* allocate space for kernel copy of board info */
Grant Likelydfff7a22011-03-28 09:58:34 +000072 ret = boot_get_kbd (lmb, &kbd);
Kumar Galab937bb72008-02-27 21:51:49 -060073 if (ret) {
74 puts("ERROR with allocation of kernel bd\n");
75 goto error;
76 }
Marian Balakowicz2efc2642008-01-31 13:58:13 +010077 set_clocks_in_mhz(kbd);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050078
Simon Glass6b4f0762013-05-08 08:06:05 +000079 ret = image_setup_linux(images);
Kumar Galab937bb72008-02-27 21:51:49 -060080 if (ret)
81 goto error;
wdenkabf7a7c2003-12-08 01:34:36 +000082
Simon Glass6b4f0762013-05-08 08:06:05 +000083 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
84
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050085 debug("## Transferring control to Linux (at address %08lx) ...\n",
86 (ulong) kernel);
wdenkabf7a7c2003-12-08 01:34:36 +000087
Simon Glass0169e6b2012-02-13 13:51:18 +000088 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenkabf7a7c2003-12-08 01:34:36 +000089
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050090 /*
91 * Linux Kernel Parameters (passing board info data):
Richard Retanubun15fa2f02009-02-20 13:01:56 -050092 * sp+00: Ignore, side effect of using jsr to jump to kernel
93 * sp+04: ptr to board info data
94 * sp+08: initrd_start or 0 if no initrd
95 * sp+12: initrd_end - unused if initrd_start is 0
96 * sp+16: Start of command line string
97 * sp+20: End of command line string
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050098 */
99 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
100 /* does not return */
Kumar Gala18f4c0f2008-02-27 21:51:46 -0600101error:
Kumar Gala48626aa2008-08-15 08:24:45 -0500102 return 1;
wdenkabf7a7c2003-12-08 01:34:36 +0000103}
Marian Balakowicz9c701e82008-01-31 13:57:17 +0100104
105static ulong get_sp (void)
106{
107 ulong sp;
108
109 asm("movel %%a7, %%d0\n"
110 "movel %%d0, %0\n": "=d"(sp): :"%d0");
111
112 return sp;
113}
Marian Balakowicz2efc2642008-01-31 13:58:13 +0100114
115static void set_clocks_in_mhz (bd_t *kbd)
116{
117 char *s;
118
119 if ((s = getenv("clocks_in_mhz")) != NULL) {
120 /* convert all clock information to MHz */
121 kbd->bi_intfreq /= 1000000L;
122 kbd->bi_busfreq /= 1000000L;
123 }
124}