blob: cbe9d85aa911bec6d3494e7f58b69248598f01b4 [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
Simon Glassa48336e2023-12-15 20:14:13 -070010#include <bootm.h>
Simon Glass52f24232020-05-10 11:40:00 -060011#include <bootstage.h>
wdenk507bbe32004-04-18 21:13:41 +000012#include <command.h>
Simon Glass1eb69ae2019-11-14 12:57:39 -070013#include <cpu_func.h>
Simon Glass7b51b572019-08-01 09:46:52 -060014#include <env.h>
Simon Glass73223f02016-02-22 22:55:43 -070015#include <fdt_support.h>
Simon Glassdb41d652019-12-28 10:45:07 -070016#include <hang.h>
Michal Simekcfc67112007-03-11 13:48:24 +010017#include <image.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060018#include <lmb.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060019#include <log.h>
Simon Glass90526e92020-05-10 11:39:56 -060020#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060021#include <asm/global_data.h>
Jean-Christophe PLAGNIOL-VILLARDa31e0912009-04-04 12:49:11 +020022#include <u-boot/zlib.h>
Michal Simekcfc67112007-03-11 13:48:24 +010023#include <asm/byteorder.h>
wdenk507bbe32004-04-18 21:13:41 +000024
Michal Simek6131a362019-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 Vasut1f391c32021-09-10 22:47:10 +020037 arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
Michal Simek6131a362019-09-25 10:45:51 +020038}
39
Simon Glassd9d7c202022-09-06 20:26:50 -060040static void boot_jump_linux(struct bootm_headers *images, int flag)
wdenk507bbe32004-04-18 21:13:41 +000041{
Michal Simek09050462019-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 Bhanu398b1d52010-04-15 18:27:17 +080047
Michal Simek1e71fa42013-05-02 12:51:48 +020048 thekernel = (void (*)(char *, ulong, ulong))images->ep;
Arun Bhanu398b1d52010-04-15 18:27:17 +080049
Michal Simekf3035cf2019-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 Simekcfc67112007-03-11 13:48:24 +010059
Ovidiu Panaitb1951342022-05-31 21:14:30 +030060 flush_cache_all();
Jean-Christophe PLAGNIOL-VILLARDa3a08c02008-09-10 22:48:09 +020061
Michal Simek09050462019-09-25 09:47:02 +020062 if (!fake) {
63 /*
64 * Linux Kernel Parameters (passing device tree):
65 * r5: pointer to command line
66 * r6: pointer to ramdisk
67 * r7: pointer to the fdt, followed by the board info data
68 */
69 thekernel((char *)cmdline, rd_start, dt);
70 /* does not return */
71 }
72}
73
Simon Glassd9d7c202022-09-06 20:26:50 -060074static void boot_prep_linux(struct bootm_headers *images)
Michal Simek09050462019-09-25 09:47:02 +020075{
Simon Glass210af542023-02-05 15:40:13 -070076 if (CONFIG_IS_ENABLED(OF_LIBFDT) && IS_ENABLED(CONFIG_LMB) && images->ft_len) {
Michal Simek4ab8d632019-10-17 14:12:48 +020077 debug("using: FDT\n");
Michal Simek09050462019-09-25 09:47:02 +020078 if (image_setup_linux(images)) {
79 printf("FDT creation failed! hanging...");
80 hang();
81 }
82 }
83}
84
Simon Glassa48336e2023-12-15 20:14:13 -070085int do_bootm_linux(int flag, struct bootm_info *bmi)
Michal Simek09050462019-09-25 09:47:02 +020086{
Simon Glassa48336e2023-12-15 20:14:13 -070087 struct bootm_headers *images = bmi->images;
88
Michal Simek09050462019-09-25 09:47:02 +020089 images->cmdline_start = (ulong)env_get("bootargs");
90
91 /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */
92 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
93 return -1;
94
95 if (flag & BOOTM_STATE_OS_PREP) {
96 boot_prep_linux(images);
97 return 0;
98 }
99
100 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
101 boot_jump_linux(images, flag);
102 return 0;
103 }
104
105 boot_prep_linux(images);
106 boot_jump_linux(images, flag);
Kumar Gala40d7e992008-08-15 08:24:45 -0500107 return 1;
wdenk507bbe32004-04-18 21:13:41 +0000108}