blob: b205e5e3db1bf3e0099d4a62353f4289a6e433fb [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +09002/*
3 * (C) Copyright 2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +09006 * (c) Copyright 2008 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
7 * (c) Copyright 2008 Renesas Solutions Corp.
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +09008 */
9
10#include <common.h>
11#include <command.h>
Simon Glass09140112020-05-10 11:40:03 -060012#include <env.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060013#include <image.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090014#include <asm/byteorder.h>
Marek Vasut1e0e5572021-09-10 22:47:16 +020015#include <asm/global_data.h>
Nobuhiro Iwamatsu9980df52010-12-08 13:46:36 +090016#include <asm/zimage.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090017
Marek Vasut1e0e5572021-09-10 22:47:16 +020018DECLARE_GLOBAL_DATA_PTR;
19
Nobuhiro Iwamatsucf2c87d2010-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 Glass09140112020-05-10 11:40:03 -060042int do_bootm_linux(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -060043 struct bootm_headers *images)
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090044{
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090045 /* Linux kernel load address */
Kumar Galac160a952008-08-15 08:24:36 -050046 void (*kernel) (void) = (void (*)(void))images->ep;
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090047 /* empty_zero_page */
Nobuhiro Iwamatsub5d10a12008-09-18 19:34:36 +090048 unsigned char *param
49 = (unsigned char *)image_get_load(images->legacy_hdr_os);
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090050 /* Linux kernel command line */
Nobuhiro Iwamatsucf2c87d2010-09-28 12:14:57 +090051 char *cmdline = (char *)param + COMMAND_LINE;
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090052 /* PAGE_SIZE */
Nobuhiro Iwamatsub5d10a12008-09-18 19:34:36 +090053 unsigned long size = images->ep - (unsigned long)param;
Simon Glass00caae62017-08-03 12:22:12 -060054 char *bootargs = env_get("bootargs");
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090055
Andreas Bießmann2cb0e552013-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 Gala49c3a862008-10-21 17:25:45 -050062 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
63 return 1;
64
Nobuhiro Iwamatsu9980df52010-12-08 13:46:36 +090065 /* Clear zero page */
66 memset(param, 0, size);
Nobuhiro Iwamatsucf2c87d2010-09-28 12:14:57 +090067
68 /* Set commandline */
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090069 strcpy(cmdline, bootargs);
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090070
Nobuhiro Iwamatsucf2c87d2010-09-28 12:14:57 +090071 /* Initrd */
72 if (images->rd_start || images->rd_end) {
Nobuhiro Iwamatsude03f8b2010-10-19 17:14:15 +090073 unsigned long ramdisk_flags = 0;
Nobuhiro Iwamatsucf2c87d2010-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 Denk071bc922010-10-27 22:48:30 +020079
Nobuhiro Iwamatsucf2c87d2010-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 Riniaa6e94d2022-11-16 13:10:37 -050091 GET_INITRD_START(images->rd_start, CFG_SYS_SDRAM_BASE));
Nobuhiro Iwamatsucf2c87d2010-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 Iwamatsu0b135cf2007-05-13 20:58:00 +090097 kernel();
Marian Balakowiczcd7c5962008-03-12 10:33:00 +010098
Nobuhiro Iwamatsu9980df52010-12-08 13:46:36 +090099 /* does not return */
Kumar Gala40d7e992008-08-15 08:24:45 -0500100 return 1;
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900101}
Marek Vasut1e0e5572021-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}