blob: 79d8b34c0d562cb5c11e384fbbdea59948cd80f3 [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
Simon Glass1ea97892020-05-10 11:40:00 -06007#include <bootstage.h>
wdenkabf7a7c2003-12-08 01:34:36 +00008#include <command.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06009#include <env.h>
wdenkabf7a7c2003-12-08 01:34:36 +000010#include <image.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060011#include <lmb.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Jean-Christophe PLAGNIOL-VILLARD6bb94492009-04-04 12:49:11 +020014#include <u-boot/zlib.h>
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050015#include <bzlib.h>
TsiChungLiew890adcb2007-10-25 17:14:00 -050016#include <watchdog.h>
wdenkabf7a7c2003-12-08 01:34:36 +000017#include <asm/byteorder.h>
Marian Balakowicz2efc2642008-01-31 13:58:13 +010018#ifdef CONFIG_SHOW_BOOT_PROGRESS
19# include <status_led.h>
20#endif
wdenkabf7a7c2003-12-08 01:34:36 +000021
Wolfgang Denk6405a152006-03-31 18:32:53 +020022DECLARE_GLOBAL_DATA_PTR;
23
wdenkabf7a7c2003-12-08 01:34:36 +000024#define PHYSADDR(x) x
25
wdenke65527f2004-02-12 00:47:09 +000026#define LINUX_MAX_ENVS 256
27#define LINUX_MAX_ARGS 256
wdenkabf7a7c2003-12-08 01:34:36 +000028
Marian Balakowicz9c701e82008-01-31 13:57:17 +010029static ulong get_sp (void);
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090030static void set_clocks_in_mhz (struct bd_info *kbd);
Marian Balakowicz9c701e82008-01-31 13:57:17 +010031
Kumar Galab02d7222008-10-16 21:52:08 -050032void arch_lmb_reserve(struct lmb *lmb)
wdenkabf7a7c2003-12-08 01:34:36 +000033{
Marek Vasutd0dd68f2021-09-10 22:47:10 +020034 arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 1024);
Kumar Galab02d7222008-10-16 21:52:08 -050035}
36
Simon Glassed38aef2020-05-10 11:40:03 -060037int do_bootm_linux(int flag, int argc, char *const argv[],
Simon Glassdf00afa2022-09-06 20:26:50 -060038 struct bootm_headers *images)
Kumar Galab02d7222008-10-16 21:52:08 -050039{
Kumar Galab02d7222008-10-16 21:52:08 -050040 int ret;
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090041 struct bd_info *kbd;
42 void (*kernel) (struct bd_info *, ulong, ulong, ulong, ulong);
Kumar Galab02d7222008-10-16 21:52:08 -050043 struct lmb *lmb = &images->lmb;
44
Andreas Bießmannda233ce2013-07-02 13:57:44 +020045 /*
46 * allow the PREP bootm subcommand, it is required for bootm to work
47 */
48 if (flag & BOOTM_STATE_OS_PREP)
49 return 0;
50
Kumar Gala18178bc2008-10-21 17:25:45 -050051 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
52 return 1;
53
Marian Balakowicz2efc2642008-01-31 13:58:13 +010054 /* allocate space for kernel copy of board info */
Grant Likelydfff7a22011-03-28 09:58:34 +000055 ret = boot_get_kbd (lmb, &kbd);
Kumar Galab937bb72008-02-27 21:51:49 -060056 if (ret) {
57 puts("ERROR with allocation of kernel bd\n");
58 goto error;
59 }
Marian Balakowicz2efc2642008-01-31 13:58:13 +010060 set_clocks_in_mhz(kbd);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050061
Simon Glassae7ed572023-02-05 15:40:13 -070062 if (IS_ENABLED(CONFIG_LMB)) {
Ashok Reddy Soma8aaae3d2022-07-07 10:45:37 +020063 ret = image_setup_linux(images);
64 if (ret)
65 goto error;
66 }
wdenkabf7a7c2003-12-08 01:34:36 +000067
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090068 kernel = (void (*)(struct bd_info *, ulong, ulong, ulong, ulong))images->ep;
Simon Glass6b4f0762013-05-08 08:06:05 +000069
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050070 debug("## Transferring control to Linux (at address %08lx) ...\n",
71 (ulong) kernel);
wdenkabf7a7c2003-12-08 01:34:36 +000072
Simon Glass0169e6b2012-02-13 13:51:18 +000073 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenkabf7a7c2003-12-08 01:34:36 +000074
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050075 /*
76 * Linux Kernel Parameters (passing board info data):
Richard Retanubun15fa2f02009-02-20 13:01:56 -050077 * sp+00: Ignore, side effect of using jsr to jump to kernel
78 * sp+04: ptr to board info data
79 * sp+08: initrd_start or 0 if no initrd
80 * sp+12: initrd_end - unused if initrd_start is 0
81 * sp+16: Start of command line string
82 * sp+20: End of command line string
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050083 */
Simon Glass660031e2014-06-07 22:07:58 -060084 (*kernel)(kbd, images->initrd_start, images->initrd_end,
85 images->cmdline_start, images->cmdline_end);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050086 /* does not return */
Kumar Gala18f4c0f2008-02-27 21:51:46 -060087error:
Kumar Gala48626aa2008-08-15 08:24:45 -050088 return 1;
wdenkabf7a7c2003-12-08 01:34:36 +000089}
Marian Balakowicz9c701e82008-01-31 13:57:17 +010090
91static ulong get_sp (void)
92{
93 ulong sp;
94
95 asm("movel %%a7, %%d0\n"
96 "movel %%d0, %0\n": "=d"(sp): :"%d0");
97
98 return sp;
99}
Marian Balakowicz2efc2642008-01-31 13:58:13 +0100100
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900101static void set_clocks_in_mhz (struct bd_info *kbd)
Marian Balakowicz2efc2642008-01-31 13:58:13 +0100102{
103 char *s;
104
Simon Glass64b723f2017-08-03 12:22:12 -0600105 s = env_get("clocks_in_mhz");
106 if (s) {
Marian Balakowicz2efc2642008-01-31 13:58:13 +0100107 /* convert all clock information to MHz */
108 kbd->bi_intfreq /= 1000000L;
109 kbd->bi_busfreq /= 1000000L;
110 }
111}