1
2
3
4
5
6
7#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
25
26
27
28
29
30
31
32 sp = get_sp();
33 debug("## Current stack ends at 0x%08lx ", sp);
34
35
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();
43 flush_dcache_all();
44 invalidate_icache_all();
45
46 return 0;
47}
48
49
50static void boot_prep_linux(bootm_headers_t *images)
51{
52 if (image_setup_linux(images))
53 hang();
54}
55
56
57static void boot_jump_linux(bootm_headers_t *images, int flag)
58{
59 void (*kernel_entry)(int zero, int arch, uint params);
60 unsigned int r0, r2;
61 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
62
63 kernel_entry = (void (*)(int, int, uint))images->ep;
64
65 debug("## Transferring control to Linux (at address %08lx)...\n",
66 (ulong) kernel_entry);
67 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
68
69 printf("\nStarting kernel ...%s\n\n", fake ?
70 "(fake run for tracing)" : "");
71 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
72
73 cleanup_before_linux();
74
75 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
76 r0 = 2;
77 r2 = (unsigned int)images->ft_addr;
78 } else {
79 r0 = 1;
80 r2 = (unsigned int)getenv("bootargs");
81 }
82
83 if (!fake)
84 kernel_entry(r0, 0, r2);
85}
86
87int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
88{
89
90 if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
91 return -1;
92
93 if (flag & BOOTM_STATE_OS_PREP) {
94 boot_prep_linux(images);
95 return 0;
96 }
97
98 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
99 boot_jump_linux(images, flag);
100 return 0;
101 }
102
103 boot_prep_linux(images);
104 boot_jump_linux(images, flag);
105 return 0;
106}
107