]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/sparc/lib/bootm.c
Merge branch 'u-boot-ti/master' into 'u-boot-arm/master'
[karo-tx-uboot.git] / arch / sparc / lib / bootm.c
1 /* SPARC code for booting linux 2.6
2  *
3  * (C) Copyright 2007
4  * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <common.h>
10 #include <command.h>
11 #include <asm/byteorder.h>
12 #include <asm/prom.h>
13 #include <asm/cache.h>
14 #include <image.h>
15
16 #define PRINT_KERNEL_HEADER
17
18 extern image_header_t header;
19 extern void srmmu_init_cpu(unsigned int entry);
20 extern void prepare_bootargs(char *bootargs);
21
22 #ifdef CONFIG_USB_UHCI
23 extern int usb_lowlevel_stop(int index);
24 #endif
25
26 /* sparc kernel argument (the ROM vector) */
27 struct 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
34 struct __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 */
67 image_header_t ihdr;
68
69 void 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
78 /* boot the linux kernel */
79 int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t * images)
80 {
81         char *bootargs;
82         ulong rd_len;
83         void (*kernel) (struct linux_romvec *, void *);
84         int ret;
85
86         /*
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
92         if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
93                 return 1;
94
95         /* Get virtual address of kernel start */
96         linux_hdr = (void *)images->os.load;
97
98         /* */
99         kernel = (void (*)(struct linux_romvec *, void *))images->ep;
100
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
122         ret = image_setup_linux(images);
123         if (ret) {
124                 puts("### Failed to relocate RAM disk\n");
125                 goto error;
126         }
127
128         /* Calc length of RAM disk, if zero no ramdisk available */
129         rd_len = images->rd_end - images->rd_start;
130
131         if (rd_len) {
132                 /* 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 =
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;
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
160         /* 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          */
167         kernel(kernel_arg_promvec, (void *)images->ep);
168
169         /* It will never come to this... */
170         while (1) ;
171
172       error:
173         return 1;
174 }