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