xref: /rk3399_rockchip-uboot/arch/microblaze/lib/bootm.c (revision a8425d52885de047fc00019cdf3e697b4d32b67a)
1ea0364f1SPeter Tyser /*
2ea0364f1SPeter Tyser  * (C) Copyright 2007 Michal Simek
3ea0364f1SPeter Tyser  * (C) Copyright 2004 Atmark Techno, Inc.
4ea0364f1SPeter Tyser  *
5ea0364f1SPeter Tyser  * Michal  SIMEK <monstr@monstr.eu>
6ea0364f1SPeter Tyser  * Yasushi SHOJI <yashi@atmark-techno.com>
7ea0364f1SPeter Tyser  *
8ea0364f1SPeter Tyser  * See file CREDITS for list of people who contributed to this
9ea0364f1SPeter Tyser  * project.
10ea0364f1SPeter Tyser  *
11ea0364f1SPeter Tyser  * This program is free software; you can redistribute it and/or
12ea0364f1SPeter Tyser  * modify it under the terms of the GNU General Public License as
13ea0364f1SPeter Tyser  * published by the Free Software Foundation; either version 2 of
14ea0364f1SPeter Tyser  * the License, or (at your option) any later version.
15ea0364f1SPeter Tyser  *
16ea0364f1SPeter Tyser  * This program is distributed in the hope that it will be useful,
17ea0364f1SPeter Tyser  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18ea0364f1SPeter Tyser  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
19ea0364f1SPeter Tyser  * GNU General Public License for more details.
20ea0364f1SPeter Tyser  *
21ea0364f1SPeter Tyser  * You should have received a copy of the GNU General Public License
22ea0364f1SPeter Tyser  * along with this program; if not, write to the Free Software
23ea0364f1SPeter Tyser  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24ea0364f1SPeter Tyser  * MA 02111-1307 USA
25ea0364f1SPeter Tyser  */
26ea0364f1SPeter Tyser 
27ea0364f1SPeter Tyser #include <common.h>
28ea0364f1SPeter Tyser #include <command.h>
29ea0364f1SPeter Tyser #include <image.h>
30ea0364f1SPeter Tyser #include <u-boot/zlib.h>
31ea0364f1SPeter Tyser #include <asm/byteorder.h>
32ea0364f1SPeter Tyser 
33ea0364f1SPeter Tyser DECLARE_GLOBAL_DATA_PTR;
34ea0364f1SPeter Tyser 
351e71fa43SMichal Simek int do_bootm_linux(int flag, int argc, char * const argv[],
361e71fa43SMichal Simek 		   bootm_headers_t *images)
37ea0364f1SPeter Tyser {
38ea0364f1SPeter Tyser 	/* First parameter is mapped to $r5 for kernel boot args */
391e71fa43SMichal Simek 	void	(*thekernel) (char *, ulong, ulong);
40ea0364f1SPeter Tyser 	char	*commandline = getenv("bootargs");
41398b1d57SArun Bhanu 	ulong	rd_data_start, rd_data_end;
42ea0364f1SPeter Tyser 
43ea0364f1SPeter Tyser 	if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
44ea0364f1SPeter Tyser 		return 1;
45ea0364f1SPeter Tyser 
46398b1d57SArun Bhanu 	int	ret;
47398b1d57SArun Bhanu 
48398b1d57SArun Bhanu 	char	*of_flat_tree = NULL;
49398b1d57SArun Bhanu #if defined(CONFIG_OF_LIBFDT)
505a75e121SJohn Rigby 	/* did generic code already find a device tree? */
515a75e121SJohn Rigby 	if (images->ft_len)
525a75e121SJohn Rigby 		of_flat_tree = images->ft_addr;
53398b1d57SArun Bhanu #endif
54398b1d57SArun Bhanu 
551e71fa43SMichal Simek 	thekernel = (void (*)(char *, ulong, ulong))images->ep;
56398b1d57SArun Bhanu 
57398b1d57SArun Bhanu 	/* find ramdisk */
58398b1d57SArun Bhanu 	ret = boot_get_ramdisk(argc, argv, images, IH_ARCH_MICROBLAZE,
59398b1d57SArun Bhanu 			&rd_data_start, &rd_data_end);
60398b1d57SArun Bhanu 	if (ret)
61398b1d57SArun Bhanu 		return 1;
62ea0364f1SPeter Tyser 
63770605e4SSimon Glass 	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
64ea0364f1SPeter Tyser 
655a75e121SJohn Rigby 	if (!of_flat_tree && argc > 3)
66398b1d57SArun Bhanu 		of_flat_tree = (char *)simple_strtoul(argv[3], NULL, 16);
67*a8425d52SMichal Simek 
68*a8425d52SMichal Simek 	/* fixup the initrd now that we know where it should be */
69*a8425d52SMichal Simek 	if (images->rd_start && images->rd_end && of_flat_tree)
70*a8425d52SMichal Simek 		ret = fdt_initrd(of_flat_tree, images->rd_start,
71*a8425d52SMichal Simek 				 images->rd_end, 1);
72*a8425d52SMichal Simek 		if (ret)
73*a8425d52SMichal Simek 			return 1;
74*a8425d52SMichal Simek 
75ea0364f1SPeter Tyser #ifdef DEBUG
761e71fa43SMichal Simek 	printf("## Transferring control to Linux (at address 0x%08lx) ",
771e71fa43SMichal Simek 	       (ulong)thekernel);
781e71fa43SMichal Simek 	printf("ramdisk 0x%08lx, FDT 0x%08lx...\n",
791e71fa43SMichal Simek 	       rd_data_start, (ulong) of_flat_tree);
80ea0364f1SPeter Tyser #endif
81ea0364f1SPeter Tyser 
829b4d9056SMichal Simek #ifdef XILINX_USE_DCACHE
839b4d9056SMichal Simek 	flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
849b4d9056SMichal Simek #endif
85398b1d57SArun Bhanu 	/*
86398b1d57SArun Bhanu 	 * Linux Kernel Parameters (passing device tree):
87398b1d57SArun Bhanu 	 * r5: pointer to command line
88398b1d57SArun Bhanu 	 * r6: pointer to ramdisk
89398b1d57SArun Bhanu 	 * r7: pointer to the fdt, followed by the board info data
90398b1d57SArun Bhanu 	 */
911e71fa43SMichal Simek 	thekernel(commandline, rd_data_start, (ulong)of_flat_tree);
92ea0364f1SPeter Tyser 	/* does not return */
93ea0364f1SPeter Tyser 
94ea0364f1SPeter Tyser 	return 1;
95ea0364f1SPeter Tyser }
96