blob: efd5acf3592bb5f8fa8747882d67145d95b0ef4b [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 Glass1eb69ae2019-11-14 12:57:39 -070012#include <cpu_func.h>
Simon Glass7b51b572019-08-01 09:46:52 -060013#include <env.h>
Simon Glass73223f02016-02-22 22:55:43 -070014#include <fdt_support.h>
Michal Simekcfc67112007-03-11 13:48:24 +010015#include <image.h>
Jean-Christophe PLAGNIOL-VILLARDa31e0912009-04-04 12:49:11 +020016#include <u-boot/zlib.h>
Michal Simekcfc67112007-03-11 13:48:24 +010017#include <asm/byteorder.h>
wdenk507bbe32004-04-18 21:13:41 +000018
Michal Simek6131a362019-09-25 10:45:51 +020019DECLARE_GLOBAL_DATA_PTR;
20
21static ulong get_sp(void)
22{
23 ulong ret;
24
25 asm("addik %0, r1, 0" : "=r"(ret) : );
26 return ret;
27}
28
29void arch_lmb_reserve(struct lmb *lmb)
30{
31 ulong sp, bank_end;
32 int bank;
33
34 /*
35 * Booting a (Linux) kernel image
36 *
37 * Allocate space for command line and board info - the
38 * address should be as high as possible within the reach of
39 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
40 * memory, which means far enough below the current stack
41 * pointer.
42 */
43 sp = get_sp();
44 debug("## Current stack ends at 0x%08lx ", sp);
45
46 /* adjust sp by 4K to be safe */
47 sp -= 4096;
48 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
49 if (sp < gd->bd->bi_dram[bank].start)
50 continue;
51 bank_end = gd->bd->bi_dram[bank].start +
52 gd->bd->bi_dram[bank].size;
53 if (sp >= bank_end)
54 continue;
55 lmb_reserve(lmb, sp, bank_end - sp);
56 break;
57 }
58}
59
Michal Simek09050462019-09-25 09:47:02 +020060static void boot_jump_linux(bootm_headers_t *images, int flag)
wdenk507bbe32004-04-18 21:13:41 +000061{
Michal Simek09050462019-09-25 09:47:02 +020062 void (*thekernel)(char *cmdline, ulong rd, ulong dt);
63 ulong dt = (ulong)images->ft_addr;
64 ulong rd_start = images->initrd_start;
65 ulong cmdline = images->cmdline_start;
66 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
Arun Bhanu398b1d52010-04-15 18:27:17 +080067
Michal Simek1e71fa42013-05-02 12:51:48 +020068 thekernel = (void (*)(char *, ulong, ulong))images->ep;
Arun Bhanu398b1d52010-04-15 18:27:17 +080069
Michal Simekf3035cf2019-10-17 13:16:56 +020070 debug("## Transferring control to Linux (at address 0x%08lx) ",
71 (ulong)thekernel);
72 debug("cmdline 0x%08lx, ramdisk 0x%08lx, FDT 0x%08lx...\n",
73 cmdline, rd_start, dt);
74 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
75
76 printf("\nStarting kernel ...%s\n\n", fake ?
77 "(fake run for tracing)" : "");
78 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
Michal Simekcfc67112007-03-11 13:48:24 +010079
Michal Simek9b4d9052010-04-16 12:01:32 +020080#ifdef XILINX_USE_DCACHE
Michal Simek9b4d9052010-04-16 12:01:32 +020081 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek9b4d9052010-04-16 12:01:32 +020082#endif
Jean-Christophe PLAGNIOL-VILLARDa3a08c02008-09-10 22:48:09 +020083
Michal Simek09050462019-09-25 09:47:02 +020084 if (!fake) {
85 /*
86 * Linux Kernel Parameters (passing device tree):
87 * r5: pointer to command line
88 * r6: pointer to ramdisk
89 * r7: pointer to the fdt, followed by the board info data
90 */
91 thekernel((char *)cmdline, rd_start, dt);
92 /* does not return */
93 }
94}
95
96static void boot_prep_linux(bootm_headers_t *images)
97{
98 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
Michal Simek4ab8d632019-10-17 14:12:48 +020099 debug("using: FDT\n");
Michal Simek09050462019-09-25 09:47:02 +0200100 if (image_setup_linux(images)) {
101 printf("FDT creation failed! hanging...");
102 hang();
103 }
104 }
105}
106
107int do_bootm_linux(int flag, int argc, char * const argv[],
108 bootm_headers_t *images)
109{
110 images->cmdline_start = (ulong)env_get("bootargs");
111
112 /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */
113 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
114 return -1;
115
116 if (flag & BOOTM_STATE_OS_PREP) {
117 boot_prep_linux(images);
118 return 0;
119 }
120
121 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
122 boot_jump_linux(images, flag);
123 return 0;
124 }
125
126 boot_prep_linux(images);
127 boot_jump_linux(images, flag);
Kumar Gala40d7e992008-08-15 08:24:45 -0500128 return 1;
wdenk507bbe32004-04-18 21:13:41 +0000129}