blob: 2896e45f0df8bf05949ef4c0af03fb2b13c58374 [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>
12#include <asm/byteorder.h>
Nobuhiro Iwamatsu3db60552010-12-08 13:46:36 +090013#include <asm/zimage.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090014
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020015#ifdef CONFIG_SYS_DEBUG
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090016static void hexdump(unsigned char *buf, int len)
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090017{
18 int i;
19
20 for (i = 0; i < len; i++) {
21 if ((i % 16) == 0)
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090022 printf("%s%08x: ", i ? "\n" : "",
23 (unsigned int)&buf[i]);
24 printf("%02x ", buf[i]);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090025 }
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090026 printf("\n");
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090027}
28#endif
29
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090030#ifdef CONFIG_SH_SDRAM_OFFSET
31#define GET_INITRD_START(initrd, linux) (initrd - linux + CONFIG_SH_SDRAM_OFFSET)
32#else
33#define GET_INITRD_START(initrd, linux) (initrd - linux)
34#endif
35
36static void set_sh_linux_param(unsigned long param_addr, unsigned long data)
37{
38 *(unsigned long *)(param_addr) = data;
39}
40
41static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base)
42{
43 unsigned long val = 0;
44 char *p = strstr(cmdline, key);
45 if (p) {
46 p += strlen(key);
47 val = simple_strtol(p, NULL, base);
48 }
49 return val;
50}
51
Wolfgang Denk6262d0212010-06-28 22:00:46 +020052int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images)
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090053{
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090054 /* Linux kernel load address */
Kumar Gala93467bc2008-08-15 08:24:36 -050055 void (*kernel) (void) = (void (*)(void))images->ep;
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090056 /* empty_zero_page */
Nobuhiro Iwamatsue58917e2008-09-18 19:34:36 +090057 unsigned char *param
58 = (unsigned char *)image_get_load(images->legacy_hdr_os);
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090059 /* Linux kernel command line */
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090060 char *cmdline = (char *)param + COMMAND_LINE;
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090061 /* PAGE_SIZE */
Nobuhiro Iwamatsue58917e2008-09-18 19:34:36 +090062 unsigned long size = images->ep - (unsigned long)param;
Simon Glass64b723f2017-08-03 12:22:12 -060063 char *bootargs = env_get("bootargs");
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090064
Andreas Bießmannda233ce2013-07-02 13:57:44 +020065 /*
66 * allow the PREP bootm subcommand, it is required for bootm to work
67 */
68 if (flag & BOOTM_STATE_OS_PREP)
69 return 0;
70
Kumar Gala18178bc2008-10-21 17:25:45 -050071 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
72 return 1;
73
Nobuhiro Iwamatsu3db60552010-12-08 13:46:36 +090074 /* Clear zero page */
75 memset(param, 0, size);
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090076
77 /* Set commandline */
Nobuhiro Iwamatsu752a5952008-09-17 11:08:36 +090078 strcpy(cmdline, bootargs);
Nobuhiro Iwamatsu547b67f2007-09-23 02:12:30 +090079
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090080 /* Initrd */
81 if (images->rd_start || images->rd_end) {
Nobuhiro Iwamatsu0b43bd82010-10-19 17:14:15 +090082 unsigned long ramdisk_flags = 0;
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090083 int val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_PROMPT, 10);
84 if (val == 1)
85 ramdisk_flags |= RD_PROMPT;
86 else
87 ramdisk_flags &= ~RD_PROMPT;
Wolfgang Denk1136f692010-10-27 22:48:30 +020088
Nobuhiro Iwamatsu190f4f72010-09-28 12:14:57 +090089 val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10);
90 if (val == 1)
91 ramdisk_flags |= RD_DOLOAD;
92 else
93 ramdisk_flags &= ~RD_DOLOAD;
94
95 set_sh_linux_param((unsigned long)param + MOUNT_ROOT_RDONLY, 0x0001);
96 set_sh_linux_param((unsigned long)param + RAMDISK_FLAGS, ramdisk_flags);
97 set_sh_linux_param((unsigned long)param + ORIG_ROOT_DEV, 0x0200);
98 set_sh_linux_param((unsigned long)param + LOADER_TYPE, 0x0001);
99 set_sh_linux_param((unsigned long)param + INITRD_START,
100 GET_INITRD_START(images->rd_start, CONFIG_SYS_SDRAM_BASE));
101 set_sh_linux_param((unsigned long)param + INITRD_SIZE,
102 images->rd_end - images->rd_start);
103 }
104
105 /* Boot kernel */
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900106 kernel();
Marian Balakowiczdf8ff332008-03-12 10:33:00 +0100107
Nobuhiro Iwamatsu3db60552010-12-08 13:46:36 +0900108 /* does not return */
Kumar Gala48626aa2008-08-15 08:24:45 -0500109 return 1;
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900110}