147f7bcaeSTom Rini /* 247f7bcaeSTom Rini * (C) Copyright 2010 347f7bcaeSTom Rini * Texas Instruments, <www.ti.com> 447f7bcaeSTom Rini * 547f7bcaeSTom Rini * Aneesh V <aneesh@ti.com> 647f7bcaeSTom Rini * 747f7bcaeSTom Rini * See file CREDITS for list of people who contributed to this 847f7bcaeSTom Rini * project. 947f7bcaeSTom Rini * 1047f7bcaeSTom Rini * This program is free software; you can redistribute it and/or 1147f7bcaeSTom Rini * modify it under the terms of the GNU General Public License as 1247f7bcaeSTom Rini * published by the Free Software Foundation; either version 2 of 1347f7bcaeSTom Rini * the License, or (at your option) any later version. 1447f7bcaeSTom Rini * 1547f7bcaeSTom Rini * This program is distributed in the hope that it will be useful, 1647f7bcaeSTom Rini * but WITHOUT ANY WARRANTY; without even the implied warranty of 1747f7bcaeSTom Rini * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1847f7bcaeSTom Rini * GNU General Public License for more details. 1947f7bcaeSTom Rini * 2047f7bcaeSTom Rini * You should have received a copy of the GNU General Public License 2147f7bcaeSTom Rini * along with this program; if not, write to the Free Software 2247f7bcaeSTom Rini * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 2347f7bcaeSTom Rini * MA 02111-1307 USA 2447f7bcaeSTom Rini */ 2547f7bcaeSTom Rini #include <common.h> 2647f7bcaeSTom Rini #include <spl.h> 2747f7bcaeSTom Rini #include <asm/u-boot.h> 2847f7bcaeSTom Rini #include <nand.h> 2947f7bcaeSTom Rini #include <fat.h> 3047f7bcaeSTom Rini #include <version.h> 3147f7bcaeSTom Rini #include <i2c.h> 3247f7bcaeSTom Rini #include <image.h> 3347f7bcaeSTom Rini #include <malloc.h> 3447f7bcaeSTom Rini #include <linux/compiler.h> 3547f7bcaeSTom Rini 3647f7bcaeSTom Rini DECLARE_GLOBAL_DATA_PTR; 3747f7bcaeSTom Rini 3847f7bcaeSTom Rini u32 *boot_params_ptr = NULL; 3947f7bcaeSTom Rini struct spl_image_info spl_image; 4047f7bcaeSTom Rini 41*6507f133STom Rini /* Define board data structure */ 4247f7bcaeSTom Rini static bd_t bdata __attribute__ ((section(".data"))); 4347f7bcaeSTom Rini 4447f7bcaeSTom Rini inline void hang(void) 4547f7bcaeSTom Rini { 4647f7bcaeSTom Rini puts("### ERROR ### Please RESET the board ###\n"); 4747f7bcaeSTom Rini for (;;) 4847f7bcaeSTom Rini ; 4947f7bcaeSTom Rini } 5047f7bcaeSTom Rini 5147f7bcaeSTom Rini /* 5247f7bcaeSTom Rini * Default function to determine if u-boot or the OS should 5347f7bcaeSTom Rini * be started. This implementation always returns 1. 5447f7bcaeSTom Rini * 5547f7bcaeSTom Rini * Please implement your own board specific funcion to do this. 5647f7bcaeSTom Rini * 5747f7bcaeSTom Rini * RETURN 5847f7bcaeSTom Rini * 0 to not start u-boot 5947f7bcaeSTom Rini * positive if u-boot should start 6047f7bcaeSTom Rini */ 6147f7bcaeSTom Rini #ifdef CONFIG_SPL_OS_BOOT 6247f7bcaeSTom Rini __weak int spl_start_uboot(void) 6347f7bcaeSTom Rini { 6447f7bcaeSTom Rini puts("SPL: Please implement spl_start_uboot() for your board\n"); 6547f7bcaeSTom Rini puts("SPL: Direct Linux boot not active!\n"); 6647f7bcaeSTom Rini return 1; 6747f7bcaeSTom Rini } 6847f7bcaeSTom Rini #endif 6947f7bcaeSTom Rini 7047f7bcaeSTom Rini void spl_parse_image_header(const struct image_header *header) 7147f7bcaeSTom Rini { 7247f7bcaeSTom Rini u32 header_size = sizeof(struct image_header); 7347f7bcaeSTom Rini 7447f7bcaeSTom Rini if (__be32_to_cpu(header->ih_magic) == IH_MAGIC) { 7547f7bcaeSTom Rini spl_image.size = __be32_to_cpu(header->ih_size) + header_size; 7647f7bcaeSTom Rini spl_image.entry_point = __be32_to_cpu(header->ih_load); 7747f7bcaeSTom Rini /* Load including the header */ 7847f7bcaeSTom Rini spl_image.load_addr = spl_image.entry_point - header_size; 7947f7bcaeSTom Rini spl_image.os = header->ih_os; 8047f7bcaeSTom Rini spl_image.name = (const char *)&header->ih_name; 8147f7bcaeSTom Rini debug("spl: payload image: %s load addr: 0x%x size: %d\n", 8247f7bcaeSTom Rini spl_image.name, spl_image.load_addr, spl_image.size); 8347f7bcaeSTom Rini } else { 8447f7bcaeSTom Rini /* Signature not found - assume u-boot.bin */ 8547f7bcaeSTom Rini puts("mkimage signature not found, assuming u-boot.bin ..\n"); 8647f7bcaeSTom Rini debug("mkimage signature not found - ih_magic = %x\n", 8747f7bcaeSTom Rini header->ih_magic); 8847f7bcaeSTom Rini /* Let's assume U-Boot will not be more than 200 KB */ 8947f7bcaeSTom Rini spl_image.size = 200 * 1024; 9047f7bcaeSTom Rini spl_image.entry_point = CONFIG_SYS_TEXT_BASE; 9147f7bcaeSTom Rini spl_image.load_addr = CONFIG_SYS_TEXT_BASE; 9247f7bcaeSTom Rini spl_image.os = IH_OS_U_BOOT; 9347f7bcaeSTom Rini spl_image.name = "U-Boot"; 9447f7bcaeSTom Rini } 9547f7bcaeSTom Rini } 9647f7bcaeSTom Rini 9747f7bcaeSTom Rini static void __noreturn jump_to_image_no_args(void) 9847f7bcaeSTom Rini { 9947f7bcaeSTom Rini typedef void __noreturn (*image_entry_noargs_t)(u32 *); 10047f7bcaeSTom Rini image_entry_noargs_t image_entry = 10147f7bcaeSTom Rini (image_entry_noargs_t) spl_image.entry_point; 10247f7bcaeSTom Rini 10347f7bcaeSTom Rini debug("image entry point: 0x%X\n", spl_image.entry_point); 10447f7bcaeSTom Rini /* Pass the saved boot_params from rom code */ 10547f7bcaeSTom Rini #if defined(CONFIG_VIRTIO) || defined(CONFIG_ZEBU) 10647f7bcaeSTom Rini image_entry = (image_entry_noargs_t)0x80100000; 10747f7bcaeSTom Rini #endif 10847f7bcaeSTom Rini u32 boot_params_ptr_addr = (u32)&boot_params_ptr; 10947f7bcaeSTom Rini image_entry((u32 *)boot_params_ptr_addr); 11047f7bcaeSTom Rini } 11147f7bcaeSTom Rini 112*6507f133STom Rini void board_init_r(gd_t *dummy1, ulong dummy2) 11347f7bcaeSTom Rini { 11447f7bcaeSTom Rini u32 boot_device; 11547f7bcaeSTom Rini debug(">>spl:board_init_r()\n"); 11647f7bcaeSTom Rini 11747f7bcaeSTom Rini #ifdef CONFIG_SYS_SPL_MALLOC_START 11847f7bcaeSTom Rini mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START, 11947f7bcaeSTom Rini CONFIG_SYS_SPL_MALLOC_SIZE); 12047f7bcaeSTom Rini #endif 12147f7bcaeSTom Rini 12247f7bcaeSTom Rini #ifdef CONFIG_SPL_BOARD_INIT 12347f7bcaeSTom Rini spl_board_init(); 12447f7bcaeSTom Rini #endif 12547f7bcaeSTom Rini 12647f7bcaeSTom Rini boot_device = spl_boot_device(); 12747f7bcaeSTom Rini debug("boot device - %d\n", boot_device); 12847f7bcaeSTom Rini switch (boot_device) { 12947f7bcaeSTom Rini #ifdef CONFIG_SPL_MMC_SUPPORT 13047f7bcaeSTom Rini case BOOT_DEVICE_MMC1: 13147f7bcaeSTom Rini case BOOT_DEVICE_MMC2: 13247f7bcaeSTom Rini case BOOT_DEVICE_MMC2_2: 13347f7bcaeSTom Rini spl_mmc_load_image(); 13447f7bcaeSTom Rini break; 13547f7bcaeSTom Rini #endif 13647f7bcaeSTom Rini #ifdef CONFIG_SPL_NAND_SUPPORT 13747f7bcaeSTom Rini case BOOT_DEVICE_NAND: 13847f7bcaeSTom Rini spl_nand_load_image(); 13947f7bcaeSTom Rini break; 14047f7bcaeSTom Rini #endif 14147f7bcaeSTom Rini #ifdef CONFIG_SPL_YMODEM_SUPPORT 14247f7bcaeSTom Rini case BOOT_DEVICE_UART: 14347f7bcaeSTom Rini spl_ymodem_load_image(); 14447f7bcaeSTom Rini break; 14547f7bcaeSTom Rini #endif 14647f7bcaeSTom Rini #ifdef CONFIG_SPL_SPI_SUPPORT 14747f7bcaeSTom Rini case BOOT_DEVICE_SPI: 14847f7bcaeSTom Rini spi_boot(); 14947f7bcaeSTom Rini break; 15047f7bcaeSTom Rini #endif 15147f7bcaeSTom Rini default: 15247f7bcaeSTom Rini puts("SPL: Un-supported Boot Device\n"); 15347f7bcaeSTom Rini debug("Found: %d\n", boot_device); 15447f7bcaeSTom Rini hang(); 15547f7bcaeSTom Rini break; 15647f7bcaeSTom Rini } 15747f7bcaeSTom Rini 15847f7bcaeSTom Rini switch (spl_image.os) { 15947f7bcaeSTom Rini case IH_OS_U_BOOT: 16047f7bcaeSTom Rini debug("Jumping to U-Boot\n"); 16147f7bcaeSTom Rini jump_to_image_no_args(); 16247f7bcaeSTom Rini break; 16347f7bcaeSTom Rini #ifdef CONFIG_SPL_OS_BOOT 16447f7bcaeSTom Rini case IH_OS_LINUX: 16547f7bcaeSTom Rini debug("Jumping to Linux\n"); 16647f7bcaeSTom Rini spl_board_prepare_for_linux(); 16747f7bcaeSTom Rini jump_to_image_linux((void *)CONFIG_SYS_SPL_ARGS_ADDR); 16847f7bcaeSTom Rini break; 16947f7bcaeSTom Rini #endif 17047f7bcaeSTom Rini default: 17147f7bcaeSTom Rini puts("Unsupported OS image.. Jumping nevertheless..\n"); 17247f7bcaeSTom Rini jump_to_image_no_args(); 17347f7bcaeSTom Rini } 17447f7bcaeSTom Rini } 17547f7bcaeSTom Rini 176*6507f133STom Rini /* 177*6507f133STom Rini * This requires UART clocks to be enabled. In order for this to work the 178*6507f133STom Rini * caller must ensure that the gd pointer is valid. 179*6507f133STom Rini */ 18047f7bcaeSTom Rini void preloader_console_init(void) 18147f7bcaeSTom Rini { 18247f7bcaeSTom Rini gd->bd = &bdata; 18347f7bcaeSTom Rini gd->flags |= GD_FLG_RELOC; 18447f7bcaeSTom Rini gd->baudrate = CONFIG_BAUDRATE; 18547f7bcaeSTom Rini 18647f7bcaeSTom Rini serial_init(); /* serial communications setup */ 18747f7bcaeSTom Rini 18847f7bcaeSTom Rini gd->have_console = 1; 18947f7bcaeSTom Rini 19047f7bcaeSTom Rini puts("\nU-Boot SPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \ 19147f7bcaeSTom Rini U_BOOT_TIME ")\n"); 19247f7bcaeSTom Rini #ifdef CONFIG_SPL_DISPLAY_PRINT 19347f7bcaeSTom Rini spl_display_print(); 19447f7bcaeSTom Rini #endif 19547f7bcaeSTom Rini } 196