blob: 2dd003445f8fe39e597a87bbf481181a641af4da [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Alexey Brodkinb628c012014-02-04 12:56:15 +04002/*
3 * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
Alexey Brodkinb628c012014-02-04 12:56:15 +04004 */
5
Simon Glass1ea97892020-05-10 11:40:00 -06006#include <common.h>
7#include <bootstage.h>
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <env.h>
Simon Glass2dc9c342020-05-10 11:40:01 -06009#include <image.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070010#include <irq_func.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Eugeniy Paltsev67fd56a2018-03-21 15:59:02 +030012#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Alexey Brodkinb628c012014-02-04 12:56:15 +040014
15DECLARE_GLOBAL_DATA_PTR;
16
Alexey Brodkinb628c012014-02-04 12:56:15 +040017static int cleanup_before_linux(void)
18{
19 disable_interrupts();
Eugeniy Paltsev67fd56a2018-03-21 15:59:02 +030020 sync_n_cleanup_cache_all();
Alexey Brodkinb628c012014-02-04 12:56:15 +040021
22 return 0;
23}
24
Simon Glassdf00afa2022-09-06 20:26:50 -060025__weak int board_prep_linux(struct bootm_headers *images) { return 0; }
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030026
Alexey Brodkinb628c012014-02-04 12:56:15 +040027/* Subcommand: PREP */
Simon Glassdf00afa2022-09-06 20:26:50 -060028static int boot_prep_linux(struct bootm_headers *images)
Alexey Brodkinb628c012014-02-04 12:56:15 +040029{
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030030 int ret;
31
Simon Glassae7ed572023-02-05 15:40:13 -070032 if (IS_ENABLED(CONFIG_LMB)) {
Ashok Reddy Soma8aaae3d2022-07-07 10:45:37 +020033 ret = image_setup_linux(images);
34 if (ret)
35 return ret;
36 }
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030037
38 return board_prep_linux(images);
Alexey Brodkinb628c012014-02-04 12:56:15 +040039}
40
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030041/* Generic implementation for single core CPU */
42__weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
43{
44 void (*kernel_entry)(int zero, int arch, uint params);
45
46 kernel_entry = (void (*)(int, int, uint))entry;
47
48 kernel_entry(zero, arch, params);
49}
Alexey Brodkincf9cafd2015-04-13 13:37:05 +030050
Alexey Brodkinb628c012014-02-04 12:56:15 +040051/* Subcommand: GO */
Simon Glassdf00afa2022-09-06 20:26:50 -060052static void boot_jump_linux(struct bootm_headers *images, int flag)
Alexey Brodkinb628c012014-02-04 12:56:15 +040053{
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030054 ulong kernel_entry;
Alexey Brodkinb628c012014-02-04 12:56:15 +040055 unsigned int r0, r2;
56 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
57
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030058 kernel_entry = images->ep;
Alexey Brodkinb628c012014-02-04 12:56:15 +040059
60 debug("## Transferring control to Linux (at address %08lx)...\n",
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030061 kernel_entry);
Alexey Brodkinb628c012014-02-04 12:56:15 +040062 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
63
64 printf("\nStarting kernel ...%s\n\n", fake ?
65 "(fake run for tracing)" : "");
66 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
67
Simon Glass85c057e2021-09-25 19:43:21 -060068 if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
Alexey Brodkinb628c012014-02-04 12:56:15 +040069 r0 = 2;
70 r2 = (unsigned int)images->ft_addr;
71 } else {
72 r0 = 1;
Simon Glass64b723f2017-08-03 12:22:12 -060073 r2 = (unsigned int)env_get("bootargs");
Alexey Brodkinb628c012014-02-04 12:56:15 +040074 }
75
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030076 cleanup_before_linux();
77
78 if (!fake)
79 board_jump_and_run(kernel_entry, r0, 0, r2);
Alexey Brodkinb628c012014-02-04 12:56:15 +040080}
81
Simon Glassdf00afa2022-09-06 20:26:50 -060082int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images)
Alexey Brodkinb628c012014-02-04 12:56:15 +040083{
84 /* No need for those on ARC */
85 if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
86 return -1;
87
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030088 if (flag & BOOTM_STATE_OS_PREP)
89 return boot_prep_linux(images);
Alexey Brodkinb628c012014-02-04 12:56:15 +040090
91 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
92 boot_jump_linux(images, flag);
93 return 0;
94 }
95
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030096 return -1;
Alexey Brodkinb628c012014-02-04 12:56:15 +040097}