blob: b912d130d6ad401f2e73605260871f61022db997 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk4e5ca3e2003-12-08 01:34:36 +00002/*
3 * (C) Copyright 2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk4e5ca3e2003-12-08 01:34:36 +00005 */
6
7#include <common.h>
Simon Glass52f24232020-05-10 11:40:00 -06008#include <bootstage.h>
wdenk4e5ca3e2003-12-08 01:34:36 +00009#include <command.h>
Simon Glass7b51b572019-08-01 09:46:52 -060010#include <env.h>
wdenk4e5ca3e2003-12-08 01:34:36 +000011#include <image.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060012#include <lmb.h>
Jean-Christophe PLAGNIOL-VILLARDa31e0912009-04-04 12:49:11 +020013#include <u-boot/zlib.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050014#include <bzlib.h>
TsiChungLiew688e8eb2007-10-25 17:14:00 -050015#include <watchdog.h>
wdenk4e5ca3e2003-12-08 01:34:36 +000016#include <asm/byteorder.h>
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010017#ifdef CONFIG_SHOW_BOOT_PROGRESS
18# include <status_led.h>
19#endif
wdenk4e5ca3e2003-12-08 01:34:36 +000020
Wolfgang Denkd87080b2006-03-31 18:32:53 +020021DECLARE_GLOBAL_DATA_PTR;
22
wdenk4e5ca3e2003-12-08 01:34:36 +000023#define PHYSADDR(x) x
24
wdenkbf9e3b32004-02-12 00:47:09 +000025#define LINUX_MAX_ENVS 256
26#define LINUX_MAX_ARGS 256
wdenk4e5ca3e2003-12-08 01:34:36 +000027
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010028static ulong get_sp (void);
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010029static void set_clocks_in_mhz (bd_t *kbd);
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010030
Kumar Gala76da19d2008-10-16 21:52:08 -050031void arch_lmb_reserve(struct lmb *lmb)
wdenk4e5ca3e2003-12-08 01:34:36 +000032{
Kumar Galae822d7f2008-02-27 21:51:49 -060033 ulong sp;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010034
TsiChungLiew8ae158c2007-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-VILLARD6d0f6bc2008-10-16 15:01:15 +020040 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
TsiChungLiew8ae158c2007-08-16 15:05:11 -050041 * memory, which means far enough below the current stack
42 * pointer.
43 */
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010044 sp = get_sp();
45 debug ("## Current stack ends at 0x%08lx ", sp);
Stefan Roese8280f6a2007-08-18 14:33:02 +020046
Kumar Galae822d7f2008-02-27 21:51:49 -060047 /* adjust sp by 1K to be safe */
48 sp -= 1024;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020049 lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
Kumar Gala76da19d2008-10-16 21:52:08 -050050}
51
Simon Glass09140112020-05-10 11:40:03 -060052int do_bootm_linux(int flag, int argc, char *const argv[],
53 bootm_headers_t *images)
Kumar Gala76da19d2008-10-16 21:52:08 -050054{
Kumar Gala76da19d2008-10-16 21:52:08 -050055 int ret;
Kumar Gala76da19d2008-10-16 21:52:08 -050056 bd_t *kbd;
57 void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
58 struct lmb *lmb = &images->lmb;
59
Andreas Bießmann2cb0e552013-07-02 13:57:44 +020060 /*
61 * allow the PREP bootm subcommand, it is required for bootm to work
62 */
63 if (flag & BOOTM_STATE_OS_PREP)
64 return 0;
65
Kumar Gala49c3a862008-10-21 17:25:45 -050066 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
67 return 1;
68
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010069 /* allocate space for kernel copy of board info */
Grant Likely590d3ca2011-03-28 09:58:34 +000070 ret = boot_get_kbd (lmb, &kbd);
Kumar Galae822d7f2008-02-27 21:51:49 -060071 if (ret) {
72 puts("ERROR with allocation of kernel bd\n");
73 goto error;
74 }
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010075 set_clocks_in_mhz(kbd);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050076
Simon Glass24507cf2013-05-08 08:06:05 +000077 ret = image_setup_linux(images);
Kumar Galae822d7f2008-02-27 21:51:49 -060078 if (ret)
79 goto error;
wdenk4e5ca3e2003-12-08 01:34:36 +000080
Simon Glass24507cf2013-05-08 08:06:05 +000081 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
82
TsiChungLiew8ae158c2007-08-16 15:05:11 -050083 debug("## Transferring control to Linux (at address %08lx) ...\n",
84 (ulong) kernel);
wdenk4e5ca3e2003-12-08 01:34:36 +000085
Simon Glass770605e2012-02-13 13:51:18 +000086 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenk4e5ca3e2003-12-08 01:34:36 +000087
TsiChungLiew8ae158c2007-08-16 15:05:11 -050088 /*
89 * Linux Kernel Parameters (passing board info data):
Richard Retanubunedff7bc2009-02-20 13:01:56 -050090 * sp+00: Ignore, side effect of using jsr to jump to kernel
91 * sp+04: ptr to board info data
92 * sp+08: initrd_start or 0 if no initrd
93 * sp+12: initrd_end - unused if initrd_start is 0
94 * sp+16: Start of command line string
95 * sp+20: End of command line string
TsiChungLiew8ae158c2007-08-16 15:05:11 -050096 */
Simon Glassddc94372014-06-07 22:07:58 -060097 (*kernel)(kbd, images->initrd_start, images->initrd_end,
98 images->cmdline_start, images->cmdline_end);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050099 /* does not return */
Kumar Gala274cea22008-02-27 21:51:46 -0600100error:
Kumar Gala40d7e992008-08-15 08:24:45 -0500101 return 1;
wdenk4e5ca3e2003-12-08 01:34:36 +0000102}
Marian Balakowiczceaed2b2008-01-31 13:57:17 +0100103
104static ulong get_sp (void)
105{
106 ulong sp;
107
108 asm("movel %%a7, %%d0\n"
109 "movel %%d0, %0\n": "=d"(sp): :"%d0");
110
111 return sp;
112}
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +0100113
114static void set_clocks_in_mhz (bd_t *kbd)
115{
116 char *s;
117
Simon Glass00caae62017-08-03 12:22:12 -0600118 s = env_get("clocks_in_mhz");
119 if (s) {
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +0100120 /* convert all clock information to MHz */
121 kbd->bi_intfreq /= 1000000L;
122 kbd->bi_busfreq /= 1000000L;
123 }
124}