2 * (C) Copyright 2000-2009
3 * Vipin Kumar, ST Microelectronics, vipin.kumar@st.com
5 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
7 * See file CREDITS for list of people who contributed to this
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.
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.
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,
28 #include <linux/compiler.h>
30 #include <asm/arch/spr_defs.h>
31 #include <linux/mtd/st_smi.h>
33 static const char kernel_name[] = "Linux";
34 static const char loader_name[] = "U-Boot";
36 int image_check_header(image_header_t *hdr, const char *name)
38 if (image_check_magic(hdr) &&
39 (!strncmp(image_get_name(hdr), name, strlen(name))) &&
40 image_check_hcrc(hdr)) {
46 int image_check_data(image_header_t *hdr)
48 if (image_check_dcrc(hdr))
55 * SNOR (Serial NOR flash) related functions
59 struct smi_regs *const smicntl =
60 (struct smi_regs * const)CONFIG_SYS_SMI_BASE;
62 /* Setting the fast mode values. SMI working at 166/4 = 41.5 MHz */
63 writel(HOLD1 | FAST_MODE | BANK_EN | DSEL_TIME | PRESCAL4,
67 static int snor_image_load(u8 *load_addr, void (**image_p)(void),
68 const char *image_name)
70 image_header_t *header;
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
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));
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);
97 static void boot_image(void (*image)(void))
99 void (*funcp)(void) __noreturn = (void *)image;
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
115 #ifdef CONFIG_SPEAR_USBTTY
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.
126 if (SNOR_BOOT_SUPPORTED && snor_boot_selected()) {
127 /* SNOR-SMI initialization */
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 */
137 /* Jump to boot image */
138 serial_puts("Jumping to U-Boot\n");
144 if (NAND_BOOT_SUPPORTED && nand_boot_selected()) {
146 /* Not ported from XLoader to SPL yet */
150 if (PNOR_BOOT_SUPPORTED && pnor_boot_selected()) {
152 /* Not ported from XLoader to SPL yet */
156 if (MMC_BOOT_SUPPORTED && mmc_boot_selected()) {
158 /* Not ported from XLoader to SPL yet */
162 if (SPI_BOOT_SUPPORTED && spi_boot_selected()) {
164 /* Not supported for any platform as of now */
168 if (I2C_BOOT_SUPPORTED && i2c_boot_selected()) {
170 /* Not supported for any platform as of now */
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
180 if (USB_BOOT_SUPPORTED && usb_boot_selected()) {
185 if (TFTP_BOOT_SUPPORTED && tftp_boot_selected()) {
190 if (UART_BOOT_SUPPORTED && uart_boot_selected()) {
195 /* Ideally, the control should not reach here. */