blob: 9e2b78464dceceefee980d10cc98157e9f9a1113 [file] [log] [blame]
Daniel Hellstrom9d7c6b22008-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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +01007 */
8
9#include <common.h>
10#include <command.h>
11#include <asm/byteorder.h>
12#include <asm/prom.h>
13#include <asm/cache.h>
Daniel Hellstromecf05d42008-11-10 12:46:20 +000014#include <image.h>
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +010015
16#define PRINT_KERNEL_HEADER
17
18extern image_header_t header;
19extern void srmmu_init_cpu(unsigned int entry);
20extern void prepare_bootargs(char *bootargs);
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +010021
22#ifdef CONFIG_USB_UHCI
Lucas Stacha3231282012-09-26 00:14:34 +020023extern int usb_lowlevel_stop(int index);
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +010024#endif
25
26/* sparc kernel argument (the ROM vector) */
27struct linux_romvec *kernel_arg_promvec;
28
29/* page szie is 4k */
30#define PAGE_SIZE 0x1000
31#define RAMDISK_IMAGE_START_MASK 0x07FF
32#define RAMDISK_PROMPT_FLAG 0x8000
33#define RAMDISK_LOAD_FLAG 0x4000
34struct __attribute__ ((packed)) {
35 char traptable[PAGE_SIZE];
36 char swapper_pg_dir[PAGE_SIZE];
37 char pg0[PAGE_SIZE];
38 char pg1[PAGE_SIZE];
39 char pg2[PAGE_SIZE];
40 char pg3[PAGE_SIZE];
41 char empty_bad_page[PAGE_SIZE];
42 char empty_bad_page_table[PAGE_SIZE];
43 char empty_zero_page[PAGE_SIZE];
44 unsigned char hdr[4]; /* ascii "HdrS" */
45 /* 00.02.06.0b is for Linux kernel 2.6.11 */
46 unsigned char linuxver_mega_major;
47 unsigned char linuxver_major;
48 unsigned char linuxver_minor;
49 unsigned char linuxver_revision;
50 /* header version 0x0203 */
51 unsigned short hdr_ver;
52 union __attribute__ ((packed)) {
53 struct __attribute__ ((packed)) {
54 unsigned short root_flags;
55 unsigned short root_dev;
56 unsigned short ram_flags;
57 unsigned int sparc_ramdisk_image;
58 unsigned int sparc_ramdisk_size;
59 unsigned int reboot_command;
60 unsigned int resv[3];
61 unsigned int end;
62 } ver_0203;
63 } hdr_input;
64} *linux_hdr;
65
66/* temporary initrd image holder */
67image_header_t ihdr;
68
Kumar Galab02d7222008-10-16 21:52:08 -050069void arch_lmb_reserve(struct lmb *lmb)
70{
71 /* Reserve the space used by PROM and stack. This is done
72 * to avoid that the RAM image is copied over stack or
73 * PROM.
74 */
75 lmb_reserve(lmb, CONFIG_SYS_RELOC_MONITOR_BASE, CONFIG_SYS_RAM_END);
76}
77
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +010078/* boot the linux kernel */
Wolfgang Denk6262d0212010-06-28 22:00:46 +020079int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t * images)
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +010080{
81 char *bootargs;
Kumar Galafffb1432008-08-15 08:24:37 -050082 ulong rd_len;
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +010083 void (*kernel) (struct linux_romvec *, void *);
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +010084 int ret;
85
Andreas Bießmannda233ce2013-07-02 13:57:44 +020086 /*
87 * allow the PREP bootm subcommand, it is required for bootm to work
88 */
89 if (flag & BOOTM_STATE_OS_PREP)
90 return 0;
91
Kumar Gala18178bc2008-10-21 17:25:45 -050092 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
93 return 1;
94
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +010095 /* Get virtual address of kernel start */
Kumar Galabd70bbe2008-08-15 08:24:41 -050096 linux_hdr = (void *)images->os.load;
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +010097
98 /* */
Kumar Gala93467bc2008-08-15 08:24:36 -050099 kernel = (void (*)(struct linux_romvec *, void *))images->ep;
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +0100100
101 /* check for a SPARC kernel */
102 if ((linux_hdr->hdr[0] != 'H') ||
103 (linux_hdr->hdr[1] != 'd') ||
104 (linux_hdr->hdr[2] != 'r') || (linux_hdr->hdr[3] != 'S')) {
105 puts("Error reading header of SPARC Linux kernel, aborting\n");
106 goto error;
107 }
108#ifdef PRINT_KERNEL_HEADER
109 printf("## Found SPARC Linux kernel %d.%d.%d ...\n",
110 linux_hdr->linuxver_major,
111 linux_hdr->linuxver_minor, linux_hdr->linuxver_revision);
112#endif
113
114#ifdef CONFIG_USB_UHCI
115 usb_lowlevel_stop();
116#endif
117
118 /* set basic boot params in kernel header now that it has been
119 * extracted and is writeable.
120 */
121
Simon Glasse9c6b3d2013-05-08 08:06:06 +0000122 ret = image_setup_linux(images);
123 if (ret) {
124 puts("### Failed to relocate RAM disk\n");
125 goto error;
126 }
127
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +0100128 /* Calc length of RAM disk, if zero no ramdisk available */
Kumar Galafffb1432008-08-15 08:24:37 -0500129 rd_len = images->rd_end - images->rd_start;
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +0100130
131 if (rd_len) {
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +0100132 /* Update SPARC kernel header so that Linux knows
133 * what is going on and where to find RAM disk.
134 *
135 * Set INITRD Image address relative to RAM Start
136 */
137 linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image =
Simon Glasse9c6b3d2013-05-08 08:06:06 +0000138 images->initrd_start - CONFIG_SYS_RAM_BASE;
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +0100139 linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = rd_len;
140 /* Clear READ ONLY flag if set to non-zero */
141 linux_hdr->hdr_input.ver_0203.root_flags = 1;
142 /* Set root device to: Root_RAM0 */
143 linux_hdr->hdr_input.ver_0203.root_dev = 0x100;
144 linux_hdr->hdr_input.ver_0203.ram_flags = 0;
145 } else {
146 /* NOT using RAMDISK image, overwriting kernel defaults */
147 linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image = 0;
148 linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = 0;
149 /* Leave to kernel defaults
150 linux_hdr->hdr_input.ver_0203.root_flags = 1;
151 linux_hdr->hdr_input.ver_0203.root_dev = 0;
152 linux_hdr->hdr_input.ver_0203.ram_flags = 0;
153 */
154 }
155
156 /* Copy bootargs from bootargs variable to kernel readable area */
157 bootargs = getenv("bootargs");
158 prepare_bootargs(bootargs);
159
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +0100160 /* turn on mmu & setup context table & page table for process 0 (kernel) */
161 srmmu_init_cpu((unsigned int)kernel);
162
163 /* Enter SPARC Linux kernel
164 * From now on the only code in u-boot that will be
165 * executed is the PROM code.
166 */
Daniel Hellstromecf05d42008-11-10 12:46:20 +0000167 kernel(kernel_arg_promvec, (void *)images->ep);
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +0100168
169 /* It will never come to this... */
170 while (1) ;
171
172 error:
Kumar Gala48626aa2008-08-15 08:24:45 -0500173 return 1;
Daniel Hellstrom9d7c6b22008-03-28 09:47:00 +0100174}