]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/spl/spl_nand.c
merged tx6dl-devel into denx master branch
[karo-tx-uboot.git] / common / spl / spl_nand.c
1 /*
2  * Copyright (C) 2011
3  * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7 #include <common.h>
8 #include <config.h>
9 #include <spl.h>
10 #include <asm/io.h>
11 #include <nand.h>
12
13 int spl_nand_load_image(void)
14 {
15         int ret;
16         struct image_header *header;
17         int *src __attribute__((unused));
18         int *dst __attribute__((unused));
19
20         debug("spl: nand - using hw ecc\n");
21         nand_init();
22
23         /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
24         header = (struct image_header *)CONFIG_SYS_TEXT_BASE;
25 #ifdef CONFIG_SPL_OS_BOOT
26         if (!spl_start_uboot()) {
27                 /*
28                  * load parameter image
29                  * load to temp position since nand_spl_load_image reads
30                  * a whole block which is typically larger than
31                  * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
32                  * following sections like BSS
33                  */
34                 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
35                         CONFIG_CMD_SPL_WRITE_SIZE,
36                         (void *)CONFIG_SYS_TEXT_BASE);
37                 /* copy to destintion */
38                 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
39                                 src = (int *)CONFIG_SYS_TEXT_BASE;
40                                 src < (int *)(CONFIG_SYS_TEXT_BASE +
41                                 CONFIG_CMD_SPL_WRITE_SIZE);
42                                 src++, dst++) {
43                         writel(readl(src), dst);
44                 }
45
46                 /* load linux */
47                 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
48                         CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
49                 spl_parse_image_header(header);
50                 if (header->ih_os == IH_OS_LINUX) {
51                         /* happy - was a linux */
52                         nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
53                                 spl_image.size, (void *)spl_image.load_addr);
54                         nand_deselect();
55                         return 0;
56                 } else {
57                         printf("The Expected Linux image was not"
58                                 "found. Please check your NAND"
59                                 "configuration.\n");
60                         printf("Trying to start u-boot now...\n");
61                 }
62         }
63 #endif
64 #ifdef CONFIG_NAND_ENV_DST
65         nand_spl_load_image(CONFIG_ENV_OFFSET,
66                 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
67         spl_parse_image_header(header);
68         nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
69                 (void *)spl_image.load_addr);
70 #ifdef CONFIG_ENV_OFFSET_REDUND
71         nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
72                 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
73         spl_parse_image_header(header);
74         nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
75                 (void *)spl_image.load_addr);
76 #endif
77 #endif
78         /* Load u-boot */
79         ret = nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
80                                 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
81         if (ret == 0) {
82                 spl_parse_image_header(header);
83                 ret = nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
84                                         spl_image.size, (void *)spl_image.load_addr);
85         }
86         nand_deselect();
87         return ret;
88 }