blob: ec332944d8e81cd881f5cd37f818367ed758133a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk507bbe32004-04-18 21:13:41 +00002/*
Michal Simekcfc67112007-03-11 13:48:24 +01003 * (C) Copyright 2007 Michal Simek
wdenk507bbe32004-04-18 21:13:41 +00004 * (C) Copyright 2004 Atmark Techno, Inc.
5 *
Michal Simekcfc67112007-03-11 13:48:24 +01006 * Michal SIMEK <monstr@monstr.eu>
wdenk507bbe32004-04-18 21:13:41 +00007 * Yasushi SHOJI <yashi@atmark-techno.com>
wdenk507bbe32004-04-18 21:13:41 +00008 */
9
10#include <common.h>
11#include <command.h>
Simon Glass7b51b572019-08-01 09:46:52 -060012#include <env.h>
Simon Glass73223f02016-02-22 22:55:43 -070013#include <fdt_support.h>
Michal Simekcfc67112007-03-11 13:48:24 +010014#include <image.h>
Jean-Christophe PLAGNIOL-VILLARDa31e0912009-04-04 12:49:11 +020015#include <u-boot/zlib.h>
Michal Simekcfc67112007-03-11 13:48:24 +010016#include <asm/byteorder.h>
wdenk507bbe32004-04-18 21:13:41 +000017
Michal Simek1e71fa42013-05-02 12:51:48 +020018int do_bootm_linux(int flag, int argc, char * const argv[],
19 bootm_headers_t *images)
wdenk507bbe32004-04-18 21:13:41 +000020{
Michal Simekcfc67112007-03-11 13:48:24 +010021 /* First parameter is mapped to $r5 for kernel boot args */
Michal Simek1e71fa42013-05-02 12:51:48 +020022 void (*thekernel) (char *, ulong, ulong);
Simon Glass00caae62017-08-03 12:22:12 -060023 char *commandline = env_get("bootargs");
Arun Bhanu398b1d52010-04-15 18:27:17 +080024 ulong rd_data_start, rd_data_end;
Michal Simekcfc67112007-03-11 13:48:24 +010025
Andreas Bießmann2cb0e552013-07-02 13:57:44 +020026 /*
27 * allow the PREP bootm subcommand, it is required for bootm to work
28 */
29 if (flag & BOOTM_STATE_OS_PREP)
30 return 0;
31
Kumar Gala49c3a862008-10-21 17:25:45 -050032 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
33 return 1;
34
Arun Bhanu398b1d52010-04-15 18:27:17 +080035 int ret;
36
37 char *of_flat_tree = NULL;
38#if defined(CONFIG_OF_LIBFDT)
John Rigby5a75e122010-10-13 13:57:34 -060039 /* did generic code already find a device tree? */
40 if (images->ft_len)
41 of_flat_tree = images->ft_addr;
Arun Bhanu398b1d52010-04-15 18:27:17 +080042#endif
43
Michal Simek1e71fa42013-05-02 12:51:48 +020044 thekernel = (void (*)(char *, ulong, ulong))images->ep;
Arun Bhanu398b1d52010-04-15 18:27:17 +080045
46 /* find ramdisk */
Michal Simek1e71fa42013-05-02 12:51:48 +020047 ret = boot_get_ramdisk(argc, argv, images, IH_ARCH_MICROBLAZE,
Arun Bhanu398b1d52010-04-15 18:27:17 +080048 &rd_data_start, &rd_data_end);
49 if (ret)
50 return 1;
Michal Simekcfc67112007-03-11 13:48:24 +010051
Simon Glass770605e2012-02-13 13:51:18 +000052 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Michal Simekcfc67112007-03-11 13:48:24 +010053
Simon Glass983c72f2013-06-11 11:14:46 -070054 if (!of_flat_tree && argc > 1)
55 of_flat_tree = (char *)simple_strtoul(argv[1], NULL, 16);
Michal Simeka8425d52013-05-02 12:49:18 +020056
57 /* fixup the initrd now that we know where it should be */
Bin Meng244ce782018-02-12 17:54:37 +080058 if (images->rd_start && images->rd_end && of_flat_tree) {
Michal Simeka8425d52013-05-02 12:49:18 +020059 ret = fdt_initrd(of_flat_tree, images->rd_start,
Masahiro Yamadadbe963a2014-04-18 17:40:59 +090060 images->rd_end);
Michal Simeka8425d52013-05-02 12:49:18 +020061 if (ret)
62 return 1;
Bin Meng244ce782018-02-12 17:54:37 +080063 }
Michal Simeka8425d52013-05-02 12:49:18 +020064
Michal Simekcfc67112007-03-11 13:48:24 +010065#ifdef DEBUG
Michal Simek1e71fa42013-05-02 12:51:48 +020066 printf("## Transferring control to Linux (at address 0x%08lx) ",
67 (ulong)thekernel);
68 printf("ramdisk 0x%08lx, FDT 0x%08lx...\n",
69 rd_data_start, (ulong) of_flat_tree);
Michal Simekcfc67112007-03-11 13:48:24 +010070#endif
71
Michal Simek9b4d9052010-04-16 12:01:32 +020072#ifdef XILINX_USE_DCACHE
Michal Simek9b4d9052010-04-16 12:01:32 +020073 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek9b4d9052010-04-16 12:01:32 +020074#endif
Arun Bhanu398b1d52010-04-15 18:27:17 +080075 /*
76 * Linux Kernel Parameters (passing device tree):
77 * r5: pointer to command line
78 * r6: pointer to ramdisk
79 * r7: pointer to the fdt, followed by the board info data
80 */
Michal Simek1e71fa42013-05-02 12:51:48 +020081 thekernel(commandline, rd_data_start, (ulong)of_flat_tree);
Marian Balakowiczcd7c5962008-03-12 10:33:00 +010082 /* does not return */
Jean-Christophe PLAGNIOL-VILLARDa3a08c02008-09-10 22:48:09 +020083
Kumar Gala40d7e992008-08-15 08:24:45 -050084 return 1;
wdenk507bbe32004-04-18 21:13:41 +000085}