blob: 11e534715d15530d9c14170c2a79cbc04cd563c3 [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 Simeke37afb52019-09-25 09:47:02 +020059static void boot_jump_linux(bootm_headers_t *images, int flag)
wdenk12490652004-04-18 21:13:41 +000060{
Michal Simeke37afb52019-09-25 09:47:02 +020061 void (*thekernel)(char *cmdline, ulong rd, ulong dt);
62 ulong dt = (ulong)images->ft_addr;
63 ulong rd_start = images->initrd_start;
64 ulong cmdline = images->cmdline_start;
65 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
Arun Bhanu2304c052010-04-15 18:27:17 +080066
Michal Simekc78ce292013-05-02 12:51:48 +020067 thekernel = (void (*)(char *, ulong, ulong))images->ep;
Arun Bhanu2304c052010-04-15 18:27:17 +080068
Michal Simek922ce202007-03-11 13:48:24 +010069#ifdef DEBUG
Michal Simekc78ce292013-05-02 12:51:48 +020070 printf("## Transferring control to Linux (at address 0x%08lx) ",
71 (ulong)thekernel);
Michal Simeke37afb52019-09-25 09:47:02 +020072 printf("cmdline 0x%08lx, ramdisk 0x%08lx, FDT 0x%08lx...\n",
73 cmdline, rd_start, dt);
Michal Simek922ce202007-03-11 13:48:24 +010074#endif
75
Michal Simek80c42c72010-04-16 12:01:32 +020076#ifdef XILINX_USE_DCACHE
Michal Simek80c42c72010-04-16 12:01:32 +020077 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek80c42c72010-04-16 12:01:32 +020078#endif
Michal Simeke37afb52019-09-25 09:47:02 +020079
80 if (!fake) {
81 /*
82 * Linux Kernel Parameters (passing device tree):
83 * r5: pointer to command line
84 * r6: pointer to ramdisk
85 * r7: pointer to the fdt, followed by the board info data
86 */
87 thekernel((char *)cmdline, rd_start, dt);
88 /* does not return */
89 }
90}
91
92static void boot_prep_linux(bootm_headers_t *images)
93{
94 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
95 printf("using: FDT\n");
96 if (image_setup_linux(images)) {
97 printf("FDT creation failed! hanging...");
98 hang();
99 }
100 }
101}
102
103int do_bootm_linux(int flag, int argc, char * const argv[],
104 bootm_headers_t *images)
105{
106 images->cmdline_start = (ulong)env_get("bootargs");
107
108 /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */
109 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
110 return -1;
111
112 if (flag & BOOTM_STATE_OS_PREP) {
113 boot_prep_linux(images);
114 return 0;
115 }
116
117 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
118 boot_jump_linux(images, flag);
119 return 0;
120 }
Jean-Christophe PLAGNIOL-VILLARD7ed7a272008-09-10 22:48:09 +0200121
Michal Simeke37afb52019-09-25 09:47:02 +0200122 boot_prep_linux(images);
123 boot_jump_linux(images, flag);
Kumar Gala48626aa2008-08-15 08:24:45 -0500124 return 1;
wdenk12490652004-04-18 21:13:41 +0000125}