blob: 3dcff8076e3cbb1e422afa94f66c3ea2cc8ee8ca [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 Glass0726d9d2023-12-15 20:14:13 -07007#include <bootm.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 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
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090029static void set_clocks_in_mhz (struct bd_info *kbd);
Marian Balakowicz9c701e82008-01-31 13:57:17 +010030
Simon Glass0726d9d2023-12-15 20:14:13 -070031int do_bootm_linux(int flag, struct bootm_info *bmi)
Kumar Galab02d7222008-10-16 21:52:08 -050032{
Simon Glass0726d9d2023-12-15 20:14:13 -070033 struct bootm_headers *images = bmi->images;
Kumar Galab02d7222008-10-16 21:52:08 -050034 int ret;
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090035 struct bd_info *kbd;
36 void (*kernel) (struct bd_info *, ulong, ulong, ulong, ulong);
Kumar Galab02d7222008-10-16 21:52:08 -050037
Andreas Bießmannda233ce2013-07-02 13:57:44 +020038 /*
39 * allow the PREP bootm subcommand, it is required for bootm to work
40 */
41 if (flag & BOOTM_STATE_OS_PREP)
42 return 0;
43
Kumar Gala18178bc2008-10-21 17:25:45 -050044 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
45 return 1;
46
Marian Balakowicz2efc2642008-01-31 13:58:13 +010047 /* allocate space for kernel copy of board info */
Sughosh Ganu291bf9c2024-08-26 17:29:18 +053048 ret = boot_get_kbd(&kbd);
Kumar Galab937bb72008-02-27 21:51:49 -060049 if (ret) {
50 puts("ERROR with allocation of kernel bd\n");
51 goto error;
52 }
Marian Balakowicz2efc2642008-01-31 13:58:13 +010053 set_clocks_in_mhz(kbd);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050054
Simon Glassae7ed572023-02-05 15:40:13 -070055 if (IS_ENABLED(CONFIG_LMB)) {
Ashok Reddy Soma8aaae3d2022-07-07 10:45:37 +020056 ret = image_setup_linux(images);
57 if (ret)
58 goto error;
59 }
wdenkabf7a7c2003-12-08 01:34:36 +000060
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090061 kernel = (void (*)(struct bd_info *, ulong, ulong, ulong, ulong))images->ep;
Simon Glass6b4f0762013-05-08 08:06:05 +000062
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050063 debug("## Transferring control to Linux (at address %08lx) ...\n",
64 (ulong) kernel);
wdenkabf7a7c2003-12-08 01:34:36 +000065
Simon Glass0169e6b2012-02-13 13:51:18 +000066 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenkabf7a7c2003-12-08 01:34:36 +000067
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050068 /*
69 * Linux Kernel Parameters (passing board info data):
Richard Retanubun15fa2f02009-02-20 13:01:56 -050070 * sp+00: Ignore, side effect of using jsr to jump to kernel
71 * sp+04: ptr to board info data
72 * sp+08: initrd_start or 0 if no initrd
73 * sp+12: initrd_end - unused if initrd_start is 0
74 * sp+16: Start of command line string
75 * sp+20: End of command line string
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050076 */
Simon Glass660031e2014-06-07 22:07:58 -060077 (*kernel)(kbd, images->initrd_start, images->initrd_end,
78 images->cmdline_start, images->cmdline_end);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050079 /* does not return */
Kumar Gala18f4c0f2008-02-27 21:51:46 -060080error:
Kumar Gala48626aa2008-08-15 08:24:45 -050081 return 1;
wdenkabf7a7c2003-12-08 01:34:36 +000082}
Marian Balakowicz9c701e82008-01-31 13:57:17 +010083
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090084static void set_clocks_in_mhz (struct bd_info *kbd)
Marian Balakowicz2efc2642008-01-31 13:58:13 +010085{
86 char *s;
87
Simon Glass64b723f2017-08-03 12:22:12 -060088 s = env_get("clocks_in_mhz");
89 if (s) {
Marian Balakowicz2efc2642008-01-31 13:58:13 +010090 /* convert all clock information to MHz */
91 kbd->bi_intfreq /= 1000000L;
92 kbd->bi_busfreq /= 1000000L;
93 }
94}