blob: 4879a41aab3bb141a6e6b5d532484c1fb7221b80 [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
Simon Glass0726d9d2023-12-15 20:14:13 -070010#include <bootm.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 Glass0f2af882020-05-10 11:40:05 -060018#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060019#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060020#include <asm/global_data.h>
Jean-Christophe PLAGNIOL-VILLARD6bb94492009-04-04 12:49:11 +020021#include <u-boot/zlib.h>
Michal Simek922ce202007-03-11 13:48:24 +010022#include <asm/byteorder.h>
wdenk12490652004-04-18 21:13:41 +000023
Michal Simek040872e2019-09-25 10:45:51 +020024DECLARE_GLOBAL_DATA_PTR;
25
Simon Glassdf00afa2022-09-06 20:26:50 -060026static void boot_jump_linux(struct bootm_headers *images, int flag)
wdenk12490652004-04-18 21:13:41 +000027{
Michal Simeke37afb52019-09-25 09:47:02 +020028 void (*thekernel)(char *cmdline, ulong rd, ulong dt);
29 ulong dt = (ulong)images->ft_addr;
30 ulong rd_start = images->initrd_start;
31 ulong cmdline = images->cmdline_start;
32 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
Arun Bhanu2304c052010-04-15 18:27:17 +080033
Michal Simekc78ce292013-05-02 12:51:48 +020034 thekernel = (void (*)(char *, ulong, ulong))images->ep;
Arun Bhanu2304c052010-04-15 18:27:17 +080035
Michal Simek1facc8f2019-10-17 13:16:56 +020036 debug("## Transferring control to Linux (at address 0x%08lx) ",
37 (ulong)thekernel);
38 debug("cmdline 0x%08lx, ramdisk 0x%08lx, FDT 0x%08lx...\n",
39 cmdline, rd_start, dt);
40 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
41
42 printf("\nStarting kernel ...%s\n\n", fake ?
43 "(fake run for tracing)" : "");
44 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
Michal Simek922ce202007-03-11 13:48:24 +010045
Ovidiu Panaitbc159c12022-05-31 21:14:30 +030046 flush_cache_all();
Michal Simeke37afb52019-09-25 09:47:02 +020047
48 if (!fake) {
49 /*
50 * Linux Kernel Parameters (passing device tree):
51 * r5: pointer to command line
52 * r6: pointer to ramdisk
53 * r7: pointer to the fdt, followed by the board info data
54 */
55 thekernel((char *)cmdline, rd_start, dt);
56 /* does not return */
57 }
58}
59
Simon Glassdf00afa2022-09-06 20:26:50 -060060static void boot_prep_linux(struct bootm_headers *images)
Michal Simeke37afb52019-09-25 09:47:02 +020061{
Simon Glassae7ed572023-02-05 15:40:13 -070062 if (CONFIG_IS_ENABLED(OF_LIBFDT) && IS_ENABLED(CONFIG_LMB) && images->ft_len) {
Michal Simek4bbe2ac2019-10-17 14:12:48 +020063 debug("using: FDT\n");
Michal Simeke37afb52019-09-25 09:47:02 +020064 if (image_setup_linux(images)) {
65 printf("FDT creation failed! hanging...");
66 hang();
67 }
68 }
69}
70
Simon Glass0726d9d2023-12-15 20:14:13 -070071int do_bootm_linux(int flag, struct bootm_info *bmi)
Michal Simeke37afb52019-09-25 09:47:02 +020072{
Simon Glass0726d9d2023-12-15 20:14:13 -070073 struct bootm_headers *images = bmi->images;
74
Michal Simeke37afb52019-09-25 09:47:02 +020075 images->cmdline_start = (ulong)env_get("bootargs");
76
77 /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */
78 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
79 return -1;
80
81 if (flag & BOOTM_STATE_OS_PREP) {
82 boot_prep_linux(images);
83 return 0;
84 }
85
86 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
87 boot_jump_linux(images, flag);
88 return 0;
89 }
Jean-Christophe PLAGNIOL-VILLARD7ed7a272008-09-10 22:48:09 +020090
Michal Simeke37afb52019-09-25 09:47:02 +020091 boot_prep_linux(images);
92 boot_jump_linux(images, flag);
Kumar Gala48626aa2008-08-15 08:24:45 -050093 return 1;
wdenk12490652004-04-18 21:13:41 +000094}