blob: 9e2b78464dceceefee980d10cc98157e9f9a1113 [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Daniel Hellstromc2f02da2008-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 Hellstromaf5eb842008-11-10 12:46:20 +000014#include <image.h>
Daniel Hellstromc2f02da2008-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 Hellstromc2f02da2008-03-28 09:47:00 +010021
22#ifdef CONFIG_USB_UHCI
Lucas Stachc7e3b2b2012-09-26 00:14:34 +020023extern int usb_lowlevel_stop(int index);
Daniel Hellstromc2f02da2008-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 Gala76da19d2008-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 Hellstromc2f02da2008-03-28 09:47:00 +010078/* boot the linux kernel */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020079int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t * images)
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010080{
81 char *bootargs;
Kumar Galac4f94192008-08-15 08:24:37 -050082 ulong rd_len;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010083 void (*kernel) (struct linux_romvec *, void *);
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010084 int ret;
85
Andreas Bießmann2cb0e552013-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 Gala49c3a862008-10-21 17:25:45 -050092 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
93 return 1;
94
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010095 /* Get virtual address of kernel start */
Kumar Gala396f6352008-08-15 08:24:41 -050096 linux_hdr = (void *)images->os.load;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010097
98 /* */
Kumar Galac160a952008-08-15 08:24:36 -050099 kernel = (void (*)(struct linux_romvec *, void *))images->ep;
Daniel Hellstromc2f02da2008-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 Glass2a08b742013-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 Hellstromc2f02da2008-03-28 09:47:00 +0100128 /* Calc length of RAM disk, if zero no ramdisk available */
Kumar Galac4f94192008-08-15 08:24:37 -0500129 rd_len = images->rd_end - images->rd_start;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100130
131 if (rd_len) {
Daniel Hellstromc2f02da2008-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 Glass2a08b742013-05-08 08:06:06 +0000138 images->initrd_start - CONFIG_SYS_RAM_BASE;
Daniel Hellstromc2f02da2008-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 Hellstromc2f02da2008-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 Hellstromaf5eb842008-11-10 12:46:20 +0000167 kernel(kernel_arg_promvec, (void *)images->ep);
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100168
169 /* It will never come to this... */
170 while (1) ;
171
172 error:
Kumar Gala40d7e992008-08-15 08:24:45 -0500173 return 1;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100174}