blob: 1b08ffe2857cda9f975ec14e84c39ecef44dab78 [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 Glass8f3f7612019-11-14 12:57:42 -07008#include <irq_func.h>
Eugeniy Paltsev67fd56a2018-03-21 15:59:02 +03009#include <asm/cache.h>
Alexey Brodkinb628c012014-02-04 12:56:15 +040010
11DECLARE_GLOBAL_DATA_PTR;
12
13static ulong get_sp(void)
14{
15 ulong ret;
16
17 asm("mov %0, sp" : "=r"(ret) : );
18 return ret;
19}
20
21void arch_lmb_reserve(struct lmb *lmb)
22{
23 ulong sp;
24
25 /*
26 * Booting a (Linux) kernel image
27 *
28 * Allocate space for command line and board info - the
29 * address should be as high as possible within the reach of
30 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
31 * memory, which means far enough below the current stack
32 * pointer.
33 */
34 sp = get_sp();
35 debug("## Current stack ends at 0x%08lx ", sp);
36
37 /* adjust sp by 4K to be safe */
38 sp -= 4096;
39 lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
40}
41
42static int cleanup_before_linux(void)
43{
44 disable_interrupts();
Eugeniy Paltsev67fd56a2018-03-21 15:59:02 +030045 sync_n_cleanup_cache_all();
Alexey Brodkinb628c012014-02-04 12:56:15 +040046
47 return 0;
48}
49
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030050__weak int board_prep_linux(bootm_headers_t *images) { return 0; }
51
Alexey Brodkinb628c012014-02-04 12:56:15 +040052/* Subcommand: PREP */
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030053static int boot_prep_linux(bootm_headers_t *images)
Alexey Brodkinb628c012014-02-04 12:56:15 +040054{
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030055 int ret;
56
57 ret = image_setup_linux(images);
58 if (ret)
59 return ret;
60
61 return board_prep_linux(images);
Alexey Brodkinb628c012014-02-04 12:56:15 +040062}
63
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030064/* Generic implementation for single core CPU */
65__weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
66{
67 void (*kernel_entry)(int zero, int arch, uint params);
68
69 kernel_entry = (void (*)(int, int, uint))entry;
70
71 kernel_entry(zero, arch, params);
72}
Alexey Brodkincf9cafd2015-04-13 13:37:05 +030073
Alexey Brodkinb628c012014-02-04 12:56:15 +040074/* Subcommand: GO */
75static void boot_jump_linux(bootm_headers_t *images, int flag)
76{
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030077 ulong kernel_entry;
Alexey Brodkinb628c012014-02-04 12:56:15 +040078 unsigned int r0, r2;
79 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
80
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030081 kernel_entry = images->ep;
Alexey Brodkinb628c012014-02-04 12:56:15 +040082
83 debug("## Transferring control to Linux (at address %08lx)...\n",
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030084 kernel_entry);
Alexey Brodkinb628c012014-02-04 12:56:15 +040085 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
86
87 printf("\nStarting kernel ...%s\n\n", fake ?
88 "(fake run for tracing)" : "");
89 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
90
Alexey Brodkinb628c012014-02-04 12:56:15 +040091 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
92 r0 = 2;
93 r2 = (unsigned int)images->ft_addr;
94 } else {
95 r0 = 1;
Simon Glass64b723f2017-08-03 12:22:12 -060096 r2 = (unsigned int)env_get("bootargs");
Alexey Brodkinb628c012014-02-04 12:56:15 +040097 }
98
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +030099 cleanup_before_linux();
100
101 if (!fake)
102 board_jump_and_run(kernel_entry, r0, 0, r2);
Alexey Brodkinb628c012014-02-04 12:56:15 +0400103}
104
105int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
106{
107 /* No need for those on ARC */
108 if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
109 return -1;
110
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +0300111 if (flag & BOOTM_STATE_OS_PREP)
112 return boot_prep_linux(images);
Alexey Brodkinb628c012014-02-04 12:56:15 +0400113
114 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
115 boot_jump_linux(images, flag);
116 return 0;
117 }
118
Eugeniy Paltsev01f45cc2018-03-23 15:35:03 +0300119 return -1;
Alexey Brodkinb628c012014-02-04 12:56:15 +0400120}