blob: f18bed235d45a416967822c41260457bc105774c [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>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Jean-Christophe PLAGNIOL-VILLARDa31e0912009-04-04 12:49:11 +020015#include <u-boot/zlib.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050016#include <bzlib.h>
TsiChungLiew688e8eb2007-10-25 17:14:00 -050017#include <watchdog.h>
wdenk4e5ca3e2003-12-08 01:34:36 +000018#include <asm/byteorder.h>
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010019#ifdef CONFIG_SHOW_BOOT_PROGRESS
20# include <status_led.h>
21#endif
wdenk4e5ca3e2003-12-08 01:34:36 +000022
Wolfgang Denkd87080b2006-03-31 18:32:53 +020023DECLARE_GLOBAL_DATA_PTR;
24
wdenk4e5ca3e2003-12-08 01:34:36 +000025#define PHYSADDR(x) x
26
wdenkbf9e3b32004-02-12 00:47:09 +000027#define LINUX_MAX_ENVS 256
28#define LINUX_MAX_ARGS 256
wdenk4e5ca3e2003-12-08 01:34:36 +000029
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010030static ulong get_sp (void);
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +090031static void set_clocks_in_mhz (struct bd_info *kbd);
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010032
Kumar Gala76da19d2008-10-16 21:52:08 -050033void arch_lmb_reserve(struct lmb *lmb)
wdenk4e5ca3e2003-12-08 01:34:36 +000034{
Marek Vasut1f391c32021-09-10 22:47:10 +020035 arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 1024);
Kumar Gala76da19d2008-10-16 21:52:08 -050036}
37
Simon Glass09140112020-05-10 11:40:03 -060038int do_bootm_linux(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -060039 struct bootm_headers *images)
Kumar Gala76da19d2008-10-16 21:52:08 -050040{
Kumar Gala76da19d2008-10-16 21:52:08 -050041 int ret;
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +090042 struct bd_info *kbd;
43 void (*kernel) (struct bd_info *, ulong, ulong, ulong, ulong);
Kumar Gala76da19d2008-10-16 21:52:08 -050044 struct lmb *lmb = &images->lmb;
45
Andreas Bießmann2cb0e552013-07-02 13:57:44 +020046 /*
47 * allow the PREP bootm subcommand, it is required for bootm to work
48 */
49 if (flag & BOOTM_STATE_OS_PREP)
50 return 0;
51
Kumar Gala49c3a862008-10-21 17:25:45 -050052 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
53 return 1;
54
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010055 /* allocate space for kernel copy of board info */
Grant Likely590d3ca2011-03-28 09:58:34 +000056 ret = boot_get_kbd (lmb, &kbd);
Kumar Galae822d7f2008-02-27 21:51:49 -060057 if (ret) {
58 puts("ERROR with allocation of kernel bd\n");
59 goto error;
60 }
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010061 set_clocks_in_mhz(kbd);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050062
Simon Glass210af542023-02-05 15:40:13 -070063 if (IS_ENABLED(CONFIG_LMB)) {
Ashok Reddy Soma65168912022-07-07 10:45:37 +020064 ret = image_setup_linux(images);
65 if (ret)
66 goto error;
67 }
wdenk4e5ca3e2003-12-08 01:34:36 +000068
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +090069 kernel = (void (*)(struct bd_info *, ulong, ulong, ulong, ulong))images->ep;
Simon Glass24507cf2013-05-08 08:06:05 +000070
TsiChungLiew8ae158c2007-08-16 15:05:11 -050071 debug("## Transferring control to Linux (at address %08lx) ...\n",
72 (ulong) kernel);
wdenk4e5ca3e2003-12-08 01:34:36 +000073
Simon Glass770605e2012-02-13 13:51:18 +000074 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenk4e5ca3e2003-12-08 01:34:36 +000075
TsiChungLiew8ae158c2007-08-16 15:05:11 -050076 /*
77 * Linux Kernel Parameters (passing board info data):
Richard Retanubunedff7bc2009-02-20 13:01:56 -050078 * sp+00: Ignore, side effect of using jsr to jump to kernel
79 * sp+04: ptr to board info data
80 * sp+08: initrd_start or 0 if no initrd
81 * sp+12: initrd_end - unused if initrd_start is 0
82 * sp+16: Start of command line string
83 * sp+20: End of command line string
TsiChungLiew8ae158c2007-08-16 15:05:11 -050084 */
Simon Glassddc94372014-06-07 22:07:58 -060085 (*kernel)(kbd, images->initrd_start, images->initrd_end,
86 images->cmdline_start, images->cmdline_end);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050087 /* does not return */
Kumar Gala274cea22008-02-27 21:51:46 -060088error:
Kumar Gala40d7e992008-08-15 08:24:45 -050089 return 1;
wdenk4e5ca3e2003-12-08 01:34:36 +000090}
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010091
92static ulong get_sp (void)
93{
94 ulong sp;
95
96 asm("movel %%a7, %%d0\n"
97 "movel %%d0, %0\n": "=d"(sp): :"%d0");
98
99 return sp;
100}
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +0100101
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900102static void set_clocks_in_mhz (struct bd_info *kbd)
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +0100103{
104 char *s;
105
Simon Glass00caae62017-08-03 12:22:12 -0600106 s = env_get("clocks_in_mhz");
107 if (s) {
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +0100108 /* convert all clock information to MHz */
109 kbd->bi_intfreq /= 1000000L;
110 kbd->bi_busfreq /= 1000000L;
111 }
112}