Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2009 |
| 3 | * Vipin Kumar, ST Microelectronics, vipin.kumar@st.com |
| 4 | * |
| 5 | * Copyright (C) 2012 Stefan Roese <sr@denx.de> |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <image.h> |
| 28 | #include <linux/compiler.h> |
| 29 | #include <asm/io.h> |
| 30 | #include <asm/arch/spr_defs.h> |
| 31 | #include <linux/mtd/st_smi.h> |
| 32 | |
| 33 | static const char kernel_name[] = "Linux"; |
| 34 | static const char loader_name[] = "U-Boot"; |
| 35 | |
| 36 | int image_check_header(image_header_t *hdr, const char *name) |
| 37 | { |
| 38 | if (image_check_magic(hdr) && |
| 39 | (!strncmp(image_get_name(hdr), name, strlen(name))) && |
| 40 | image_check_hcrc(hdr)) { |
| 41 | return 1; |
| 42 | } |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | int image_check_data(image_header_t *hdr) |
| 47 | { |
| 48 | if (image_check_dcrc(hdr)) |
| 49 | return 1; |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * SNOR (Serial NOR flash) related functions |
| 56 | */ |
| 57 | void snor_init(void) |
| 58 | { |
| 59 | struct smi_regs *const smicntl = |
| 60 | (struct smi_regs * const)CONFIG_SYS_SMI_BASE; |
| 61 | |
| 62 | /* Setting the fast mode values. SMI working at 166/4 = 41.5 MHz */ |
| 63 | writel(HOLD1 | FAST_MODE | BANK_EN | DSEL_TIME | PRESCAL4, |
| 64 | &smicntl->smi_cr1); |
| 65 | } |
| 66 | |
| 67 | static int snor_image_load(u8 *load_addr, void (**image_p)(void), |
| 68 | const char *image_name) |
| 69 | { |
| 70 | image_header_t *header; |
| 71 | |
| 72 | /* |
| 73 | * Since calculating the crc in the SNOR flash does not |
| 74 | * work, we copy the image to the destination address |
| 75 | * minus the header size. And point the header to this |
| 76 | * new destination. This will not work for address 0 |
| 77 | * of course. |
| 78 | */ |
| 79 | header = (image_header_t *)load_addr; |
| 80 | memcpy((ulong *)(image_get_load(header) - sizeof(image_header_t)), |
| 81 | (const ulong *)load_addr, |
| 82 | image_get_data_size(header) + sizeof(image_header_t)); |
| 83 | header = (image_header_t *)(image_get_load(header) - |
| 84 | sizeof(image_header_t)); |
| 85 | |
| 86 | if (image_check_header(header, image_name)) { |
| 87 | if (image_check_data(header)) { |
| 88 | /* Jump to boot image */ |
| 89 | *image_p = (void *)image_get_load(header); |
| 90 | return 1; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static void boot_image(void (*image)(void)) |
| 98 | { |
| 99 | void (*funcp)(void) __noreturn = (void *)image; |
| 100 | |
| 101 | (*funcp)(); |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * spl_boot: |
| 106 | * |
| 107 | * All supported booting types of all supported SoCs are listed here. |
| 108 | * Generic readback APIs are provided for each supported booting type |
| 109 | * eg. nand_read_skip_bad |
| 110 | */ |
| 111 | u32 spl_boot(void) |
| 112 | { |
| 113 | void (*image)(void); |
| 114 | |
| 115 | #ifdef CONFIG_SPEAR_USBTTY |
| 116 | plat_late_init(); |
| 117 | return 1; |
| 118 | #endif |
| 119 | |
| 120 | /* |
| 121 | * All the supported booting devices are listed here. Each of |
| 122 | * the booting type supported by the platform would define the |
| 123 | * macro xxx_BOOT_SUPPORTED to TRUE. |
| 124 | */ |
| 125 | |
| 126 | if (SNOR_BOOT_SUPPORTED && snor_boot_selected()) { |
| 127 | /* SNOR-SMI initialization */ |
| 128 | snor_init(); |
| 129 | |
| 130 | serial_puts("Booting via SNOR\n"); |
| 131 | /* Serial NOR booting */ |
| 132 | if (1 == snor_image_load((u8 *)CONFIG_SYS_UBOOT_BASE, |
| 133 | &image, loader_name)) { |
| 134 | /* Platform related late initialasations */ |
| 135 | plat_late_init(); |
| 136 | |
| 137 | /* Jump to boot image */ |
| 138 | serial_puts("Jumping to U-Boot\n"); |
| 139 | boot_image(image); |
| 140 | return 1; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if (NAND_BOOT_SUPPORTED && nand_boot_selected()) { |
| 145 | /* NAND booting */ |
| 146 | /* Not ported from XLoader to SPL yet */ |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | if (PNOR_BOOT_SUPPORTED && pnor_boot_selected()) { |
| 151 | /* PNOR booting */ |
| 152 | /* Not ported from XLoader to SPL yet */ |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | if (MMC_BOOT_SUPPORTED && mmc_boot_selected()) { |
| 157 | /* MMC booting */ |
| 158 | /* Not ported from XLoader to SPL yet */ |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | if (SPI_BOOT_SUPPORTED && spi_boot_selected()) { |
| 163 | /* SPI booting */ |
| 164 | /* Not supported for any platform as of now */ |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | if (I2C_BOOT_SUPPORTED && i2c_boot_selected()) { |
| 169 | /* I2C booting */ |
| 170 | /* Not supported for any platform as of now */ |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * All booting types without memory are listed as below |
| 176 | * Control has to be returned to BootROM in case of all |
| 177 | * the following booting scenarios |
| 178 | */ |
| 179 | |
| 180 | if (USB_BOOT_SUPPORTED && usb_boot_selected()) { |
| 181 | plat_late_init(); |
| 182 | return 1; |
| 183 | } |
| 184 | |
| 185 | if (TFTP_BOOT_SUPPORTED && tftp_boot_selected()) { |
| 186 | plat_late_init(); |
| 187 | return 1; |
| 188 | } |
| 189 | |
| 190 | if (UART_BOOT_SUPPORTED && uart_boot_selected()) { |
| 191 | plat_late_init(); |
| 192 | return 1; |
| 193 | } |
| 194 | |
| 195 | /* Ideally, the control should not reach here. */ |
| 196 | hang(); |
| 197 | } |