]> git.ipfire.org Git - thirdparty/u-boot.git/blame - arch/sh/lib/bootm.c
command: Remove the cmd_tbl_t typedef
[thirdparty/u-boot.git] / arch / sh / lib / bootm.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
0b135cfc
NI
2/*
3 * (C) Copyright 2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6b44a439
NI
6 * (c) Copyright 2008 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
7 * (c) Copyright 2008 Renesas Solutions Corp.
0b135cfc
NI
8 */
9
10#include <common.h>
11#include <command.h>
09140113 12#include <env.h>
4d72caa5 13#include <image.h>
0b135cfc 14#include <asm/byteorder.h>
9980df56 15#include <asm/zimage.h>
0b135cfc 16
6d0f6bcf 17#ifdef CONFIG_SYS_DEBUG
6b44a439 18static void hexdump(unsigned char *buf, int len)
0b135cfc
NI
19{
20 int i;
21
22 for (i = 0; i < len; i++) {
23 if ((i % 16) == 0)
6b44a439
NI
24 printf("%s%08x: ", i ? "\n" : "",
25 (unsigned int)&buf[i]);
26 printf("%02x ", buf[i]);
0b135cfc 27 }
6b44a439 28 printf("\n");
0b135cfc
NI
29}
30#endif
31
cf2c87d3
NI
32#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
09140113
SG
54int do_bootm_linux(int flag, int argc, char *const argv[],
55 bootm_headers_t *images)
0b135cfc 56{
6b44a439 57 /* Linux kernel load address */
c160a954 58 void (*kernel) (void) = (void (*)(void))images->ep;
6b44a439 59 /* empty_zero_page */
b5d10a13
NI
60 unsigned char *param
61 = (unsigned char *)image_get_load(images->legacy_hdr_os);
6b44a439 62 /* Linux kernel command line */
cf2c87d3 63 char *cmdline = (char *)param + COMMAND_LINE;
6b44a439 64 /* PAGE_SIZE */
b5d10a13 65 unsigned long size = images->ep - (unsigned long)param;
00caae6d 66 char *bootargs = env_get("bootargs");
0b135cfc 67
2cb0e55a
AB
68 /*
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
49c3a861
KG
74 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
75 return 1;
76
9980df56
NI
77 /* Clear zero page */
78 memset(param, 0, size);
cf2c87d3
NI
79
80 /* Set commandline */
6b44a439 81 strcpy(cmdline, bootargs);
b02bad12 82
cf2c87d3
NI
83 /* Initrd */
84 if (images->rd_start || images->rd_end) {
de03f8bc 85 unsigned long ramdisk_flags = 0;
cf2c87d3
NI
86 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;
071bc923 91
cf2c87d3
NI
92 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 */
0b135cfc 109 kernel();
cd7c596e 110
9980df56 111 /* does not return */
40d7e99d 112 return 1;
0b135cfc 113}