1 /* SPARC code for booting linux 2.6
4 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/byteorder.h>
13 #include <asm/cache.h>
16 #define PRINT_KERNEL_HEADER
18 extern image_header_t header;
19 extern void srmmu_init_cpu(unsigned int entry);
20 extern void prepare_bootargs(char *bootargs);
22 #ifdef CONFIG_USB_UHCI
23 extern int usb_lowlevel_stop(int index);
26 /* sparc kernel argument (the ROM vector) */
27 struct linux_romvec *kernel_arg_promvec;
30 #define PAGE_SIZE 0x1000
31 #define RAMDISK_IMAGE_START_MASK 0x07FF
32 #define RAMDISK_PROMPT_FLAG 0x8000
33 #define RAMDISK_LOAD_FLAG 0x4000
34 struct __attribute__ ((packed)) {
35 char traptable[PAGE_SIZE];
36 char swapper_pg_dir[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;
66 /* temporary initrd image holder */
69 void arch_lmb_reserve(struct lmb *lmb)
71 /* Reserve the space used by PROM and stack. This is done
72 * to avoid that the RAM image is copied over stack or
75 lmb_reserve(lmb, CONFIG_SYS_RELOC_MONITOR_BASE, CONFIG_SYS_RAM_END);
78 /* boot the linux kernel */
79 int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t * images)
83 void (*kernel) (struct linux_romvec *, void *);
87 * allow the PREP bootm subcommand, it is required for bootm to work
89 if (flag & BOOTM_STATE_OS_PREP)
92 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
95 /* Get virtual address of kernel start */
96 linux_hdr = (void *)images->os.load;
99 kernel = (void (*)(struct linux_romvec *, void *))images->ep;
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");
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);
114 #ifdef CONFIG_USB_UHCI
118 /* set basic boot params in kernel header now that it has been
119 * extracted and is writeable.
122 ret = image_setup_linux(images);
124 puts("### Failed to relocate RAM disk\n");
128 /* Calc length of RAM disk, if zero no ramdisk available */
129 rd_len = images->rd_end - images->rd_start;
132 /* Update SPARC kernel header so that Linux knows
133 * what is going on and where to find RAM disk.
135 * Set INITRD Image address relative to RAM Start
137 linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image =
138 images->initrd_start - CONFIG_SYS_RAM_BASE;
139 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;
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;
156 /* Copy bootargs from bootargs variable to kernel readable area */
157 bootargs = getenv("bootargs");
158 prepare_bootargs(bootargs);
160 /* turn on mmu & setup context table & page table for process 0 (kernel) */
161 srmmu_init_cpu((unsigned int)kernel);
163 /* Enter SPARC Linux kernel
164 * From now on the only code in u-boot that will be
165 * executed is the PROM code.
167 kernel(kernel_arg_promvec, (void *)images->ep);
169 /* It will never come to this... */