]> git.ipfire.org Git - thirdparty/u-boot.git/blame - arch/arc/lib/bootm.c
command: Remove the cmd_tbl_t typedef
[thirdparty/u-boot.git] / arch / arc / lib / bootm.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
22723828
AB
2/*
3 * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
22723828
AB
4 */
5
52f24238
SG
6#include <common.h>
7#include <bootstage.h>
09140113 8#include <env.h>
4d72caa5 9#include <image.h>
36bf446b 10#include <irq_func.h>
4d72caa5 11#include <lmb.h>
375945ba 12#include <asm/cache.h>
22723828
AB
13
14DECLARE_GLOBAL_DATA_PTR;
15
16static ulong get_sp(void)
17{
18 ulong ret;
19
20 asm("mov %0, sp" : "=r"(ret) : );
21 return ret;
22}
23
24void arch_lmb_reserve(struct lmb *lmb)
25{
26 ulong sp;
27
28 /*
29 * Booting a (Linux) kernel image
30 *
31 * Allocate space for command line and board info - the
32 * address should be as high as possible within the reach of
33 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
34 * memory, which means far enough below the current stack
35 * pointer.
36 */
37 sp = get_sp();
38 debug("## Current stack ends at 0x%08lx ", sp);
39
40 /* adjust sp by 4K to be safe */
41 sp -= 4096;
42 lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
43}
44
45static int cleanup_before_linux(void)
46{
47 disable_interrupts();
375945ba 48 sync_n_cleanup_cache_all();
22723828
AB
49
50 return 0;
51}
52
f665c14f
EP
53__weak int board_prep_linux(bootm_headers_t *images) { return 0; }
54
22723828 55/* Subcommand: PREP */
f665c14f 56static int boot_prep_linux(bootm_headers_t *images)
22723828 57{
f665c14f
EP
58 int ret;
59
60 ret = image_setup_linux(images);
61 if (ret)
62 return ret;
63
64 return board_prep_linux(images);
22723828
AB
65}
66
f665c14f
EP
67/* Generic implementation for single core CPU */
68__weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
69{
70 void (*kernel_entry)(int zero, int arch, uint params);
71
72 kernel_entry = (void (*)(int, int, uint))entry;
73
74 kernel_entry(zero, arch, params);
75}
8b2eb776 76
22723828
AB
77/* Subcommand: GO */
78static void boot_jump_linux(bootm_headers_t *images, int flag)
79{
f665c14f 80 ulong kernel_entry;
22723828
AB
81 unsigned int r0, r2;
82 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
83
f665c14f 84 kernel_entry = images->ep;
22723828
AB
85
86 debug("## Transferring control to Linux (at address %08lx)...\n",
f665c14f 87 kernel_entry);
22723828
AB
88 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
89
90 printf("\nStarting kernel ...%s\n\n", fake ?
91 "(fake run for tracing)" : "");
92 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
93
22723828
AB
94 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
95 r0 = 2;
96 r2 = (unsigned int)images->ft_addr;
97 } else {
98 r0 = 1;
00caae6d 99 r2 = (unsigned int)env_get("bootargs");
22723828
AB
100 }
101
f665c14f
EP
102 cleanup_before_linux();
103
104 if (!fake)
105 board_jump_and_run(kernel_entry, r0, 0, r2);
22723828
AB
106}
107
108int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
109{
110 /* No need for those on ARC */
111 if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
112 return -1;
113
f665c14f
EP
114 if (flag & BOOTM_STATE_OS_PREP)
115 return boot_prep_linux(images);
22723828
AB
116
117 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
118 boot_jump_linux(images, flag);
119 return 0;
120 }
121
f665c14f 122 return -1;
22723828 123}