2 * (C) Copyright 2000-2009
3 * Vipin Kumar, ST Microelectronics, vipin.kumar@st.com
5 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
7 * SPDX-License-Identifier: GPL-2.0+
12 #include <linux/compiler.h>
14 #include <asm/arch/spr_defs.h>
15 #include <linux/mtd/st_smi.h>
17 static const char kernel_name[] = "Linux";
18 static const char loader_name[] = "U-Boot";
20 int image_check_header(image_header_t *hdr, const char *name)
22 if (image_check_magic(hdr) &&
23 (!strncmp(image_get_name(hdr), name, strlen(name))) &&
24 image_check_hcrc(hdr)) {
30 int image_check_data(image_header_t *hdr)
32 if (image_check_dcrc(hdr))
39 * SNOR (Serial NOR flash) related functions
43 struct smi_regs *const smicntl =
44 (struct smi_regs * const)CONFIG_SYS_SMI_BASE;
46 /* Setting the fast mode values. SMI working at 166/4 = 41.5 MHz */
47 writel(HOLD1 | FAST_MODE | BANK_EN | DSEL_TIME | PRESCAL4,
51 static int snor_image_load(u8 *load_addr, void (**image_p)(void),
52 const char *image_name)
54 image_header_t *header;
57 * Since calculating the crc in the SNOR flash does not
58 * work, we copy the image to the destination address
59 * minus the header size. And point the header to this
60 * new destination. This will not work for address 0
63 header = (image_header_t *)load_addr;
64 memcpy((ulong *)(image_get_load(header) - sizeof(image_header_t)),
65 (const ulong *)load_addr,
66 image_get_data_size(header) + sizeof(image_header_t));
67 header = (image_header_t *)(image_get_load(header) -
68 sizeof(image_header_t));
70 if (image_check_header(header, image_name)) {
71 if (image_check_data(header)) {
72 /* Jump to boot image */
73 *image_p = (void *)image_get_load(header);
81 static void boot_image(void (*image)(void))
83 void (*funcp)(void) __noreturn = (void *)image;
91 * All supported booting types of all supported SoCs are listed here.
92 * Generic readback APIs are provided for each supported booting type
93 * eg. nand_read_skip_bad
99 #ifdef CONFIG_SPEAR_USBTTY
105 * All the supported booting devices are listed here. Each of
106 * the booting type supported by the platform would define the
107 * macro xxx_BOOT_SUPPORTED to true.
110 if (SNOR_BOOT_SUPPORTED && snor_boot_selected()) {
111 /* SNOR-SMI initialization */
114 serial_puts("Booting via SNOR\n");
115 /* Serial NOR booting */
116 if (1 == snor_image_load((u8 *)CONFIG_SYS_UBOOT_BASE,
117 &image, loader_name)) {
118 /* Platform related late initialasations */
121 /* Jump to boot image */
122 serial_puts("Jumping to U-Boot\n");
128 if (NAND_BOOT_SUPPORTED && nand_boot_selected()) {
130 /* Not ported from XLoader to SPL yet */
134 if (PNOR_BOOT_SUPPORTED && pnor_boot_selected()) {
136 /* Not ported from XLoader to SPL yet */
140 if (MMC_BOOT_SUPPORTED && mmc_boot_selected()) {
142 /* Not ported from XLoader to SPL yet */
146 if (SPI_BOOT_SUPPORTED && spi_boot_selected()) {
148 /* Not supported for any platform as of now */
152 if (I2C_BOOT_SUPPORTED && i2c_boot_selected()) {
154 /* Not supported for any platform as of now */
159 * All booting types without memory are listed as below
160 * Control has to be returned to BootROM in case of all
161 * the following booting scenarios
164 if (USB_BOOT_SUPPORTED && usb_boot_selected()) {
169 if (TFTP_BOOT_SUPPORTED && tftp_boot_selected()) {
174 if (UART_BOOT_SUPPORTED && uart_boot_selected()) {
179 /* Ideally, the control should not reach here. */