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