blob: dc94f8378566e957db8e412887b06fe9c98641f4 [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>
Nobuhiro Iwamatsu9980df52010-12-08 13:46:36 +090015#include <asm/zimage.h>
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090016
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020017#ifdef CONFIG_SYS_DEBUG
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090018static void hexdump(unsigned char *buf, int len)
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090019{
20 int i;
21
22 for (i = 0; i < len; i++) {
23 if ((i % 16) == 0)
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090024 printf("%s%08x: ", i ? "\n" : "",
25 (unsigned int)&buf[i]);
26 printf("%02x ", buf[i]);
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090027 }
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090028 printf("\n");
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090029}
30#endif
31
Nobuhiro Iwamatsucf2c87d2010-09-28 12:14:57 +090032#ifdef CONFIG_SH_SDRAM_OFFSET
33#define GET_INITRD_START(initrd, linux) (initrd - linux + CONFIG_SH_SDRAM_OFFSET)
34#else
35#define GET_INITRD_START(initrd, linux) (initrd - linux)
36#endif
37
38static void set_sh_linux_param(unsigned long param_addr, unsigned long data)
39{
40 *(unsigned long *)(param_addr) = data;
41}
42
43static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base)
44{
45 unsigned long val = 0;
46 char *p = strstr(cmdline, key);
47 if (p) {
48 p += strlen(key);
49 val = simple_strtol(p, NULL, base);
50 }
51 return val;
52}
53
Simon Glass09140112020-05-10 11:40:03 -060054int do_bootm_linux(int flag, int argc, char *const argv[],
55 bootm_headers_t *images)
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090056{
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090057 /* Linux kernel load address */
Kumar Galac160a952008-08-15 08:24:36 -050058 void (*kernel) (void) = (void (*)(void))images->ep;
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090059 /* empty_zero_page */
Nobuhiro Iwamatsub5d10a12008-09-18 19:34:36 +090060 unsigned char *param
61 = (unsigned char *)image_get_load(images->legacy_hdr_os);
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090062 /* Linux kernel command line */
Nobuhiro Iwamatsucf2c87d2010-09-28 12:14:57 +090063 char *cmdline = (char *)param + COMMAND_LINE;
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090064 /* PAGE_SIZE */
Nobuhiro Iwamatsub5d10a12008-09-18 19:34:36 +090065 unsigned long size = images->ep - (unsigned long)param;
Simon Glass00caae62017-08-03 12:22:12 -060066 char *bootargs = env_get("bootargs");
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +090067
Andreas Bießmann2cb0e552013-07-02 13:57:44 +020068 /*
69 * allow the PREP bootm subcommand, it is required for bootm to work
70 */
71 if (flag & BOOTM_STATE_OS_PREP)
72 return 0;
73
Kumar Gala49c3a862008-10-21 17:25:45 -050074 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
75 return 1;
76
Nobuhiro Iwamatsu9980df52010-12-08 13:46:36 +090077 /* Clear zero page */
78 memset(param, 0, size);
Nobuhiro Iwamatsucf2c87d2010-09-28 12:14:57 +090079
80 /* Set commandline */
Nobuhiro Iwamatsu6b44a432008-09-17 11:08:36 +090081 strcpy(cmdline, bootargs);
Nobuhiro Iwamatsub02bad12007-09-23 02:12:30 +090082
Nobuhiro Iwamatsucf2c87d2010-09-28 12:14:57 +090083 /* Initrd */
84 if (images->rd_start || images->rd_end) {
Nobuhiro Iwamatsude03f8b2010-10-19 17:14:15 +090085 unsigned long ramdisk_flags = 0;
Nobuhiro Iwamatsucf2c87d2010-09-28 12:14:57 +090086 int val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_PROMPT, 10);
87 if (val == 1)
88 ramdisk_flags |= RD_PROMPT;
89 else
90 ramdisk_flags &= ~RD_PROMPT;
Wolfgang Denk071bc922010-10-27 22:48:30 +020091
Nobuhiro Iwamatsucf2c87d2010-09-28 12:14:57 +090092 val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10);
93 if (val == 1)
94 ramdisk_flags |= RD_DOLOAD;
95 else
96 ramdisk_flags &= ~RD_DOLOAD;
97
98 set_sh_linux_param((unsigned long)param + MOUNT_ROOT_RDONLY, 0x0001);
99 set_sh_linux_param((unsigned long)param + RAMDISK_FLAGS, ramdisk_flags);
100 set_sh_linux_param((unsigned long)param + ORIG_ROOT_DEV, 0x0200);
101 set_sh_linux_param((unsigned long)param + LOADER_TYPE, 0x0001);
102 set_sh_linux_param((unsigned long)param + INITRD_START,
103 GET_INITRD_START(images->rd_start, CONFIG_SYS_SDRAM_BASE));
104 set_sh_linux_param((unsigned long)param + INITRD_SIZE,
105 images->rd_end - images->rd_start);
106 }
107
108 /* Boot kernel */
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900109 kernel();
Marian Balakowiczcd7c5962008-03-12 10:33:00 +0100110
Nobuhiro Iwamatsu9980df52010-12-08 13:46:36 +0900111 /* does not return */
Kumar Gala40d7e992008-08-15 08:24:45 -0500112 return 1;
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900113}