]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/mtd/spi/fsl_espi_spl.c
driver/mtd/spi:Read 8KB data chunk during u-boot load in SPL
[karo-tx-uboot.git] / drivers / mtd / spi / fsl_espi_spl.c
1 /*
2  * Copyright 2013 Freescale Semiconductor, Inc.
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
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;
23         u32 offset, code_len, copy_len = 0;
24 #ifndef CONFIG_FSL_CORENET
25         unsigned char *buf = NULL;
26 #endif
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
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
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;
59 #endif
60         /* copy code to DDR */
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
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 }