blob: 4f04aad34a7a01bef308f8f6a81efa6ca2c356d1 [file] [log] [blame]
Alexey Brodkin22723822014-02-04 12:56:15 +04001/*
2 * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
Eugeniy Paltsev375945b2018-03-21 15:59:02 +03007#include <asm/cache.h>
Alexey Brodkin22723822014-02-04 12:56:15 +04008#include <common.h>
9
10DECLARE_GLOBAL_DATA_PTR;
11
12static ulong get_sp(void)
13{
14 ulong ret;
15
16 asm("mov %0, sp" : "=r"(ret) : );
17 return ret;
18}
19
20void arch_lmb_reserve(struct lmb *lmb)
21{
22 ulong sp;
23
24 /*
25 * Booting a (Linux) kernel image
26 *
27 * Allocate space for command line and board info - the
28 * address should be as high as possible within the reach of
29 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
30 * memory, which means far enough below the current stack
31 * pointer.
32 */
33 sp = get_sp();
34 debug("## Current stack ends at 0x%08lx ", sp);
35
36 /* adjust sp by 4K to be safe */
37 sp -= 4096;
38 lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
39}
40
41static int cleanup_before_linux(void)
42{
43 disable_interrupts();
Eugeniy Paltsev375945b2018-03-21 15:59:02 +030044 sync_n_cleanup_cache_all();
Alexey Brodkin22723822014-02-04 12:56:15 +040045
46 return 0;
47}
48
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030049__weak int board_prep_linux(bootm_headers_t *images) { return 0; }
50
Alexey Brodkin22723822014-02-04 12:56:15 +040051/* Subcommand: PREP */
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030052static int boot_prep_linux(bootm_headers_t *images)
Alexey Brodkin22723822014-02-04 12:56:15 +040053{
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030054 int ret;
55
56 ret = image_setup_linux(images);
57 if (ret)
58 return ret;
59
60 return board_prep_linux(images);
Alexey Brodkin22723822014-02-04 12:56:15 +040061}
62
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030063/* Generic implementation for single core CPU */
64__weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
65{
66 void (*kernel_entry)(int zero, int arch, uint params);
67
68 kernel_entry = (void (*)(int, int, uint))entry;
69
70 kernel_entry(zero, arch, params);
71}
Alexey Brodkin8b2eb772015-04-13 13:37:05 +030072
Alexey Brodkin22723822014-02-04 12:56:15 +040073/* Subcommand: GO */
74static void boot_jump_linux(bootm_headers_t *images, int flag)
75{
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030076 ulong kernel_entry;
Alexey Brodkin22723822014-02-04 12:56:15 +040077 unsigned int r0, r2;
78 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
79
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030080 kernel_entry = images->ep;
Alexey Brodkin22723822014-02-04 12:56:15 +040081
82 debug("## Transferring control to Linux (at address %08lx)...\n",
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030083 kernel_entry);
Alexey Brodkin22723822014-02-04 12:56:15 +040084 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
85
86 printf("\nStarting kernel ...%s\n\n", fake ?
87 "(fake run for tracing)" : "");
88 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
89
Alexey Brodkin22723822014-02-04 12:56:15 +040090 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
91 r0 = 2;
92 r2 = (unsigned int)images->ft_addr;
93 } else {
94 r0 = 1;
Simon Glass00caae62017-08-03 12:22:12 -060095 r2 = (unsigned int)env_get("bootargs");
Alexey Brodkin22723822014-02-04 12:56:15 +040096 }
97
Eugeniy Paltsevf665c142018-03-23 15:35:03 +030098 cleanup_before_linux();
99
100 if (!fake)
101 board_jump_and_run(kernel_entry, r0, 0, r2);
Alexey Brodkin22723822014-02-04 12:56:15 +0400102}
103
104int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
105{
106 /* No need for those on ARC */
107 if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
108 return -1;
109
Eugeniy Paltsevf665c142018-03-23 15:35:03 +0300110 if (flag & BOOTM_STATE_OS_PREP)
111 return boot_prep_linux(images);
Alexey Brodkin22723822014-02-04 12:56:15 +0400112
113 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
114 boot_jump_linux(images, flag);
115 return 0;
116 }
117
Eugeniy Paltsevf665c142018-03-23 15:35:03 +0300118 return -1;
Alexey Brodkin22723822014-02-04 12:56:15 +0400119}