blob: 49757595f7129c104252f15bf67462cd768c9c5d [file] [log] [blame]
Daniel Hellstromc2f02da2008-03-28 09:47:00 +01001/* SPARC code for booting linux 2.6
2 *
3 * (C) Copyright 2007
4 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <command.h>
27#include <asm/byteorder.h>
28#include <asm/prom.h>
29#include <asm/cache.h>
30
31#define PRINT_KERNEL_HEADER
32
33extern image_header_t header;
34extern void srmmu_init_cpu(unsigned int entry);
35extern void prepare_bootargs(char *bootargs);
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010036
37#ifdef CONFIG_USB_UHCI
38extern int usb_lowlevel_stop(void);
39#endif
40
41/* sparc kernel argument (the ROM vector) */
42struct linux_romvec *kernel_arg_promvec;
43
44/* page szie is 4k */
45#define PAGE_SIZE 0x1000
46#define RAMDISK_IMAGE_START_MASK 0x07FF
47#define RAMDISK_PROMPT_FLAG 0x8000
48#define RAMDISK_LOAD_FLAG 0x4000
49struct __attribute__ ((packed)) {
50 char traptable[PAGE_SIZE];
51 char swapper_pg_dir[PAGE_SIZE];
52 char pg0[PAGE_SIZE];
53 char pg1[PAGE_SIZE];
54 char pg2[PAGE_SIZE];
55 char pg3[PAGE_SIZE];
56 char empty_bad_page[PAGE_SIZE];
57 char empty_bad_page_table[PAGE_SIZE];
58 char empty_zero_page[PAGE_SIZE];
59 unsigned char hdr[4]; /* ascii "HdrS" */
60 /* 00.02.06.0b is for Linux kernel 2.6.11 */
61 unsigned char linuxver_mega_major;
62 unsigned char linuxver_major;
63 unsigned char linuxver_minor;
64 unsigned char linuxver_revision;
65 /* header version 0x0203 */
66 unsigned short hdr_ver;
67 union __attribute__ ((packed)) {
68 struct __attribute__ ((packed)) {
69 unsigned short root_flags;
70 unsigned short root_dev;
71 unsigned short ram_flags;
72 unsigned int sparc_ramdisk_image;
73 unsigned int sparc_ramdisk_size;
74 unsigned int reboot_command;
75 unsigned int resv[3];
76 unsigned int end;
77 } ver_0203;
78 } hdr_input;
79} *linux_hdr;
80
81/* temporary initrd image holder */
82image_header_t ihdr;
83
Kumar Gala76da19d2008-10-16 21:52:08 -050084void arch_lmb_reserve(struct lmb *lmb)
85{
86 /* Reserve the space used by PROM and stack. This is done
87 * to avoid that the RAM image is copied over stack or
88 * PROM.
89 */
90 lmb_reserve(lmb, CONFIG_SYS_RELOC_MONITOR_BASE, CONFIG_SYS_RAM_END);
91}
92
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010093/* boot the linux kernel */
Kumar Gala40d7e992008-08-15 08:24:45 -050094int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t * images)
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010095{
96 char *bootargs;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010097 ulong initrd_start, initrd_end;
Kumar Galac4f94192008-08-15 08:24:37 -050098 ulong rd_len;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010099 unsigned int data, len, checksum;
100 unsigned int initrd_addr, kernend;
101 void (*kernel) (struct linux_romvec *, void *);
Kumar Galae906cfa2008-08-15 08:24:40 -0500102 struct lmb *lmb = &images->lmb;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100103 int ret;
104
Kumar Gala49c3a862008-10-21 17:25:45 -0500105 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
106 return 1;
107
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100108 /* Get virtual address of kernel start */
Kumar Gala396f6352008-08-15 08:24:41 -0500109 linux_hdr = (void *)images->os.load;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100110
111 /* */
Kumar Galac160a952008-08-15 08:24:36 -0500112 kernel = (void (*)(struct linux_romvec *, void *))images->ep;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100113
114 /* check for a SPARC kernel */
115 if ((linux_hdr->hdr[0] != 'H') ||
116 (linux_hdr->hdr[1] != 'd') ||
117 (linux_hdr->hdr[2] != 'r') || (linux_hdr->hdr[3] != 'S')) {
118 puts("Error reading header of SPARC Linux kernel, aborting\n");
119 goto error;
120 }
121#ifdef PRINT_KERNEL_HEADER
122 printf("## Found SPARC Linux kernel %d.%d.%d ...\n",
123 linux_hdr->linuxver_major,
124 linux_hdr->linuxver_minor, linux_hdr->linuxver_revision);
125#endif
126
127#ifdef CONFIG_USB_UHCI
128 usb_lowlevel_stop();
129#endif
130
131 /* set basic boot params in kernel header now that it has been
132 * extracted and is writeable.
133 */
134
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100135 /* Calc length of RAM disk, if zero no ramdisk available */
Kumar Galac4f94192008-08-15 08:24:37 -0500136 rd_len = images->rd_end - images->rd_start;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100137
138 if (rd_len) {
Kumar Galac4f94192008-08-15 08:24:37 -0500139 ret = boot_ramdisk_high(lmb, images->rd_start, rd_len,
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100140 &initrd_start, &initrd_end);
141 if (ret) {
142 puts("### Failed to relocate RAM disk\n");
143 goto error;
144 }
145
146 /* Update SPARC kernel header so that Linux knows
147 * what is going on and where to find RAM disk.
148 *
149 * Set INITRD Image address relative to RAM Start
150 */
151 linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200152 initrd_start - CONFIG_SYS_RAM_BASE;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100153 linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = rd_len;
154 /* Clear READ ONLY flag if set to non-zero */
155 linux_hdr->hdr_input.ver_0203.root_flags = 1;
156 /* Set root device to: Root_RAM0 */
157 linux_hdr->hdr_input.ver_0203.root_dev = 0x100;
158 linux_hdr->hdr_input.ver_0203.ram_flags = 0;
159 } else {
160 /* NOT using RAMDISK image, overwriting kernel defaults */
161 linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image = 0;
162 linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = 0;
163 /* Leave to kernel defaults
164 linux_hdr->hdr_input.ver_0203.root_flags = 1;
165 linux_hdr->hdr_input.ver_0203.root_dev = 0;
166 linux_hdr->hdr_input.ver_0203.ram_flags = 0;
167 */
168 }
169
170 /* Copy bootargs from bootargs variable to kernel readable area */
171 bootargs = getenv("bootargs");
172 prepare_bootargs(bootargs);
173
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100174 /* turn on mmu & setup context table & page table for process 0 (kernel) */
175 srmmu_init_cpu((unsigned int)kernel);
176
177 /* Enter SPARC Linux kernel
178 * From now on the only code in u-boot that will be
179 * executed is the PROM code.
180 */
181 kernel(kernel_arg_promvec, (void *)ep);
182
183 /* It will never come to this... */
184 while (1) ;
185
186 error:
Kumar Gala40d7e992008-08-15 08:24:45 -0500187 return 1;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100188}