Ying Zhang | ded0f0f | 2013-08-16 15:16:13 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Freescale Semiconductor, Inc. |
| 3 | * |
York Sun | b27fef5 | 2013-08-20 10:15:37 -0700 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Ying Zhang | ded0f0f | 2013-08-16 15:16:13 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <spi_flash.h> |
| 9 | #include <malloc.h> |
| 10 | |
| 11 | #define ESPI_BOOT_IMAGE_SIZE 0x48 |
| 12 | #define ESPI_BOOT_IMAGE_ADDR 0x50 |
| 13 | #define CONFIG_CFG_DATA_SECTOR 0 |
| 14 | |
| 15 | /* |
| 16 | * The main entry for SPI booting. It's necessary that SDRAM is already |
| 17 | * configured and available since this code loads the main U-Boot image |
| 18 | * from SPI into SDRAM and starts it from there. |
| 19 | */ |
| 20 | void spi_boot(void) |
| 21 | { |
| 22 | void (*uboot)(void) __noreturn; |
Prabhakar Kushwaha | 77aa132 | 2014-04-08 19:13:11 +0530 | [diff] [blame^] | 23 | u32 offset, code_len, copy_len = 0; |
| 24 | #ifndef CONFIG_FSL_CORENET |
Ying Zhang | ded0f0f | 2013-08-16 15:16:13 +0800 | [diff] [blame] | 25 | unsigned char *buf = NULL; |
Prabhakar Kushwaha | 77aa132 | 2014-04-08 19:13:11 +0530 | [diff] [blame^] | 26 | #endif |
Ying Zhang | ded0f0f | 2013-08-16 15:16:13 +0800 | [diff] [blame] | 27 | struct spi_flash *flash; |
| 28 | |
| 29 | flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, |
| 30 | CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); |
| 31 | if (flash == NULL) { |
| 32 | puts("\nspi_flash_probe failed"); |
| 33 | hang(); |
| 34 | } |
| 35 | |
Priyanka Jain | fed1d31 | 2013-11-28 10:08:12 +0530 | [diff] [blame] | 36 | #ifdef CONFIG_FSL_CORENET |
| 37 | offset = CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS; |
| 38 | code_len = CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE; |
| 39 | #else |
Ying Zhang | ded0f0f | 2013-08-16 15:16:13 +0800 | [diff] [blame] | 40 | /* |
| 41 | * Load U-Boot image from SPI flash into RAM |
| 42 | */ |
| 43 | buf = malloc(flash->page_size); |
| 44 | if (buf == NULL) { |
| 45 | puts("\nmalloc failed"); |
| 46 | hang(); |
| 47 | } |
| 48 | memset(buf, 0, flash->page_size); |
| 49 | |
| 50 | spi_flash_read(flash, CONFIG_CFG_DATA_SECTOR, |
| 51 | flash->page_size, (void *)buf); |
| 52 | offset = *(u32 *)(buf + ESPI_BOOT_IMAGE_ADDR); |
| 53 | /* Skip spl code */ |
| 54 | offset += CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS; |
| 55 | /* Get the code size from offset 0x48 */ |
| 56 | code_len = *(u32 *)(buf + ESPI_BOOT_IMAGE_SIZE); |
| 57 | /* Skip spl code */ |
| 58 | code_len = code_len - CONFIG_SPL_MAX_SIZE; |
Priyanka Jain | fed1d31 | 2013-11-28 10:08:12 +0530 | [diff] [blame] | 59 | #endif |
Ying Zhang | ded0f0f | 2013-08-16 15:16:13 +0800 | [diff] [blame] | 60 | /* copy code to DDR */ |
Prabhakar Kushwaha | 77aa132 | 2014-04-08 19:13:11 +0530 | [diff] [blame^] | 61 | printf("Loading second stage boot loader "); |
| 62 | while (copy_len <= code_len) { |
| 63 | spi_flash_read(flash, offset + copy_len, 0x2000, |
| 64 | (void *)(CONFIG_SYS_SPI_FLASH_U_BOOT_DST |
| 65 | + copy_len)); |
| 66 | copy_len = copy_len + 0x2000; |
| 67 | putc('.'); |
| 68 | } |
| 69 | |
Ying Zhang | ded0f0f | 2013-08-16 15:16:13 +0800 | [diff] [blame] | 70 | /* |
| 71 | * Jump to U-Boot image |
| 72 | */ |
| 73 | flush_cache(CONFIG_SYS_SPI_FLASH_U_BOOT_DST, code_len); |
| 74 | uboot = (void *)CONFIG_SYS_SPI_FLASH_U_BOOT_START; |
| 75 | (*uboot)(); |
| 76 | } |