blob: 083a43c3a5c74de6b05adaab8f8a275b478f9559 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk12490652004-04-18 21:13:41 +00002/*
Michal Simek922ce202007-03-11 13:48:24 +01003 * (C) Copyright 2007 Michal Simek
wdenk12490652004-04-18 21:13:41 +00004 * (C) Copyright 2004 Atmark Techno, Inc.
5 *
Michal Simek922ce202007-03-11 13:48:24 +01006 * Michal SIMEK <monstr@monstr.eu>
wdenk12490652004-04-18 21:13:41 +00007 * Yasushi SHOJI <yashi@atmark-techno.com>
wdenk12490652004-04-18 21:13:41 +00008 */
9
10#include <common.h>
11#include <command.h>
Simon Glasse3ee2fb2016-02-22 22:55:43 -070012#include <fdt_support.h>
Michal Simek922ce202007-03-11 13:48:24 +010013#include <image.h>
Jean-Christophe PLAGNIOL-VILLARD6bb94492009-04-04 12:49:11 +020014#include <u-boot/zlib.h>
Michal Simek922ce202007-03-11 13:48:24 +010015#include <asm/byteorder.h>
wdenk12490652004-04-18 21:13:41 +000016
Michal Simekc78ce292013-05-02 12:51:48 +020017int do_bootm_linux(int flag, int argc, char * const argv[],
18 bootm_headers_t *images)
wdenk12490652004-04-18 21:13:41 +000019{
Michal Simek922ce202007-03-11 13:48:24 +010020 /* First parameter is mapped to $r5 for kernel boot args */
Michal Simekc78ce292013-05-02 12:51:48 +020021 void (*thekernel) (char *, ulong, ulong);
Simon Glass64b723f2017-08-03 12:22:12 -060022 char *commandline = env_get("bootargs");
Arun Bhanu2304c052010-04-15 18:27:17 +080023 ulong rd_data_start, rd_data_end;
Michal Simek922ce202007-03-11 13:48:24 +010024
Andreas Bießmannda233ce2013-07-02 13:57:44 +020025 /*
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
Kumar Gala18178bc2008-10-21 17:25:45 -050031 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
32 return 1;
33
Arun Bhanu2304c052010-04-15 18:27:17 +080034 int ret;
35
36 char *of_flat_tree = NULL;
37#if defined(CONFIG_OF_LIBFDT)
John Rigby708e6672010-10-13 13:57:34 -060038 /* did generic code already find a device tree? */
39 if (images->ft_len)
40 of_flat_tree = images->ft_addr;
Arun Bhanu2304c052010-04-15 18:27:17 +080041#endif
42
Michal Simekc78ce292013-05-02 12:51:48 +020043 thekernel = (void (*)(char *, ulong, ulong))images->ep;
Arun Bhanu2304c052010-04-15 18:27:17 +080044
45 /* find ramdisk */
Michal Simekc78ce292013-05-02 12:51:48 +020046 ret = boot_get_ramdisk(argc, argv, images, IH_ARCH_MICROBLAZE,
Arun Bhanu2304c052010-04-15 18:27:17 +080047 &rd_data_start, &rd_data_end);
48 if (ret)
49 return 1;
Michal Simek922ce202007-03-11 13:48:24 +010050
Simon Glass0169e6b2012-02-13 13:51:18 +000051 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Michal Simek922ce202007-03-11 13:48:24 +010052
Simon Glass794a9212013-06-11 11:14:46 -070053 if (!of_flat_tree && argc > 1)
54 of_flat_tree = (char *)simple_strtoul(argv[1], NULL, 16);
Michal Simek70b1c492013-05-02 12:49:18 +020055
56 /* fixup the initrd now that we know where it should be */
Bin Menge7289832018-02-12 17:54:37 +080057 if (images->rd_start && images->rd_end && of_flat_tree) {
Michal Simek70b1c492013-05-02 12:49:18 +020058 ret = fdt_initrd(of_flat_tree, images->rd_start,
Masahiro Yamada5b114892014-04-18 17:40:59 +090059 images->rd_end);
Michal Simek70b1c492013-05-02 12:49:18 +020060 if (ret)
61 return 1;
Bin Menge7289832018-02-12 17:54:37 +080062 }
Michal Simek70b1c492013-05-02 12:49:18 +020063
Michal Simek922ce202007-03-11 13:48:24 +010064#ifdef DEBUG
Michal Simekc78ce292013-05-02 12:51:48 +020065 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);
Michal Simek922ce202007-03-11 13:48:24 +010069#endif
70
Michal Simek80c42c72010-04-16 12:01:32 +020071#ifdef XILINX_USE_DCACHE
Michal Simek80c42c72010-04-16 12:01:32 +020072 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek80c42c72010-04-16 12:01:32 +020073#endif
Arun Bhanu2304c052010-04-15 18:27:17 +080074 /*
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 */
Michal Simekc78ce292013-05-02 12:51:48 +020080 thekernel(commandline, rd_data_start, (ulong)of_flat_tree);
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010081 /* does not return */
Jean-Christophe PLAGNIOL-VILLARD7ed7a272008-09-10 22:48:09 +020082
Kumar Gala48626aa2008-08-15 08:24:45 -050083 return 1;
wdenk12490652004-04-18 21:13:41 +000084}