Daniel Hellstrom | 9d7c6b2 | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 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> |
Daniel Hellstrom | ecf05d4 | 2008-11-10 12:46:20 +0000 | [diff] [blame] | 14 | #include <image.h> |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 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); |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 21 | |
| 22 | #ifdef CONFIG_USB_UHCI |
Lucas Stach | a323128 | 2012-09-26 00:14:34 +0200 | [diff] [blame] | 23 | extern int usb_lowlevel_stop(int index); |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 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 | |
Kumar Gala | b02d722 | 2008-10-16 21:52:08 -0500 | [diff] [blame] | 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 | |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 78 | /* boot the linux kernel */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 79 | int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t * images) |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 80 | { |
| 81 | char *bootargs; |
Kumar Gala | fffb143 | 2008-08-15 08:24:37 -0500 | [diff] [blame] | 82 | ulong rd_len; |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 83 | void (*kernel) (struct linux_romvec *, void *); |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 84 | int ret; |
| 85 | |
Andreas Bießmann | da233ce | 2013-07-02 13:57:44 +0200 | [diff] [blame] | 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 | |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 92 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 93 | return 1; |
| 94 | |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 95 | /* Get virtual address of kernel start */ |
Kumar Gala | bd70bbe | 2008-08-15 08:24:41 -0500 | [diff] [blame] | 96 | linux_hdr = (void *)images->os.load; |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 97 | |
| 98 | /* */ |
Kumar Gala | 93467bc | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 99 | kernel = (void (*)(struct linux_romvec *, void *))images->ep; |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 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 | |
Simon Glass | e9c6b3d | 2013-05-08 08:06:06 +0000 | [diff] [blame] | 122 | ret = image_setup_linux(images); |
| 123 | if (ret) { |
| 124 | puts("### Failed to relocate RAM disk\n"); |
| 125 | goto error; |
| 126 | } |
| 127 | |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 128 | /* Calc length of RAM disk, if zero no ramdisk available */ |
Kumar Gala | fffb143 | 2008-08-15 08:24:37 -0500 | [diff] [blame] | 129 | rd_len = images->rd_end - images->rd_start; |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 130 | |
| 131 | if (rd_len) { |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 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 = |
Simon Glass | e9c6b3d | 2013-05-08 08:06:06 +0000 | [diff] [blame] | 138 | images->initrd_start - CONFIG_SYS_RAM_BASE; |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 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 | |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 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 | */ |
Daniel Hellstrom | ecf05d4 | 2008-11-10 12:46:20 +0000 | [diff] [blame] | 167 | kernel(kernel_arg_promvec, (void *)images->ep); |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 168 | |
| 169 | /* It will never come to this... */ |
| 170 | while (1) ; |
| 171 | |
| 172 | error: |
Kumar Gala | 48626aa | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 173 | return 1; |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 174 | } |