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