1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2007 Michal Simek
4 * (C) Copyright 2004 Atmark Techno, Inc.
5 *
6 * Michal SIMEK <monstr@monstr.eu>
7 * Yasushi SHOJI <yashi@atmark-techno.com>
8 */
9
10 #include <common.h>
11 #include <command.h>
12 #include <fdt_support.h>
13 #include <image.h>
14 #include <u-boot/zlib.h>
15 #include <asm/byteorder.h>
16
do_bootm_linux(int flag,int argc,char * const argv[],bootm_headers_t * images)17 int do_bootm_linux(int flag, int argc, char * const argv[],
18 bootm_headers_t *images)
19 {
20 /* First parameter is mapped to $r5 for kernel boot args */
21 void (*thekernel) (char *, ulong, ulong);
22 char *commandline = env_get("bootargs");
23 ulong rd_data_start, rd_data_end;
24
25 /*
26 * allow the PREP bootm subcommand, it is required for bootm to work
27 */
28 if (flag & BOOTM_STATE_OS_PREP)
29 return 0;
30
31 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
32 return 1;
33
34 int ret;
35
36 char *of_flat_tree = NULL;
37 #if defined(CONFIG_OF_LIBFDT)
38 /* did generic code already find a device tree? */
39 if (images->ft_len)
40 of_flat_tree = images->ft_addr;
41 #endif
42
43 thekernel = (void (*)(char *, ulong, ulong))images->ep;
44
45 /* find ramdisk */
46 ret = boot_get_ramdisk(argc, argv, images, IH_ARCH_MICROBLAZE,
47 &rd_data_start, &rd_data_end);
48 if (ret)
49 return 1;
50
51 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
52
53 if (!of_flat_tree && argc > 1)
54 of_flat_tree = (char *)simple_strtoul(argv[1], NULL, 16);
55
56 /* fixup the initrd now that we know where it should be */
57 if (images->rd_start && images->rd_end && of_flat_tree) {
58 ret = fdt_initrd(of_flat_tree, images->rd_start,
59 images->rd_end);
60 if (ret)
61 return 1;
62 }
63
64 #ifdef DEBUG
65 printf("## Transferring control to Linux (at address 0x%08lx) ",
66 (ulong)thekernel);
67 printf("ramdisk 0x%08lx, FDT 0x%08lx...\n",
68 rd_data_start, (ulong) of_flat_tree);
69 #endif
70
71 #ifdef XILINX_USE_DCACHE
72 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
73 #endif
74 /*
75 * Linux Kernel Parameters (passing device tree):
76 * r5: pointer to command line
77 * r6: pointer to ramdisk
78 * r7: pointer to the fdt, followed by the board info data
79 */
80 thekernel(commandline, rd_data_start, (ulong)of_flat_tree);
81 /* does not return */
82
83 return 1;
84 }
85