blob: a74f1d1e559cac217f05e8eca08cd39c6f0af24d [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 Glass0af6e2d2019-08-01 09:46:52 -060012#include <env.h>
Simon Glasse3ee2fb2016-02-22 22:55:43 -070013#include <fdt_support.h>
Michal Simek922ce202007-03-11 13:48:24 +010014#include <image.h>
Jean-Christophe PLAGNIOL-VILLARD6bb94492009-04-04 12:49:11 +020015#include <u-boot/zlib.h>
Michal Simek922ce202007-03-11 13:48:24 +010016#include <asm/byteorder.h>
wdenk12490652004-04-18 21:13:41 +000017
Michal Simek040872e2019-09-25 10:45:51 +020018DECLARE_GLOBAL_DATA_PTR;
19
20static ulong get_sp(void)
21{
22 ulong ret;
23
24 asm("addik %0, r1, 0" : "=r"(ret) : );
25 return ret;
26}
27
28void arch_lmb_reserve(struct lmb *lmb)
29{
30 ulong sp, bank_end;
31 int bank;
32
33 /*
34 * Booting a (Linux) kernel image
35 *
36 * Allocate space for command line and board info - the
37 * address should be as high as possible within the reach of
38 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
39 * memory, which means far enough below the current stack
40 * pointer.
41 */
42 sp = get_sp();
43 debug("## Current stack ends at 0x%08lx ", sp);
44
45 /* adjust sp by 4K to be safe */
46 sp -= 4096;
47 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
48 if (sp < gd->bd->bi_dram[bank].start)
49 continue;
50 bank_end = gd->bd->bi_dram[bank].start +
51 gd->bd->bi_dram[bank].size;
52 if (sp >= bank_end)
53 continue;
54 lmb_reserve(lmb, sp, bank_end - sp);
55 break;
56 }
57}
58
Michal Simekc78ce292013-05-02 12:51:48 +020059int do_bootm_linux(int flag, int argc, char * const argv[],
60 bootm_headers_t *images)
wdenk12490652004-04-18 21:13:41 +000061{
Michal Simek922ce202007-03-11 13:48:24 +010062 /* First parameter is mapped to $r5 for kernel boot args */
Michal Simekc78ce292013-05-02 12:51:48 +020063 void (*thekernel) (char *, ulong, ulong);
Simon Glass64b723f2017-08-03 12:22:12 -060064 char *commandline = env_get("bootargs");
Arun Bhanu2304c052010-04-15 18:27:17 +080065 ulong rd_data_start, rd_data_end;
Michal Simek922ce202007-03-11 13:48:24 +010066
Andreas Bießmannda233ce2013-07-02 13:57:44 +020067 /*
68 * allow the PREP bootm subcommand, it is required for bootm to work
69 */
70 if (flag & BOOTM_STATE_OS_PREP)
71 return 0;
72
Kumar Gala18178bc2008-10-21 17:25:45 -050073 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
74 return 1;
75
Arun Bhanu2304c052010-04-15 18:27:17 +080076 int ret;
77
78 char *of_flat_tree = NULL;
79#if defined(CONFIG_OF_LIBFDT)
John Rigby708e6672010-10-13 13:57:34 -060080 /* did generic code already find a device tree? */
81 if (images->ft_len)
82 of_flat_tree = images->ft_addr;
Arun Bhanu2304c052010-04-15 18:27:17 +080083#endif
84
Michal Simekc78ce292013-05-02 12:51:48 +020085 thekernel = (void (*)(char *, ulong, ulong))images->ep;
Arun Bhanu2304c052010-04-15 18:27:17 +080086
87 /* find ramdisk */
Michal Simekc78ce292013-05-02 12:51:48 +020088 ret = boot_get_ramdisk(argc, argv, images, IH_ARCH_MICROBLAZE,
Arun Bhanu2304c052010-04-15 18:27:17 +080089 &rd_data_start, &rd_data_end);
90 if (ret)
91 return 1;
Michal Simek922ce202007-03-11 13:48:24 +010092
Simon Glass0169e6b2012-02-13 13:51:18 +000093 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Michal Simek922ce202007-03-11 13:48:24 +010094
Simon Glass794a9212013-06-11 11:14:46 -070095 if (!of_flat_tree && argc > 1)
96 of_flat_tree = (char *)simple_strtoul(argv[1], NULL, 16);
Michal Simek70b1c492013-05-02 12:49:18 +020097
98 /* fixup the initrd now that we know where it should be */
Bin Menge7289832018-02-12 17:54:37 +080099 if (images->rd_start && images->rd_end && of_flat_tree) {
Michal Simek70b1c492013-05-02 12:49:18 +0200100 ret = fdt_initrd(of_flat_tree, images->rd_start,
Masahiro Yamada5b114892014-04-18 17:40:59 +0900101 images->rd_end);
Michal Simek70b1c492013-05-02 12:49:18 +0200102 if (ret)
103 return 1;
Bin Menge7289832018-02-12 17:54:37 +0800104 }
Michal Simek70b1c492013-05-02 12:49:18 +0200105
Michal Simek922ce202007-03-11 13:48:24 +0100106#ifdef DEBUG
Michal Simekc78ce292013-05-02 12:51:48 +0200107 printf("## Transferring control to Linux (at address 0x%08lx) ",
108 (ulong)thekernel);
109 printf("ramdisk 0x%08lx, FDT 0x%08lx...\n",
110 rd_data_start, (ulong) of_flat_tree);
Michal Simek922ce202007-03-11 13:48:24 +0100111#endif
112
Michal Simek80c42c72010-04-16 12:01:32 +0200113#ifdef XILINX_USE_DCACHE
Michal Simek80c42c72010-04-16 12:01:32 +0200114 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek80c42c72010-04-16 12:01:32 +0200115#endif
Arun Bhanu2304c052010-04-15 18:27:17 +0800116 /*
117 * Linux Kernel Parameters (passing device tree):
118 * r5: pointer to command line
119 * r6: pointer to ramdisk
120 * r7: pointer to the fdt, followed by the board info data
121 */
Michal Simekc78ce292013-05-02 12:51:48 +0200122 thekernel(commandline, rd_data_start, (ulong)of_flat_tree);
Marian Balakowiczdf8ff332008-03-12 10:33:00 +0100123 /* does not return */
Jean-Christophe PLAGNIOL-VILLARD7ed7a272008-09-10 22:48:09 +0200124
Kumar Gala48626aa2008-08-15 08:24:45 -0500125 return 1;
wdenk12490652004-04-18 21:13:41 +0000126}