blob: c976904fa9ca5d198a06278af9da82a0e90cb4eb [file] [log] [blame]
wdenk4e5ca3e2003-12-08 01:34:36 +00001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk4e5ca3e2003-12-08 01:34:36 +00006 */
7
8#include <common.h>
9#include <command.h>
wdenk4e5ca3e2003-12-08 01:34:36 +000010#include <image.h>
Jean-Christophe PLAGNIOL-VILLARDa31e0912009-04-04 12:49:11 +020011#include <u-boot/zlib.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050012#include <bzlib.h>
TsiChungLiew688e8eb2007-10-25 17:14:00 -050013#include <watchdog.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050014#include <environment.h>
wdenk4e5ca3e2003-12-08 01:34:36 +000015#include <asm/byteorder.h>
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010016#ifdef CONFIG_SHOW_BOOT_PROGRESS
17# include <status_led.h>
18#endif
wdenk4e5ca3e2003-12-08 01:34:36 +000019
Wolfgang Denkd87080b2006-03-31 18:32:53 +020020DECLARE_GLOBAL_DATA_PTR;
21
wdenk4e5ca3e2003-12-08 01:34:36 +000022#define PHYSADDR(x) x
23
wdenkbf9e3b32004-02-12 00:47:09 +000024#define LINUX_MAX_ENVS 256
25#define LINUX_MAX_ARGS 256
wdenk4e5ca3e2003-12-08 01:34:36 +000026
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010027static ulong get_sp (void);
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010028static void set_clocks_in_mhz (bd_t *kbd);
Marian Balakowiczceaed2b2008-01-31 13:57:17 +010029
Kumar Gala76da19d2008-10-16 21:52:08 -050030void arch_lmb_reserve(struct lmb *lmb)
wdenk4e5ca3e2003-12-08 01:34:36 +000031{
Kumar Galae822d7f2008-02-27 21:51:49 -060032 ulong sp;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010033
TsiChungLiew8ae158c2007-08-16 15:05:11 -050034 /*
35 * Booting a (Linux) kernel image
36 *
37 * Allocate space for command line and board info - the
38 * address should be as high as possible within the reach of
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020039 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
TsiChungLiew8ae158c2007-08-16 15:05:11 -050040 * memory, which means far enough below the current stack
41 * pointer.
42 */
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010043 sp = get_sp();
44 debug ("## Current stack ends at 0x%08lx ", sp);
Stefan Roese8280f6a2007-08-18 14:33:02 +020045
Kumar Galae822d7f2008-02-27 21:51:49 -060046 /* adjust sp by 1K to be safe */
47 sp -= 1024;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020048 lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
Kumar Gala76da19d2008-10-16 21:52:08 -050049}
50
Wolfgang Denk54841ab2010-06-28 22:00:46 +020051int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images)
Kumar Gala76da19d2008-10-16 21:52:08 -050052{
Kumar Gala76da19d2008-10-16 21:52:08 -050053 int ret;
Kumar Gala76da19d2008-10-16 21:52:08 -050054 bd_t *kbd;
55 void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
56 struct lmb *lmb = &images->lmb;
57
Andreas Bießmann2cb0e552013-07-02 13:57:44 +020058 /*
59 * allow the PREP bootm subcommand, it is required for bootm to work
60 */
61 if (flag & BOOTM_STATE_OS_PREP)
62 return 0;
63
Kumar Gala49c3a862008-10-21 17:25:45 -050064 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
65 return 1;
66
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010067 /* allocate space for kernel copy of board info */
Grant Likely590d3ca2011-03-28 09:58:34 +000068 ret = boot_get_kbd (lmb, &kbd);
Kumar Galae822d7f2008-02-27 21:51:49 -060069 if (ret) {
70 puts("ERROR with allocation of kernel bd\n");
71 goto error;
72 }
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +010073 set_clocks_in_mhz(kbd);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050074
Simon Glass24507cf2013-05-08 08:06:05 +000075 ret = image_setup_linux(images);
Kumar Galae822d7f2008-02-27 21:51:49 -060076 if (ret)
77 goto error;
wdenk4e5ca3e2003-12-08 01:34:36 +000078
Simon Glass24507cf2013-05-08 08:06:05 +000079 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))images->ep;
80
TsiChungLiew8ae158c2007-08-16 15:05:11 -050081 debug("## Transferring control to Linux (at address %08lx) ...\n",
82 (ulong) kernel);
wdenk4e5ca3e2003-12-08 01:34:36 +000083
Simon Glass770605e2012-02-13 13:51:18 +000084 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenk4e5ca3e2003-12-08 01:34:36 +000085
TsiChungLiew8ae158c2007-08-16 15:05:11 -050086 /*
87 * Linux Kernel Parameters (passing board info data):
Richard Retanubunedff7bc2009-02-20 13:01:56 -050088 * sp+00: Ignore, side effect of using jsr to jump to kernel
89 * sp+04: ptr to board info data
90 * sp+08: initrd_start or 0 if no initrd
91 * sp+12: initrd_end - unused if initrd_start is 0
92 * sp+16: Start of command line string
93 * sp+20: End of command line string
TsiChungLiew8ae158c2007-08-16 15:05:11 -050094 */
Simon Glassddc94372014-06-07 22:07:58 -060095 (*kernel)(kbd, images->initrd_start, images->initrd_end,
96 images->cmdline_start, images->cmdline_end);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050097 /* does not return */
Kumar Gala274cea22008-02-27 21:51:46 -060098error:
Kumar Gala40d7e992008-08-15 08:24:45 -050099 return 1;
wdenk4e5ca3e2003-12-08 01:34:36 +0000100}
Marian Balakowiczceaed2b2008-01-31 13:57:17 +0100101
102static ulong get_sp (void)
103{
104 ulong sp;
105
106 asm("movel %%a7, %%d0\n"
107 "movel %%d0, %0\n": "=d"(sp): :"%d0");
108
109 return sp;
110}
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +0100111
112static void set_clocks_in_mhz (bd_t *kbd)
113{
114 char *s;
115
Simon Glass00caae62017-08-03 12:22:12 -0600116 s = env_get("clocks_in_mhz");
117 if (s) {
Marian Balakowiczb6b0fe62008-01-31 13:58:13 +0100118 /* convert all clock information to MHz */
119 kbd->bi_intfreq /= 1000000L;
120 kbd->bi_busfreq /= 1000000L;
121 }
122}