]> git.sur5r.net Git - u-boot/blob - lib_m68k/bootm.c
[new uImage] Factor out common image_get_ramdisk() routine
[u-boot] / lib_m68k / bootm.c
1 /*
2  * (C) Copyright 2003
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #include <common.h>
25 #include <command.h>
26 #include <image.h>
27 #include <zlib.h>
28 #include <bzlib.h>
29 #include <watchdog.h>
30 #include <environment.h>
31 #include <asm/byteorder.h>
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 #define PHYSADDR(x) x
36
37 #define LINUX_MAX_ENVS          256
38 #define LINUX_MAX_ARGS          256
39
40 #ifdef CONFIG_SHOW_BOOT_PROGRESS
41 # include <status_led.h>
42 # define SHOW_BOOT_PROGRESS(arg)        show_boot_progress(arg)
43 #else
44 # define SHOW_BOOT_PROGRESS(arg)
45 #endif
46
47 void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
48                     int argc, char *argv[],
49                     image_header_t *hdr, int verify)
50 {
51         ulong sp;
52
53         ulong rd_data_start, rd_data_end, rd_len;
54         ulong initrd_high;
55         ulong initrd_start, initrd_end;
56         int initrd_copy_to_ram = 1;
57
58         ulong cmd_start, cmd_end;
59         char *cmdline;
60         char *s;
61         bd_t *kbd;
62         void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
63
64         if ((s = getenv("initrd_high")) != NULL) {
65                 /* a value of "no" or a similar string will act like 0,
66                  * turning the "load high" feature off. This is intentional.
67                  */
68                 initrd_high = simple_strtoul(s, NULL, 16);
69                 if (initrd_high == ~0)
70                         initrd_copy_to_ram = 0;
71         } else {                /* not set, no restrictions to load high */
72                 initrd_high = ~0;
73         }
74
75 #ifdef CONFIG_LOGBUFFER
76         kbd = gd->bd;
77         /* Prevent initrd from overwriting logbuffer */
78         if (initrd_high < (kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD))
79                 initrd_high = kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD;
80         debug("## Logbuffer at 0x%08lX ", kbd->bi_memsize - LOGBUFF_LEN);
81 #endif
82
83         /*
84          * Booting a (Linux) kernel image
85          *
86          * Allocate space for command line and board info - the
87          * address should be as high as possible within the reach of
88          * the kernel (see CFG_BOOTMAPSZ settings), but in unused
89          * memory, which means far enough below the current stack
90          * pointer.
91          */
92         asm("movel %%a7, %%d0\n"
93             "movel %%d0, %0\n": "=d"(sp): :"%d0");
94
95         debug("## Current stack ends at 0x%08lX ", sp);
96
97         sp -= 2048;             /* just to be sure */
98         if (sp > CFG_BOOTMAPSZ)
99                 sp = CFG_BOOTMAPSZ;
100         sp &= ~0xF;
101
102         debug("=> set upper limit to 0x%08lX\n", sp);
103
104         cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
105         kbd = (bd_t *) (((ulong) cmdline - sizeof(bd_t)) & ~0xF);
106
107         if ((s = getenv("bootargs")) == NULL)
108                 s = "";
109
110         strcpy(cmdline, s);
111
112         cmd_start = (ulong) & cmdline[0];
113         cmd_end = cmd_start + strlen(cmdline);
114
115         *kbd = *(gd->bd);
116
117 #ifdef  DEBUG
118         printf("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
119
120         do_bdinfo(NULL, 0, 0, NULL);
121 #endif
122
123         if ((s = getenv("clocks_in_mhz")) != NULL) {
124                 /* convert all clock information to MHz */
125                 kbd->bi_intfreq /= 1000000L;
126                 kbd->bi_busfreq /= 1000000L;
127         }
128
129         kernel =
130             (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
131
132         get_ramdisk (cmdtp, flag, argc, argv, hdr, verify,
133                         IH_ARCH_M68K, &rd_data_start, &rd_data_end);
134         rd_len = rd_data_end - rd_data_start;
135
136         if (rd_data_start) {
137                 if (!initrd_copy_to_ram) {      /* zero-copy ramdisk support */
138                         initrd_start = rd_data_start;
139                         initrd_end = rd_data_end;
140                 } else {
141                         initrd_start = (ulong) kbd - rd_len;
142                         initrd_start &= ~(4096 - 1);    /* align on page */
143
144                         if (initrd_high) {
145                                 ulong nsp;
146
147                                 /*
148                                  * the inital ramdisk does not need to be within
149                                  * CFG_BOOTMAPSZ as it is not accessed until after
150                                  * the mm system is initialised.
151                                  *
152                                  * do the stack bottom calculation again and see if
153                                  * the initrd will fit just below the monitor stack
154                                  * bottom without overwriting the area allocated
155                                  * above for command line args and board info.
156                                  */
157                                 asm("movel %%a7, %%d0\n"
158                                     "movel %%d0, %0\n": "=d"(nsp): :"%d0");
159
160                                 nsp -= 2048;    /* just to be sure */
161                                 nsp &= ~0xF;
162
163                                 if (nsp > initrd_high)  /* limit as specified */
164                                         nsp = initrd_high;
165
166                                         nsp -= rd_len;
167                                 nsp &= ~(4096 - 1);     /* align on page */
168
169                                 if (nsp >= sp)
170                                         initrd_start = nsp;
171                         }
172
173                         SHOW_BOOT_PROGRESS(12);
174
175                         debug
176                             ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
177                              rd_data_start, rd_data_end - 1, rd_len, rd_len);
178
179                         initrd_end = initrd_start + rd_len;
180                         printf("   Loading Ramdisk to %08lx, end %08lx ... ",
181                                initrd_start, initrd_end);
182
183                         memmove_wd((void *)initrd_start,
184                                    (void *)rd_data_start, rd_len, CHUNKSZ);
185
186                         puts("OK\n");
187                 }
188         } else {
189                 initrd_start = 0;
190                 initrd_end = 0;
191         }
192
193         debug("## Transferring control to Linux (at address %08lx) ...\n",
194               (ulong) kernel);
195
196         SHOW_BOOT_PROGRESS(15);
197
198         /*
199          * Linux Kernel Parameters (passing board info data):
200          *   r3: ptr to board info data
201          *   r4: initrd_start or 0 if no initrd
202          *   r5: initrd_end - unused if r4 is 0
203          *   r6: Start of command line string
204          *   r7: End   of command line string
205          */
206         (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
207         /* does not return */
208 }