blob: c36ee79c923f5774aa7393fe806bb496232bdc6b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkabf7a7c2003-12-08 01:34:36 +00002/*
3 * (C) Copyright 2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenkabf7a7c2003-12-08 01:34:36 +00005 */
6
7#include <common.h>
Simon Glass1ea97892020-05-10 11:40:00 -06008#include <bootstage.h>
wdenkabf7a7c2003-12-08 01:34:36 +00009#include <command.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060010#include <env.h>
wdenkabf7a7c2003-12-08 01:34:36 +000011#include <image.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060012#include <lmb.h>
Jean-Christophe PLAGNIOL-VILLARD6bb94492009-04-04 12:49:11 +020013#include <u-boot/zlib.h>
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050014#include <bzlib.h>
TsiChungLiew890adcb2007-10-25 17:14:00 -050015#include <watchdog.h>
wdenkabf7a7c2003-12-08 01:34:36 +000016#include <asm/byteorder.h>
Marian Balakowicz2efc2642008-01-31 13:58:13 +010017#ifdef CONFIG_SHOW_BOOT_PROGRESS
18# include <status_led.h>
19#endif
wdenkabf7a7c2003-12-08 01:34:36 +000020
Wolfgang Denk6405a152006-03-31 18:32:53 +020021DECLARE_GLOBAL_DATA_PTR;
22
wdenkabf7a7c2003-12-08 01:34:36 +000023#define PHYSADDR(x) x
24
wdenke65527f2004-02-12 00:47:09 +000025#define LINUX_MAX_ENVS 256
26#define LINUX_MAX_ARGS 256
wdenkabf7a7c2003-12-08 01:34:36 +000027
Marian Balakowicz9c701e82008-01-31 13:57:17 +010028static ulong get_sp (void);
Marian Balakowicz2efc2642008-01-31 13:58:13 +010029static void set_clocks_in_mhz (bd_t *kbd);
Marian Balakowicz9c701e82008-01-31 13:57:17 +010030
Kumar Galab02d7222008-10-16 21:52:08 -050031void arch_lmb_reserve(struct lmb *lmb)
wdenkabf7a7c2003-12-08 01:34:36 +000032{
Kumar Galab937bb72008-02-27 21:51:49 -060033 ulong sp;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +010034
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050035 /*
36 * Booting a (Linux) kernel image
37 *
38 * Allocate space for command line and board info - the
39 * address should be as high as possible within the reach of
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020040 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050041 * memory, which means far enough below the current stack
42 * pointer.
43 */
Marian Balakowicz2efc2642008-01-31 13:58:13 +010044 sp = get_sp();
45 debug ("## Current stack ends at 0x%08lx ", sp);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050046
Kumar Galab937bb72008-02-27 21:51:49 -060047 /* adjust sp by 1K to be safe */
48 sp -= 1024;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020049 lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
Kumar Galab02d7222008-10-16 21:52:08 -050050}
51
Wolfgang Denk6262d0212010-06-28 22:00:46 +020052int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images)
Kumar Galab02d7222008-10-16 21:52:08 -050053{
Kumar Galab02d7222008-10-16 21:52:08 -050054 int ret;
Kumar Galab02d7222008-10-16 21:52:08 -050055 bd_t *kbd;
56 void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
57 struct lmb *lmb = &images->lmb;
58
Andreas Bießmannda233ce2013-07-02 13:57:44 +020059 /*
60 * allow the PREP bootm subcommand, it is required for bootm to work
61 */
62 if (flag & BOOTM_STATE_OS_PREP)
63 return 0;
64
Kumar Gala18178bc2008-10-21 17:25:45 -050065 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
66 return 1;
67
Marian Balakowicz2efc2642008-01-31 13:58:13 +010068 /* allocate space for kernel copy of board info */
Grant Likelydfff7a22011-03-28 09:58:34 +000069 ret = boot_get_kbd (lmb, &kbd);
Kumar Galab937bb72008-02-27 21:51:49 -060070 if (ret) {
71 puts("ERROR with allocation of kernel bd\n");
72 goto error;
73 }
Marian Balakowicz2efc2642008-01-31 13:58:13 +010074 set_clocks_in_mhz(kbd);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050075
Simon Glass6b4f0762013-05-08 08:06:05 +000076 ret = image_setup_linux(images);
Kumar Galab937bb72008-02-27 21:51:49 -060077 if (ret)
78 goto error;
wdenkabf7a7c2003-12-08 01:34:36 +000079
Simon Glass6b4f0762013-05-08 08:06:05 +000080 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
81
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050082 debug("## Transferring control to Linux (at address %08lx) ...\n",
83 (ulong) kernel);
wdenkabf7a7c2003-12-08 01:34:36 +000084
Simon Glass0169e6b2012-02-13 13:51:18 +000085 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenkabf7a7c2003-12-08 01:34:36 +000086
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050087 /*
88 * Linux Kernel Parameters (passing board info data):
Richard Retanubun15fa2f02009-02-20 13:01:56 -050089 * sp+00: Ignore, side effect of using jsr to jump to kernel
90 * sp+04: ptr to board info data
91 * sp+08: initrd_start or 0 if no initrd
92 * sp+12: initrd_end - unused if initrd_start is 0
93 * sp+16: Start of command line string
94 * sp+20: End of command line string
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050095 */
Simon Glass660031e2014-06-07 22:07:58 -060096 (*kernel)(kbd, images->initrd_start, images->initrd_end,
97 images->cmdline_start, images->cmdline_end);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050098 /* does not return */
Kumar Gala18f4c0f2008-02-27 21:51:46 -060099error:
Kumar Gala48626aa2008-08-15 08:24:45 -0500100 return 1;
wdenkabf7a7c2003-12-08 01:34:36 +0000101}
Marian Balakowicz9c701e82008-01-31 13:57:17 +0100102
103static ulong get_sp (void)
104{
105 ulong sp;
106
107 asm("movel %%a7, %%d0\n"
108 "movel %%d0, %0\n": "=d"(sp): :"%d0");
109
110 return sp;
111}
Marian Balakowicz2efc2642008-01-31 13:58:13 +0100112
113static void set_clocks_in_mhz (bd_t *kbd)
114{
115 char *s;
116
Simon Glass64b723f2017-08-03 12:22:12 -0600117 s = env_get("clocks_in_mhz");
118 if (s) {
Marian Balakowicz2efc2642008-01-31 13:58:13 +0100119 /* convert all clock information to MHz */
120 kbd->bi_intfreq /= 1000000L;
121 kbd->bi_busfreq /= 1000000L;
122 }
123}