blob: 12ea32488e69ae7d67493d0ea2e08c96c2a7a25e [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>
Simon Glass1ea97892020-05-10 11:40:00 -060011#include <bootstage.h>
wdenk12490652004-04-18 21:13:41 +000012#include <command.h>
Simon Glass63334482019-11-14 12:57:39 -070013#include <cpu_func.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060014#include <env.h>
Simon Glasse3ee2fb2016-02-22 22:55:43 -070015#include <fdt_support.h>
Simon Glassf11478f2019-12-28 10:45:07 -070016#include <hang.h>
Michal Simek922ce202007-03-11 13:48:24 +010017#include <image.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060018#include <lmb.h>
Simon Glass0f2af882020-05-10 11:40:05 -060019#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060020#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060021#include <asm/global_data.h>
Jean-Christophe PLAGNIOL-VILLARD6bb94492009-04-04 12:49:11 +020022#include <u-boot/zlib.h>
Michal Simek922ce202007-03-11 13:48:24 +010023#include <asm/byteorder.h>
wdenk12490652004-04-18 21:13:41 +000024
Michal Simek040872e2019-09-25 10:45:51 +020025DECLARE_GLOBAL_DATA_PTR;
26
27static ulong get_sp(void)
28{
29 ulong ret;
30
31 asm("addik %0, r1, 0" : "=r"(ret) : );
32 return ret;
33}
34
35void arch_lmb_reserve(struct lmb *lmb)
36{
Marek Vasutd0dd68f2021-09-10 22:47:10 +020037 arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
Michal Simek040872e2019-09-25 10:45:51 +020038}
39
Michal Simeke37afb52019-09-25 09:47:02 +020040static void boot_jump_linux(bootm_headers_t *images, int flag)
wdenk12490652004-04-18 21:13:41 +000041{
Michal Simeke37afb52019-09-25 09:47:02 +020042 void (*thekernel)(char *cmdline, ulong rd, ulong dt);
43 ulong dt = (ulong)images->ft_addr;
44 ulong rd_start = images->initrd_start;
45 ulong cmdline = images->cmdline_start;
46 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
Arun Bhanu2304c052010-04-15 18:27:17 +080047
Michal Simekc78ce292013-05-02 12:51:48 +020048 thekernel = (void (*)(char *, ulong, ulong))images->ep;
Arun Bhanu2304c052010-04-15 18:27:17 +080049
Michal Simek1facc8f2019-10-17 13:16:56 +020050 debug("## Transferring control to Linux (at address 0x%08lx) ",
51 (ulong)thekernel);
52 debug("cmdline 0x%08lx, ramdisk 0x%08lx, FDT 0x%08lx...\n",
53 cmdline, rd_start, dt);
54 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
55
56 printf("\nStarting kernel ...%s\n\n", fake ?
57 "(fake run for tracing)" : "");
58 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
Michal Simek922ce202007-03-11 13:48:24 +010059
Michal Simek80c42c72010-04-16 12:01:32 +020060#ifdef XILINX_USE_DCACHE
Michal Simek80c42c72010-04-16 12:01:32 +020061 flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
Michal Simek80c42c72010-04-16 12:01:32 +020062#endif
Michal Simeke37afb52019-09-25 09:47:02 +020063
64 if (!fake) {
65 /*
66 * Linux Kernel Parameters (passing device tree):
67 * r5: pointer to command line
68 * r6: pointer to ramdisk
69 * r7: pointer to the fdt, followed by the board info data
70 */
71 thekernel((char *)cmdline, rd_start, dt);
72 /* does not return */
73 }
74}
75
76static void boot_prep_linux(bootm_headers_t *images)
77{
Simon Glass85c057e2021-09-25 19:43:21 -060078 if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
Michal Simek4bbe2ac2019-10-17 14:12:48 +020079 debug("using: FDT\n");
Michal Simeke37afb52019-09-25 09:47:02 +020080 if (image_setup_linux(images)) {
81 printf("FDT creation failed! hanging...");
82 hang();
83 }
84 }
85}
86
Simon Glassed38aef2020-05-10 11:40:03 -060087int do_bootm_linux(int flag, int argc, char *const argv[],
Michal Simeke37afb52019-09-25 09:47:02 +020088 bootm_headers_t *images)
89{
90 images->cmdline_start = (ulong)env_get("bootargs");
91
92 /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */
93 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
94 return -1;
95
96 if (flag & BOOTM_STATE_OS_PREP) {
97 boot_prep_linux(images);
98 return 0;
99 }
100
101 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
102 boot_jump_linux(images, flag);
103 return 0;
104 }
Jean-Christophe PLAGNIOL-VILLARD7ed7a272008-09-10 22:48:09 +0200105
Michal Simeke37afb52019-09-25 09:47:02 +0200106 boot_prep_linux(images);
107 boot_jump_linux(images, flag);
Kumar Gala48626aa2008-08-15 08:24:45 -0500108 return 1;
wdenk12490652004-04-18 21:13:41 +0000109}