blob: 254e0284b3fb2e55a30d04e53d515f32335b5eed [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
Eugeniy Paltsev375945b2018-03-21 15:59:02 +03006#include <asm/cache.h>
Alexey Brodkin22723822014-02-04 12:56:15 +04007#include <common.h>
8
9DECLARE_GLOBAL_DATA_PTR;
10
11static ulong get_sp(void)
12{
13 ulong ret;
14
15 asm("mov %0, sp" : "=r"(ret) : );
16 return ret;
17}
18
19void arch_lmb_reserve(struct lmb *lmb)
20{
21 ulong sp;
22
23 /*
24 * Booting a (Linux) kernel image
25 *
26 * Allocate space for command line and board info - the
27 * address should be as high as possible within the reach of
28 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
29 * memory, which means far enough below the current stack
30 * pointer.
31 */
32 sp = get_sp();
33 debug("## Current stack ends at 0x%08lx ", sp);
34
35 /* adjust sp by 4K to be safe */
36 sp -= 4096;
37 lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
38}
39
40static int cleanup_before_linux(void)
41{
42 disable_interrupts();
Eugeniy Paltsev375945b2018-03-21 15:59:02 +030043 sync_n_cleanup_cache_all();
Alexey Brodkin22723822014-02-04 12:56:15 +040044
45 return 0;
46}
47
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030048__weak int board_prep_linux(bootm_headers_t *images) { return 0; }
49
Alexey Brodkin22723822014-02-04 12:56:15 +040050/* Subcommand: PREP */
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030051static int boot_prep_linux(bootm_headers_t *images)
Alexey Brodkin22723822014-02-04 12:56:15 +040052{
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030053 int ret;
54
55 ret = image_setup_linux(images);
56 if (ret)
57 return ret;
58
59 return board_prep_linux(images);
Alexey Brodkin22723822014-02-04 12:56:15 +040060}
61
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030062/* Generic implementation for single core CPU */
63__weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
64{
65 void (*kernel_entry)(int zero, int arch, uint params);
66
67 kernel_entry = (void (*)(int, int, uint))entry;
68
69 kernel_entry(zero, arch, params);
70}
Alexey Brodkin8b2eb772015-04-13 13:37:05 +030071
Alexey Brodkin22723822014-02-04 12:56:15 +040072/* Subcommand: GO */
73static void boot_jump_linux(bootm_headers_t *images, int flag)
74{
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030075 ulong kernel_entry;
Alexey Brodkin22723822014-02-04 12:56:15 +040076 unsigned int r0, r2;
77 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
78
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030079 kernel_entry = images->ep;
Alexey Brodkin22723822014-02-04 12:56:15 +040080
81 debug("## Transferring control to Linux (at address %08lx)...\n",
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030082 kernel_entry);
Alexey Brodkin22723822014-02-04 12:56:15 +040083 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
84
85 printf("\nStarting kernel ...%s\n\n", fake ?
86 "(fake run for tracing)" : "");
87 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
88
Alexey Brodkin22723822014-02-04 12:56:15 +040089 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
90 r0 = 2;
91 r2 = (unsigned int)images->ft_addr;
92 } else {
93 r0 = 1;
Simon Glass00caae62017-08-03 12:22:12 -060094 r2 = (unsigned int)env_get("bootargs");
Alexey Brodkin22723822014-02-04 12:56:15 +040095 }
96
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030097 cleanup_before_linux();
98
99 if (!fake)
100 board_jump_and_run(kernel_entry, r0, 0, r2);
Alexey Brodkin22723822014-02-04 12:56:15 +0400101}
102
103int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
104{
105 /* No need for those on ARC */
106 if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
107 return -1;
108
Eugeniy Paltsevf665c142018-03-23 15:35:03 +0300109 if (flag & BOOTM_STATE_OS_PREP)
110 return boot_prep_linux(images);
Alexey Brodkin22723822014-02-04 12:56:15 +0400111
112 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
113 boot_jump_linux(images, flag);
114 return 0;
115 }
116
Eugeniy Paltsevf665c142018-03-23 15:35:03 +0300117 return -1;
Alexey Brodkin22723822014-02-04 12:56:15 +0400118}