Merge tag 'efi-2020-07-rc6' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
[oweals/u-boot.git] / arch / m68k / lib / bootm.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2003
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  */
6
7 #include <common.h>
8 #include <bootstage.h>
9 #include <command.h>
10 #include <env.h>
11 #include <image.h>
12 #include <lmb.h>
13 #include <log.h>
14 #include <u-boot/zlib.h>
15 #include <bzlib.h>
16 #include <watchdog.h>
17 #include <asm/byteorder.h>
18 #ifdef CONFIG_SHOW_BOOT_PROGRESS
19 # include <status_led.h>
20 #endif
21
22 DECLARE_GLOBAL_DATA_PTR;
23
24 #define PHYSADDR(x) x
25
26 #define LINUX_MAX_ENVS          256
27 #define LINUX_MAX_ARGS          256
28
29 static ulong get_sp (void);
30 static void set_clocks_in_mhz (bd_t *kbd);
31
32 void arch_lmb_reserve(struct lmb *lmb)
33 {
34         ulong sp;
35
36         /*
37          * Booting a (Linux) kernel image
38          *
39          * Allocate space for command line and board info - the
40          * address should be as high as possible within the reach of
41          * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
42          * memory, which means far enough below the current stack
43          * pointer.
44          */
45         sp = get_sp();
46         debug ("## Current stack ends at 0x%08lx ", sp);
47
48         /* adjust sp by 1K to be safe */
49         sp -= 1024;
50         lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
51 }
52
53 int do_bootm_linux(int flag, int argc, char *const argv[],
54                    bootm_headers_t *images)
55 {
56         int ret;
57         bd_t  *kbd;
58         void  (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
59         struct lmb *lmb = &images->lmb;
60
61         /*
62          * allow the PREP bootm subcommand, it is required for bootm to work
63          */
64         if (flag & BOOTM_STATE_OS_PREP)
65                 return 0;
66
67         if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
68                 return 1;
69
70         /* allocate space for kernel copy of board info */
71         ret = boot_get_kbd (lmb, &kbd);
72         if (ret) {
73                 puts("ERROR with allocation of kernel bd\n");
74                 goto error;
75         }
76         set_clocks_in_mhz(kbd);
77
78         ret = image_setup_linux(images);
79         if (ret)
80                 goto error;
81
82         kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
83
84         debug("## Transferring control to Linux (at address %08lx) ...\n",
85               (ulong) kernel);
86
87         bootstage_mark(BOOTSTAGE_ID_RUN_OS);
88
89         /*
90          * Linux Kernel Parameters (passing board info data):
91          *   sp+00: Ignore, side effect of using jsr to jump to kernel
92          *   sp+04: ptr to board info data
93          *   sp+08: initrd_start or 0 if no initrd
94          *   sp+12: initrd_end - unused if initrd_start is 0
95          *   sp+16: Start of command line string
96          *   sp+20: End   of command line string
97          */
98         (*kernel)(kbd, images->initrd_start, images->initrd_end,
99                   images->cmdline_start, images->cmdline_end);
100         /* does not return */
101 error:
102         return 1;
103 }
104
105 static ulong get_sp (void)
106 {
107         ulong sp;
108
109         asm("movel %%a7, %%d0\n"
110             "movel %%d0, %0\n": "=d"(sp): :"%d0");
111
112         return sp;
113 }
114
115 static void set_clocks_in_mhz (bd_t *kbd)
116 {
117         char *s;
118
119         s = env_get("clocks_in_mhz");
120         if (s) {
121                 /* convert all clock information to MHz */
122                 kbd->bi_intfreq /= 1000000L;
123                 kbd->bi_busfreq /= 1000000L;
124         }
125 }