blob: e298d766b52d0ae666671480916685d7a55caef8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09002/*
3 * (C) Copyright 2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +09006 * (c) Copyright 2008 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
7 * (c) Copyright 2008 Renesas Solutions Corp.
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09008 */
9
Tom Rinidec7ea02024-05-20 13:35:03 -060010#include <config.h>
Simon Glass0726d9d2023-12-15 20:14:13 -070011#include <bootm.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090012#include <command.h>
Simon Glassed38aef2020-05-10 11:40:03 -060013#include <env.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060014#include <image.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090015#include <asm/byteorder.h>
Marek Vasut35c6d0e2021-09-10 22:47:16 +020016#include <asm/global_data.h>
Nobuhiro Iwamatsu3db60552010-12-08 13:46:36 +090017#include <asm/zimage.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090018
Marek Vasut35c6d0e2021-09-10 22:47:16 +020019DECLARE_GLOBAL_DATA_PTR;
20
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090021#ifdef CONFIG_SH_SDRAM_OFFSET
22#define GET_INITRD_START(initrd, linux) (initrd - linux + CONFIG_SH_SDRAM_OFFSET)
23#else
24#define GET_INITRD_START(initrd, linux) (initrd - linux)
25#endif
26
27static void set_sh_linux_param(unsigned long param_addr, unsigned long data)
28{
29 *(unsigned long *)(param_addr) = data;
30}
31
32static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base)
33{
34 unsigned long val = 0;
35 char *p = strstr(cmdline, key);
36 if (p) {
37 p += strlen(key);
38 val = simple_strtol(p, NULL, base);
39 }
40 return val;
41}
42
Simon Glass0726d9d2023-12-15 20:14:13 -070043int do_bootm_linux(int flag, struct bootm_info *bmi)
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090044{
Simon Glass0726d9d2023-12-15 20:14:13 -070045 struct bootm_headers *images = bmi->images;
46
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090047 /* Linux kernel load address */
Kumar Gala93467bc2008-08-15 08:24:36 -050048 void (*kernel) (void) = (void (*)(void))images->ep;
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090049 /* empty_zero_page */
Nobuhiro Iwamatsue58917e2008-09-18 19:34:36 +090050 unsigned char *param
51 = (unsigned char *)image_get_load(images->legacy_hdr_os);
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090052 /* Linux kernel command line */
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090053 char *cmdline = (char *)param + COMMAND_LINE;
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090054 /* PAGE_SIZE */
Nobuhiro Iwamatsue58917e2008-09-18 19:34:36 +090055 unsigned long size = images->ep - (unsigned long)param;
Simon Glass64b723f2017-08-03 12:22:12 -060056 char *bootargs = env_get("bootargs");
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090057
Andreas Bießmannda233ce2013-07-02 13:57:44 +020058 /*
59 * allow the PREP bootm subcommand, it is required for bootm to work
60 */
61 if (flag & BOOTM_STATE_OS_PREP)
62 return 0;
63
Kumar Gala18178bc2008-10-21 17:25:45 -050064 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
65 return 1;
66
Nobuhiro Iwamatsu3db60552010-12-08 13:46:36 +090067 /* Clear zero page */
68 memset(param, 0, size);
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090069
70 /* Set commandline */
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090071 strcpy(cmdline, bootargs);
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090072
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090073 /* Initrd */
74 if (images->rd_start || images->rd_end) {
Nobuhiro Iwamatsu0b43bd82010-10-19 17:14:15 +090075 unsigned long ramdisk_flags = 0;
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090076 int val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_PROMPT, 10);
77 if (val == 1)
78 ramdisk_flags |= RD_PROMPT;
79 else
80 ramdisk_flags &= ~RD_PROMPT;
Wolfgang Denk1136f692010-10-27 22:48:30 +020081
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090082 val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10);
83 if (val == 1)
84 ramdisk_flags |= RD_DOLOAD;
85 else
86 ramdisk_flags &= ~RD_DOLOAD;
87
88 set_sh_linux_param((unsigned long)param + MOUNT_ROOT_RDONLY, 0x0001);
89 set_sh_linux_param((unsigned long)param + RAMDISK_FLAGS, ramdisk_flags);
90 set_sh_linux_param((unsigned long)param + ORIG_ROOT_DEV, 0x0200);
91 set_sh_linux_param((unsigned long)param + LOADER_TYPE, 0x0001);
92 set_sh_linux_param((unsigned long)param + INITRD_START,
Tom Rinibb4dd962022-11-16 13:10:37 -050093 GET_INITRD_START(images->rd_start, CFG_SYS_SDRAM_BASE));
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090094 set_sh_linux_param((unsigned long)param + INITRD_SIZE,
95 images->rd_end - images->rd_start);
96 }
97
98 /* Boot kernel */
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090099 kernel();
Marian Balakowiczdf8ff332008-03-12 10:33:00 +0100100
Nobuhiro Iwamatsu3db60552010-12-08 13:46:36 +0900101 /* does not return */
Kumar Gala48626aa2008-08-15 08:24:45 -0500102 return 1;
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900103}
Marek Vasut35c6d0e2021-09-10 22:47:16 +0200104
105static ulong get_sp(void)
106{
107 ulong ret;
108
109 asm("mov r15, %0" : "=r"(ret) : );
110 return ret;
111}
112
113void arch_lmb_reserve(struct lmb *lmb)
114{
115 arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
116}