xref: /rk3399_rockchip-uboot/arch/microblaze/lib/bootm.c (revision 2cb0e55a3cd737be1d228a9f90b3d34fab0d0d46)
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 
43*2cb0e55aSAndreas Bießmann 	/*
44*2cb0e55aSAndreas Bießmann 	 * allow the PREP bootm subcommand, it is required for bootm to work
45*2cb0e55aSAndreas Bießmann 	 */
46*2cb0e55aSAndreas Bießmann 	if (flag & BOOTM_STATE_OS_PREP)
47*2cb0e55aSAndreas Bießmann 		return 0;
48*2cb0e55aSAndreas Bießmann 
49ea0364f1SPeter Tyser 	if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
50ea0364f1SPeter Tyser 		return 1;
51ea0364f1SPeter Tyser 
52398b1d57SArun Bhanu 	int	ret;
53398b1d57SArun Bhanu 
54398b1d57SArun Bhanu 	char	*of_flat_tree = NULL;
55398b1d57SArun Bhanu #if defined(CONFIG_OF_LIBFDT)
565a75e121SJohn Rigby 	/* did generic code already find a device tree? */
575a75e121SJohn Rigby 	if (images->ft_len)
585a75e121SJohn Rigby 		of_flat_tree = images->ft_addr;
59398b1d57SArun Bhanu #endif
60398b1d57SArun Bhanu 
611e71fa43SMichal Simek 	thekernel = (void (*)(char *, ulong, ulong))images->ep;
62398b1d57SArun Bhanu 
63398b1d57SArun Bhanu 	/* find ramdisk */
64398b1d57SArun Bhanu 	ret = boot_get_ramdisk(argc, argv, images, IH_ARCH_MICROBLAZE,
65398b1d57SArun Bhanu 			&rd_data_start, &rd_data_end);
66398b1d57SArun Bhanu 	if (ret)
67398b1d57SArun Bhanu 		return 1;
68ea0364f1SPeter Tyser 
69770605e4SSimon Glass 	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
70ea0364f1SPeter Tyser 
71983c72f4SSimon Glass 	if (!of_flat_tree && argc > 1)
72983c72f4SSimon Glass 		of_flat_tree = (char *)simple_strtoul(argv[1], NULL, 16);
73a8425d52SMichal Simek 
74a8425d52SMichal Simek 	/* fixup the initrd now that we know where it should be */
75a8425d52SMichal Simek 	if (images->rd_start && images->rd_end && of_flat_tree)
76a8425d52SMichal Simek 		ret = fdt_initrd(of_flat_tree, images->rd_start,
77a8425d52SMichal Simek 				 images->rd_end, 1);
78a8425d52SMichal Simek 		if (ret)
79a8425d52SMichal Simek 			return 1;
80a8425d52SMichal Simek 
81ea0364f1SPeter Tyser #ifdef DEBUG
821e71fa43SMichal Simek 	printf("## Transferring control to Linux (at address 0x%08lx) ",
831e71fa43SMichal Simek 	       (ulong)thekernel);
841e71fa43SMichal Simek 	printf("ramdisk 0x%08lx, FDT 0x%08lx...\n",
851e71fa43SMichal Simek 	       rd_data_start, (ulong) of_flat_tree);
86ea0364f1SPeter Tyser #endif
87ea0364f1SPeter Tyser 
889b4d9056SMichal Simek #ifdef XILINX_USE_DCACHE
899b4d9056SMichal Simek 	flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
909b4d9056SMichal Simek #endif
91398b1d57SArun Bhanu 	/*
92398b1d57SArun Bhanu 	 * Linux Kernel Parameters (passing device tree):
93398b1d57SArun Bhanu 	 * r5: pointer to command line
94398b1d57SArun Bhanu 	 * r6: pointer to ramdisk
95398b1d57SArun Bhanu 	 * r7: pointer to the fdt, followed by the board info data
96398b1d57SArun Bhanu 	 */
971e71fa43SMichal Simek 	thekernel(commandline, rd_data_start, (ulong)of_flat_tree);
98ea0364f1SPeter Tyser 	/* does not return */
99ea0364f1SPeter Tyser 
100ea0364f1SPeter Tyser 	return 1;
101ea0364f1SPeter Tyser }
102