blob: ed6c5dfa58451568ce98f27cb4c8c25710d1bd85 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Alexey Brodkin22723822014-02-04 12:56:15 +04002/*
3 * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
Alexey Brodkin22723822014-02-04 12:56:15 +04004 */
5
Simon Glass52f24232020-05-10 11:40:00 -06006#include <common.h>
7#include <bootstage.h>
Simon Glass09140112020-05-10 11:40:03 -06008#include <env.h>
Simon Glass4d72caa2020-05-10 11:40:01 -06009#include <image.h>
Simon Glass36bf4462019-11-14 12:57:42 -070010#include <irq_func.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Eugeniy Paltsev375945b2018-03-21 15:59:02 +030012#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Alexey Brodkin22723822014-02-04 12:56:15 +040014
15DECLARE_GLOBAL_DATA_PTR;
16
Alexey Brodkin22723822014-02-04 12:56:15 +040017static int cleanup_before_linux(void)
18{
19 disable_interrupts();
Eugeniy Paltsev375945b2018-03-21 15:59:02 +030020 sync_n_cleanup_cache_all();
Alexey Brodkin22723822014-02-04 12:56:15 +040021
22 return 0;
23}
24
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030025__weak int board_prep_linux(bootm_headers_t *images) { return 0; }
26
Alexey Brodkin22723822014-02-04 12:56:15 +040027/* Subcommand: PREP */
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030028static int boot_prep_linux(bootm_headers_t *images)
Alexey Brodkin22723822014-02-04 12:56:15 +040029{
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030030 int ret;
31
32 ret = image_setup_linux(images);
33 if (ret)
34 return ret;
35
36 return board_prep_linux(images);
Alexey Brodkin22723822014-02-04 12:56:15 +040037}
38
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030039/* Generic implementation for single core CPU */
40__weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
41{
42 void (*kernel_entry)(int zero, int arch, uint params);
43
44 kernel_entry = (void (*)(int, int, uint))entry;
45
46 kernel_entry(zero, arch, params);
47}
Alexey Brodkin8b2eb772015-04-13 13:37:05 +030048
Alexey Brodkin22723822014-02-04 12:56:15 +040049/* Subcommand: GO */
50static void boot_jump_linux(bootm_headers_t *images, int flag)
51{
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030052 ulong kernel_entry;
Alexey Brodkin22723822014-02-04 12:56:15 +040053 unsigned int r0, r2;
54 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
55
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030056 kernel_entry = images->ep;
Alexey Brodkin22723822014-02-04 12:56:15 +040057
58 debug("## Transferring control to Linux (at address %08lx)...\n",
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030059 kernel_entry);
Alexey Brodkin22723822014-02-04 12:56:15 +040060 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
61
62 printf("\nStarting kernel ...%s\n\n", fake ?
63 "(fake run for tracing)" : "");
64 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
65
Simon Glass0c303f92021-09-25 19:43:21 -060066 if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
Alexey Brodkin22723822014-02-04 12:56:15 +040067 r0 = 2;
68 r2 = (unsigned int)images->ft_addr;
69 } else {
70 r0 = 1;
Simon Glass00caae62017-08-03 12:22:12 -060071 r2 = (unsigned int)env_get("bootargs");
Alexey Brodkin22723822014-02-04 12:56:15 +040072 }
73
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030074 cleanup_before_linux();
75
76 if (!fake)
77 board_jump_and_run(kernel_entry, r0, 0, r2);
Alexey Brodkin22723822014-02-04 12:56:15 +040078}
79
80int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
81{
82 /* No need for those on ARC */
83 if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
84 return -1;
85
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030086 if (flag & BOOTM_STATE_OS_PREP)
87 return boot_prep_linux(images);
Alexey Brodkin22723822014-02-04 12:56:15 +040088
89 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
90 boot_jump_linux(images, flag);
91 return 0;
92 }
93
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030094 return -1;
Alexey Brodkin22723822014-02-04 12:56:15 +040095}