blob: b205e5e3db1bf3e0099d4a62353f4289a6e433fb [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
10#include <common.h>
11#include <command.h>
Simon Glassed38aef2020-05-10 11:40:03 -060012#include <env.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060013#include <image.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090014#include <asm/byteorder.h>
Marek Vasut35c6d0e2021-09-10 22:47:16 +020015#include <asm/global_data.h>
Nobuhiro Iwamatsu3db60552010-12-08 13:46:36 +090016#include <asm/zimage.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090017
Marek Vasut35c6d0e2021-09-10 22:47:16 +020018DECLARE_GLOBAL_DATA_PTR;
19
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090020#ifdef CONFIG_SH_SDRAM_OFFSET
21#define GET_INITRD_START(initrd, linux) (initrd - linux + CONFIG_SH_SDRAM_OFFSET)
22#else
23#define GET_INITRD_START(initrd, linux) (initrd - linux)
24#endif
25
26static void set_sh_linux_param(unsigned long param_addr, unsigned long data)
27{
28 *(unsigned long *)(param_addr) = data;
29}
30
31static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base)
32{
33 unsigned long val = 0;
34 char *p = strstr(cmdline, key);
35 if (p) {
36 p += strlen(key);
37 val = simple_strtol(p, NULL, base);
38 }
39 return val;
40}
41
Simon Glassed38aef2020-05-10 11:40:03 -060042int do_bootm_linux(int flag, int argc, char *const argv[],
Simon Glassdf00afa2022-09-06 20:26:50 -060043 struct bootm_headers *images)
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090044{
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090045 /* Linux kernel load address */
Kumar Gala93467bc2008-08-15 08:24:36 -050046 void (*kernel) (void) = (void (*)(void))images->ep;
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090047 /* empty_zero_page */
Nobuhiro Iwamatsue58917e2008-09-18 19:34:36 +090048 unsigned char *param
49 = (unsigned char *)image_get_load(images->legacy_hdr_os);
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090050 /* Linux kernel command line */
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090051 char *cmdline = (char *)param + COMMAND_LINE;
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090052 /* PAGE_SIZE */
Nobuhiro Iwamatsue58917e2008-09-18 19:34:36 +090053 unsigned long size = images->ep - (unsigned long)param;
Simon Glass64b723f2017-08-03 12:22:12 -060054 char *bootargs = env_get("bootargs");
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090055
Andreas Bießmannda233ce2013-07-02 13:57:44 +020056 /*
57 * allow the PREP bootm subcommand, it is required for bootm to work
58 */
59 if (flag & BOOTM_STATE_OS_PREP)
60 return 0;
61
Kumar Gala18178bc2008-10-21 17:25:45 -050062 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
63 return 1;
64
Nobuhiro Iwamatsu3db60552010-12-08 13:46:36 +090065 /* Clear zero page */
66 memset(param, 0, size);
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090067
68 /* Set commandline */
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090069 strcpy(cmdline, bootargs);
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090070
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090071 /* Initrd */
72 if (images->rd_start || images->rd_end) {
Nobuhiro Iwamatsu0b43bd82010-10-19 17:14:15 +090073 unsigned long ramdisk_flags = 0;
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090074 int val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_PROMPT, 10);
75 if (val == 1)
76 ramdisk_flags |= RD_PROMPT;
77 else
78 ramdisk_flags &= ~RD_PROMPT;
Wolfgang Denk1136f692010-10-27 22:48:30 +020079
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090080 val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10);
81 if (val == 1)
82 ramdisk_flags |= RD_DOLOAD;
83 else
84 ramdisk_flags &= ~RD_DOLOAD;
85
86 set_sh_linux_param((unsigned long)param + MOUNT_ROOT_RDONLY, 0x0001);
87 set_sh_linux_param((unsigned long)param + RAMDISK_FLAGS, ramdisk_flags);
88 set_sh_linux_param((unsigned long)param + ORIG_ROOT_DEV, 0x0200);
89 set_sh_linux_param((unsigned long)param + LOADER_TYPE, 0x0001);
90 set_sh_linux_param((unsigned long)param + INITRD_START,
Tom Rinibb4dd962022-11-16 13:10:37 -050091 GET_INITRD_START(images->rd_start, CFG_SYS_SDRAM_BASE));
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090092 set_sh_linux_param((unsigned long)param + INITRD_SIZE,
93 images->rd_end - images->rd_start);
94 }
95
96 /* Boot kernel */
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090097 kernel();
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010098
Nobuhiro Iwamatsu3db60552010-12-08 13:46:36 +090099 /* does not return */
Kumar Gala48626aa2008-08-15 08:24:45 -0500100 return 1;
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900101}
Marek Vasut35c6d0e2021-09-10 22:47:16 +0200102
103static ulong get_sp(void)
104{
105 ulong ret;
106
107 asm("mov r15, %0" : "=r"(ret) : );
108 return ret;
109}
110
111void arch_lmb_reserve(struct lmb *lmb)
112{
113 arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
114}