Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 1 | /* SPARC code for booting linux 2.6 |
| 2 | * |
| 3 | * (C) Copyright 2007 |
| 4 | * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com. |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <common.h> |
| 26 | #include <command.h> |
| 27 | #include <asm/byteorder.h> |
| 28 | #include <asm/prom.h> |
| 29 | #include <asm/cache.h> |
Daniel Hellstrom | af5eb84 | 2008-11-10 12:46:20 +0000 | [diff] [blame] | 30 | #include <image.h> |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 31 | |
| 32 | #define PRINT_KERNEL_HEADER |
| 33 | |
| 34 | extern image_header_t header; |
| 35 | extern void srmmu_init_cpu(unsigned int entry); |
| 36 | extern void prepare_bootargs(char *bootargs); |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 37 | |
| 38 | #ifdef CONFIG_USB_UHCI |
Lucas Stach | c7e3b2b | 2012-09-26 00:14:34 +0200 | [diff] [blame] | 39 | extern int usb_lowlevel_stop(int index); |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 40 | #endif |
| 41 | |
| 42 | /* sparc kernel argument (the ROM vector) */ |
| 43 | struct linux_romvec *kernel_arg_promvec; |
| 44 | |
| 45 | /* page szie is 4k */ |
| 46 | #define PAGE_SIZE 0x1000 |
| 47 | #define RAMDISK_IMAGE_START_MASK 0x07FF |
| 48 | #define RAMDISK_PROMPT_FLAG 0x8000 |
| 49 | #define RAMDISK_LOAD_FLAG 0x4000 |
| 50 | struct __attribute__ ((packed)) { |
| 51 | char traptable[PAGE_SIZE]; |
| 52 | char swapper_pg_dir[PAGE_SIZE]; |
| 53 | char pg0[PAGE_SIZE]; |
| 54 | char pg1[PAGE_SIZE]; |
| 55 | char pg2[PAGE_SIZE]; |
| 56 | char pg3[PAGE_SIZE]; |
| 57 | char empty_bad_page[PAGE_SIZE]; |
| 58 | char empty_bad_page_table[PAGE_SIZE]; |
| 59 | char empty_zero_page[PAGE_SIZE]; |
| 60 | unsigned char hdr[4]; /* ascii "HdrS" */ |
| 61 | /* 00.02.06.0b is for Linux kernel 2.6.11 */ |
| 62 | unsigned char linuxver_mega_major; |
| 63 | unsigned char linuxver_major; |
| 64 | unsigned char linuxver_minor; |
| 65 | unsigned char linuxver_revision; |
| 66 | /* header version 0x0203 */ |
| 67 | unsigned short hdr_ver; |
| 68 | union __attribute__ ((packed)) { |
| 69 | struct __attribute__ ((packed)) { |
| 70 | unsigned short root_flags; |
| 71 | unsigned short root_dev; |
| 72 | unsigned short ram_flags; |
| 73 | unsigned int sparc_ramdisk_image; |
| 74 | unsigned int sparc_ramdisk_size; |
| 75 | unsigned int reboot_command; |
| 76 | unsigned int resv[3]; |
| 77 | unsigned int end; |
| 78 | } ver_0203; |
| 79 | } hdr_input; |
| 80 | } *linux_hdr; |
| 81 | |
| 82 | /* temporary initrd image holder */ |
| 83 | image_header_t ihdr; |
| 84 | |
Kumar Gala | 76da19d | 2008-10-16 21:52:08 -0500 | [diff] [blame] | 85 | void arch_lmb_reserve(struct lmb *lmb) |
| 86 | { |
| 87 | /* Reserve the space used by PROM and stack. This is done |
| 88 | * to avoid that the RAM image is copied over stack or |
| 89 | * PROM. |
| 90 | */ |
| 91 | lmb_reserve(lmb, CONFIG_SYS_RELOC_MONITOR_BASE, CONFIG_SYS_RAM_END); |
| 92 | } |
| 93 | |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 94 | /* boot the linux kernel */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 95 | int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t * images) |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 96 | { |
| 97 | char *bootargs; |
Kumar Gala | c4f9419 | 2008-08-15 08:24:37 -0500 | [diff] [blame] | 98 | ulong rd_len; |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 99 | void (*kernel) (struct linux_romvec *, void *); |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 100 | int ret; |
| 101 | |
Andreas Bießmann | 2cb0e55 | 2013-07-02 13:57:44 +0200 | [diff] [blame^] | 102 | /* |
| 103 | * allow the PREP bootm subcommand, it is required for bootm to work |
| 104 | */ |
| 105 | if (flag & BOOTM_STATE_OS_PREP) |
| 106 | return 0; |
| 107 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 108 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 109 | return 1; |
| 110 | |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 111 | /* Get virtual address of kernel start */ |
Kumar Gala | 396f635 | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 112 | linux_hdr = (void *)images->os.load; |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 113 | |
| 114 | /* */ |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 115 | kernel = (void (*)(struct linux_romvec *, void *))images->ep; |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 116 | |
| 117 | /* check for a SPARC kernel */ |
| 118 | if ((linux_hdr->hdr[0] != 'H') || |
| 119 | (linux_hdr->hdr[1] != 'd') || |
| 120 | (linux_hdr->hdr[2] != 'r') || (linux_hdr->hdr[3] != 'S')) { |
| 121 | puts("Error reading header of SPARC Linux kernel, aborting\n"); |
| 122 | goto error; |
| 123 | } |
| 124 | #ifdef PRINT_KERNEL_HEADER |
| 125 | printf("## Found SPARC Linux kernel %d.%d.%d ...\n", |
| 126 | linux_hdr->linuxver_major, |
| 127 | linux_hdr->linuxver_minor, linux_hdr->linuxver_revision); |
| 128 | #endif |
| 129 | |
| 130 | #ifdef CONFIG_USB_UHCI |
| 131 | usb_lowlevel_stop(); |
| 132 | #endif |
| 133 | |
| 134 | /* set basic boot params in kernel header now that it has been |
| 135 | * extracted and is writeable. |
| 136 | */ |
| 137 | |
Simon Glass | 2a08b74 | 2013-05-08 08:06:06 +0000 | [diff] [blame] | 138 | ret = image_setup_linux(images); |
| 139 | if (ret) { |
| 140 | puts("### Failed to relocate RAM disk\n"); |
| 141 | goto error; |
| 142 | } |
| 143 | |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 144 | /* Calc length of RAM disk, if zero no ramdisk available */ |
Kumar Gala | c4f9419 | 2008-08-15 08:24:37 -0500 | [diff] [blame] | 145 | rd_len = images->rd_end - images->rd_start; |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 146 | |
| 147 | if (rd_len) { |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 148 | /* Update SPARC kernel header so that Linux knows |
| 149 | * what is going on and where to find RAM disk. |
| 150 | * |
| 151 | * Set INITRD Image address relative to RAM Start |
| 152 | */ |
| 153 | linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image = |
Simon Glass | 2a08b74 | 2013-05-08 08:06:06 +0000 | [diff] [blame] | 154 | images->initrd_start - CONFIG_SYS_RAM_BASE; |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 155 | linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = rd_len; |
| 156 | /* Clear READ ONLY flag if set to non-zero */ |
| 157 | linux_hdr->hdr_input.ver_0203.root_flags = 1; |
| 158 | /* Set root device to: Root_RAM0 */ |
| 159 | linux_hdr->hdr_input.ver_0203.root_dev = 0x100; |
| 160 | linux_hdr->hdr_input.ver_0203.ram_flags = 0; |
| 161 | } else { |
| 162 | /* NOT using RAMDISK image, overwriting kernel defaults */ |
| 163 | linux_hdr->hdr_input.ver_0203.sparc_ramdisk_image = 0; |
| 164 | linux_hdr->hdr_input.ver_0203.sparc_ramdisk_size = 0; |
| 165 | /* Leave to kernel defaults |
| 166 | linux_hdr->hdr_input.ver_0203.root_flags = 1; |
| 167 | linux_hdr->hdr_input.ver_0203.root_dev = 0; |
| 168 | linux_hdr->hdr_input.ver_0203.ram_flags = 0; |
| 169 | */ |
| 170 | } |
| 171 | |
| 172 | /* Copy bootargs from bootargs variable to kernel readable area */ |
| 173 | bootargs = getenv("bootargs"); |
| 174 | prepare_bootargs(bootargs); |
| 175 | |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 176 | /* turn on mmu & setup context table & page table for process 0 (kernel) */ |
| 177 | srmmu_init_cpu((unsigned int)kernel); |
| 178 | |
| 179 | /* Enter SPARC Linux kernel |
| 180 | * From now on the only code in u-boot that will be |
| 181 | * executed is the PROM code. |
| 182 | */ |
Daniel Hellstrom | af5eb84 | 2008-11-10 12:46:20 +0000 | [diff] [blame] | 183 | kernel(kernel_arg_promvec, (void *)images->ep); |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 184 | |
| 185 | /* It will never come to this... */ |
| 186 | while (1) ; |
| 187 | |
| 188 | error: |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 189 | return 1; |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 190 | } |