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 <bootm.h>
8 #include <bootstage.h>
9 #include <command.h>
10 #include <env.h>
11 #include <image.h>
12 #include <log.h>
13 #include <asm/global_data.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 void set_clocks_in_mhz (struct bd_info *kbd);
30
do_bootm_linux(int flag,struct bootm_info * bmi)31 int do_bootm_linux(int flag, struct bootm_info *bmi)
32 {
33 struct bootm_headers *images = bmi->images;
34 int ret;
35 struct bd_info *kbd;
36 void (*kernel) (struct bd_info *, ulong, ulong, ulong, ulong);
37
38 /*
39 * allow the PREP bootm subcommand, it is required for bootm to work
40 */
41 if (flag & BOOTM_STATE_OS_PREP)
42 return 0;
43
44 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
45 return 1;
46
47 /* allocate space for kernel copy of board info */
48 ret = boot_get_kbd(&kbd);
49 if (ret) {
50 puts("ERROR with allocation of kernel bd\n");
51 goto error;
52 }
53 set_clocks_in_mhz(kbd);
54
55 if (IS_ENABLED(CONFIG_LMB)) {
56 ret = image_setup_linux(images);
57 if (ret)
58 goto error;
59 }
60
61 kernel = (void (*)(struct bd_info *, ulong, ulong, ulong, ulong))images->ep;
62
63 debug("## Transferring control to Linux (at address %08lx) ...\n",
64 (ulong) kernel);
65
66 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
67
68 /*
69 * Linux Kernel Parameters (passing board info data):
70 * sp+00: Ignore, side effect of using jsr to jump to kernel
71 * sp+04: ptr to board info data
72 * sp+08: initrd_start or 0 if no initrd
73 * sp+12: initrd_end - unused if initrd_start is 0
74 * sp+16: Start of command line string
75 * sp+20: End of command line string
76 */
77 (*kernel)(kbd, images->initrd_start, images->initrd_end,
78 images->cmdline_start, images->cmdline_end);
79 /* does not return */
80 error:
81 return 1;
82 }
83
set_clocks_in_mhz(struct bd_info * kbd)84 static void set_clocks_in_mhz (struct bd_info *kbd)
85 {
86 char *s;
87
88 s = env_get("clocks_in_mhz");
89 if (s) {
90 /* convert all clock information to MHz */
91 kbd->bi_intfreq /= 1000000L;
92 kbd->bi_busfreq /= 1000000L;
93 }
94 }
95