1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
3*4882a593Smuzhiyun * Scott McNutt <smcnutt@psyent.com>
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <common.h>
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #define NIOS_MAGIC 0x534f494e /* enable command line and initrd passing */
11*4882a593Smuzhiyun
do_bootm_linux(int flag,int argc,char * const argv[],bootm_headers_t * images)12*4882a593Smuzhiyun int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images)
13*4882a593Smuzhiyun {
14*4882a593Smuzhiyun void (*kernel)(int, int, int, char *) = (void *)images->ep;
15*4882a593Smuzhiyun char *commandline = env_get("bootargs");
16*4882a593Smuzhiyun ulong initrd_start = images->rd_start;
17*4882a593Smuzhiyun ulong initrd_end = images->rd_end;
18*4882a593Smuzhiyun char *of_flat_tree = NULL;
19*4882a593Smuzhiyun #if defined(CONFIG_OF_LIBFDT)
20*4882a593Smuzhiyun /* did generic code already find a device tree? */
21*4882a593Smuzhiyun if (images->ft_len)
22*4882a593Smuzhiyun of_flat_tree = images->ft_addr;
23*4882a593Smuzhiyun #endif
24*4882a593Smuzhiyun if (!of_flat_tree && argc > 1)
25*4882a593Smuzhiyun of_flat_tree = (char *)simple_strtoul(argv[1], NULL, 16);
26*4882a593Smuzhiyun if (of_flat_tree)
27*4882a593Smuzhiyun initrd_end = (ulong)of_flat_tree;
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /*
30*4882a593Smuzhiyun * allow the PREP bootm subcommand, it is required for bootm to work
31*4882a593Smuzhiyun */
32*4882a593Smuzhiyun if (flag & BOOTM_STATE_OS_PREP)
33*4882a593Smuzhiyun return 0;
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
36*4882a593Smuzhiyun return 1;
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /* flushes data and instruction caches before calling the kernel */
39*4882a593Smuzhiyun disable_interrupts();
40*4882a593Smuzhiyun flush_dcache_all();
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun debug("bootargs=%s @ 0x%lx\n", commandline, (ulong)&commandline);
43*4882a593Smuzhiyun debug("initrd=0x%lx-0x%lx\n", (ulong)initrd_start, (ulong)initrd_end);
44*4882a593Smuzhiyun /* kernel parameters passing
45*4882a593Smuzhiyun * r4 : NIOS magic
46*4882a593Smuzhiyun * r5 : initrd start
47*4882a593Smuzhiyun * r6 : initrd end or fdt
48*4882a593Smuzhiyun * r7 : kernel command line
49*4882a593Smuzhiyun * fdt is passed to kernel via r6, the same as initrd_end. fdt will be
50*4882a593Smuzhiyun * verified with fdt magic. when both initrd and fdt are used at the
51*4882a593Smuzhiyun * same time, fdt must follow immediately after initrd.
52*4882a593Smuzhiyun */
53*4882a593Smuzhiyun kernel(NIOS_MAGIC, initrd_start, initrd_end, commandline);
54*4882a593Smuzhiyun /* does not return */
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun return 1;
57*4882a593Smuzhiyun }
58