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 /* sparc kernel argument (the ROM vector) */
23 struct linux_romvec
*kernel_arg_promvec
;
26 #define PAGE_SIZE 0x1000
27 #define RAMDISK_IMAGE_START_MASK 0x07FF
28 #define RAMDISK_PROMPT_FLAG 0x8000
29 #define RAMDISK_LOAD_FLAG 0x4000
30 struct __attribute__ ((packed
)) {
31 char traptable
[PAGE_SIZE
];
32 char swapper_pg_dir
[PAGE_SIZE
];
37 char empty_bad_page
[PAGE_SIZE
];
38 char empty_bad_page_table
[PAGE_SIZE
];
39 char empty_zero_page
[PAGE_SIZE
];
40 unsigned char hdr
[4]; /* ascii "HdrS" */
41 /* 00.02.06.0b is for Linux kernel 2.6.11 */
42 unsigned char linuxver_mega_major
;
43 unsigned char linuxver_major
;
44 unsigned char linuxver_minor
;
45 unsigned char linuxver_revision
;
46 /* header version 0x0203 */
47 unsigned short hdr_ver
;
48 union __attribute__ ((packed
)) {
49 struct __attribute__ ((packed
)) {
50 unsigned short root_flags
;
51 unsigned short root_dev
;
52 unsigned short ram_flags
;
53 unsigned int sparc_ramdisk_image
;
54 unsigned int sparc_ramdisk_size
;
55 unsigned int reboot_command
;
62 /* temporary initrd image holder */
65 void arch_lmb_reserve(struct lmb
*lmb
)
67 /* Reserve the space used by PROM and stack. This is done
68 * to avoid that the RAM image is copied over stack or
71 lmb_reserve(lmb
, CONFIG_SYS_RELOC_MONITOR_BASE
, CONFIG_SYS_RAM_END
);
74 /* boot the linux kernel */
75 int do_bootm_linux(int flag
, int argc
, char * const argv
[], bootm_headers_t
* images
)
79 void (*kernel
) (struct linux_romvec
*, void *);
83 * allow the PREP bootm subcommand, it is required for bootm to work
85 if (flag
& BOOTM_STATE_OS_PREP
)
88 if ((flag
!= 0) && (flag
!= BOOTM_STATE_OS_GO
))
91 /* Get virtual address of kernel start */
92 linux_hdr
= (void *)images
->os
.load
;
95 kernel
= (void (*)(struct linux_romvec
*, void *))images
->ep
;
97 /* check for a SPARC kernel */
98 if ((linux_hdr
->hdr
[0] != 'H') ||
99 (linux_hdr
->hdr
[1] != 'd') ||
100 (linux_hdr
->hdr
[2] != 'r') || (linux_hdr
->hdr
[3] != 'S')) {
101 puts("Error reading header of SPARC Linux kernel, aborting\n");
104 #ifdef PRINT_KERNEL_HEADER
105 printf("## Found SPARC Linux kernel %d.%d.%d ...\n",
106 linux_hdr
->linuxver_major
,
107 linux_hdr
->linuxver_minor
, linux_hdr
->linuxver_revision
);
110 /* set basic boot params in kernel header now that it has been
111 * extracted and is writeable.
114 ret
= image_setup_linux(images
);
116 puts("### Failed to relocate RAM disk\n");
120 /* Calc length of RAM disk, if zero no ramdisk available */
121 rd_len
= images
->rd_end
- images
->rd_start
;
124 /* Update SPARC kernel header so that Linux knows
125 * what is going on and where to find RAM disk.
127 * Set INITRD Image address relative to RAM Start
129 linux_hdr
->hdr_input
.ver_0203
.sparc_ramdisk_image
=
130 images
->initrd_start
- CONFIG_SYS_RAM_BASE
;
131 linux_hdr
->hdr_input
.ver_0203
.sparc_ramdisk_size
= rd_len
;
132 /* Clear READ ONLY flag if set to non-zero */
133 linux_hdr
->hdr_input
.ver_0203
.root_flags
= 1;
134 /* Set root device to: Root_RAM0 */
135 linux_hdr
->hdr_input
.ver_0203
.root_dev
= 0x100;
136 linux_hdr
->hdr_input
.ver_0203
.ram_flags
= 0;
138 /* NOT using RAMDISK image, overwriting kernel defaults */
139 linux_hdr
->hdr_input
.ver_0203
.sparc_ramdisk_image
= 0;
140 linux_hdr
->hdr_input
.ver_0203
.sparc_ramdisk_size
= 0;
141 /* Leave to kernel defaults
142 linux_hdr->hdr_input.ver_0203.root_flags = 1;
143 linux_hdr->hdr_input.ver_0203.root_dev = 0;
144 linux_hdr->hdr_input.ver_0203.ram_flags = 0;
148 /* Copy bootargs from bootargs variable to kernel readable area */
149 bootargs
= getenv("bootargs");
150 prepare_bootargs(bootargs
);
152 /* turn on mmu & setup context table & page table for process 0 (kernel) */
153 srmmu_init_cpu((unsigned int)kernel
);
155 /* Enter SPARC Linux kernel
156 * From now on the only code in u-boot that will be
157 * executed is the PROM code.
159 kernel(kernel_arg_promvec
, (void *)images
->ep
);
161 /* It will never come to this... */