blob: b915469b404adb44adecabaa5ae21b6effb8d238 [file] [log] [blame]
Ying Zhangfdf85292013-08-16 15:16:13 +08001/*
2 * Copyright 2013 Freescale Semiconductor, Inc.
3 *
York Sunbf902562013-08-20 10:15:37 -07004 * SPDX-License-Identifier: GPL-2.0+
Ying Zhangfdf85292013-08-16 15:16:13 +08005 */
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
Prabhakar Kushwaha1eaa7422014-04-08 19:13:22 +053015void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
16{
17 struct spi_flash *flash;
18
19 flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
20 CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
21 if (flash == NULL) {
22 puts("\nspi_flash_probe failed");
23 hang();
24 }
25
26 spi_flash_read(flash, offs, size, vdst);
27}
28
Ying Zhangfdf85292013-08-16 15:16:13 +080029/*
30 * The main entry for SPI booting. It's necessary that SDRAM is already
31 * configured and available since this code loads the main U-Boot image
32 * from SPI into SDRAM and starts it from there.
33 */
34void spi_boot(void)
35{
36 void (*uboot)(void) __noreturn;
Prabhakar Kushwahae278ddc2014-04-08 19:13:11 +053037 u32 offset, code_len, copy_len = 0;
38#ifndef CONFIG_FSL_CORENET
Ying Zhangfdf85292013-08-16 15:16:13 +080039 unsigned char *buf = NULL;
Prabhakar Kushwahae278ddc2014-04-08 19:13:11 +053040#endif
Ying Zhangfdf85292013-08-16 15:16:13 +080041 struct spi_flash *flash;
42
43 flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
44 CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
45 if (flash == NULL) {
46 puts("\nspi_flash_probe failed");
47 hang();
48 }
49
Priyanka Jain7aa6c452013-11-28 10:08:12 +053050#ifdef CONFIG_FSL_CORENET
51 offset = CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
52 code_len = CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE;
53#else
Ying Zhangfdf85292013-08-16 15:16:13 +080054 /*
55 * Load U-Boot image from SPI flash into RAM
56 */
57 buf = malloc(flash->page_size);
58 if (buf == NULL) {
59 puts("\nmalloc failed");
60 hang();
61 }
62 memset(buf, 0, flash->page_size);
63
64 spi_flash_read(flash, CONFIG_CFG_DATA_SECTOR,
65 flash->page_size, (void *)buf);
66 offset = *(u32 *)(buf + ESPI_BOOT_IMAGE_ADDR);
67 /* Skip spl code */
68 offset += CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
69 /* Get the code size from offset 0x48 */
70 code_len = *(u32 *)(buf + ESPI_BOOT_IMAGE_SIZE);
71 /* Skip spl code */
72 code_len = code_len - CONFIG_SPL_MAX_SIZE;
Priyanka Jain7aa6c452013-11-28 10:08:12 +053073#endif
Ying Zhangfdf85292013-08-16 15:16:13 +080074 /* copy code to DDR */
Prabhakar Kushwahae278ddc2014-04-08 19:13:11 +053075 printf("Loading second stage boot loader ");
76 while (copy_len <= code_len) {
77 spi_flash_read(flash, offset + copy_len, 0x2000,
78 (void *)(CONFIG_SYS_SPI_FLASH_U_BOOT_DST
79 + copy_len));
80 copy_len = copy_len + 0x2000;
81 putc('.');
82 }
83
Ying Zhangfdf85292013-08-16 15:16:13 +080084 /*
85 * Jump to U-Boot image
86 */
87 flush_cache(CONFIG_SYS_SPI_FLASH_U_BOOT_DST, code_len);
88 uboot = (void *)CONFIG_SYS_SPI_FLASH_U_BOOT_START;
89 (*uboot)();
90}