blob: 44ec5864a1c6bbfdf342b1038523db2ec1836a38 [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 <bootstage.h>
Simon Glassed38aef2020-05-10 11:40:03 -06007#include <env.h>
Simon Glass2dc9c342020-05-10 11:40:01 -06008#include <image.h>
Simon Glass8f3f7612019-11-14 12:57:42 -07009#include <irq_func.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Eugeniy Paltsev67fd56a2018-03-21 15:59:02 +030011#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Alexey Brodkinb628c012014-02-04 12:56:15 +040013
14DECLARE_GLOBAL_DATA_PTR;
15
Alexey Brodkinb628c012014-02-04 12:56:15 +040016static int cleanup_before_linux(void)
17{
18 disable_interrupts();
Eugeniy Paltsev67fd56a2018-03-21 15:59:02 +030019 sync_n_cleanup_cache_all();
Alexey Brodkinb628c012014-02-04 12:56:15 +040020
21 return 0;
22}
23
Simon Glassdf00afa2022-09-06 20:26:50 -060024__weak int board_prep_linux(struct bootm_headers *images) { return 0; }
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030025
Alexey Brodkinb628c012014-02-04 12:56:15 +040026/* Subcommand: PREP */
Simon Glassdf00afa2022-09-06 20:26:50 -060027static int boot_prep_linux(struct bootm_headers *images)
Alexey Brodkinb628c012014-02-04 12:56:15 +040028{
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030029 int ret;
30
Simon Glassae7ed572023-02-05 15:40:13 -070031 if (IS_ENABLED(CONFIG_LMB)) {
Ashok Reddy Soma8aaae3d2022-07-07 10:45:37 +020032 ret = image_setup_linux(images);
33 if (ret)
34 return ret;
35 }
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030036
37 return board_prep_linux(images);
Alexey Brodkinb628c012014-02-04 12:56:15 +040038}
39
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030040/* Generic implementation for single core CPU */
41__weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
42{
43 void (*kernel_entry)(int zero, int arch, uint params);
44
45 kernel_entry = (void (*)(int, int, uint))entry;
46
47 kernel_entry(zero, arch, params);
48}
Alexey Brodkincf9cafd2015-04-13 13:37:05 +030049
Alexey Brodkinb628c012014-02-04 12:56:15 +040050/* Subcommand: GO */
Simon Glassdf00afa2022-09-06 20:26:50 -060051static void boot_jump_linux(struct bootm_headers *images, int flag)
Alexey Brodkinb628c012014-02-04 12:56:15 +040052{
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030053 ulong kernel_entry;
Alexey Brodkinb628c012014-02-04 12:56:15 +040054 unsigned int r0, r2;
55 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
56
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030057 kernel_entry = images->ep;
Alexey Brodkinb628c012014-02-04 12:56:15 +040058
59 debug("## Transferring control to Linux (at address %08lx)...\n",
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030060 kernel_entry);
Alexey Brodkinb628c012014-02-04 12:56:15 +040061 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
62
63 printf("\nStarting kernel ...%s\n\n", fake ?
64 "(fake run for tracing)" : "");
65 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
66
Simon Glass85c057e2021-09-25 19:43:21 -060067 if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
Alexey Brodkinb628c012014-02-04 12:56:15 +040068 r0 = 2;
69 r2 = (unsigned int)images->ft_addr;
70 } else {
71 r0 = 1;
Simon Glass64b723f2017-08-03 12:22:12 -060072 r2 = (unsigned int)env_get("bootargs");
Alexey Brodkinb628c012014-02-04 12:56:15 +040073 }
74
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030075 cleanup_before_linux();
76
77 if (!fake)
78 board_jump_and_run(kernel_entry, r0, 0, r2);
Alexey Brodkinb628c012014-02-04 12:56:15 +040079}
80
Simon Glassdf00afa2022-09-06 20:26:50 -060081int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images)
Alexey Brodkinb628c012014-02-04 12:56:15 +040082{
83 /* No need for those on ARC */
84 if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
85 return -1;
86
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030087 if (flag & BOOTM_STATE_OS_PREP)
88 return boot_prep_linux(images);
Alexey Brodkinb628c012014-02-04 12:56:15 +040089
90 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
91 boot_jump_linux(images, flag);
92 return 0;
93 }
94
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030095 return -1;
Alexey Brodkinb628c012014-02-04 12:56:15 +040096}