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