]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/spl/spl_nand.c
TX6 Release 2013-04-22
[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  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23 #include <common.h>
24 #include <config.h>
25 #include <spl.h>
26 #include <asm/io.h>
27 #include <nand.h>
28
29 int spl_nand_load_image(void)
30 {
31         int ret;
32         struct image_header *header;
33         int *src __attribute__((unused));
34         int *dst __attribute__((unused));
35
36         debug("spl: nand - using hw ecc\n");
37         nand_init();
38
39         /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
40         header = (struct image_header *)CONFIG_SYS_TEXT_BASE;
41 #ifdef CONFIG_SPL_OS_BOOT
42         if (!spl_start_uboot()) {
43                 /*
44                  * load parameter image
45                  * load to temp position since nand_spl_load_image reads
46                  * a whole block which is typically larger than
47                  * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
48                  * following sections like BSS
49                  */
50                 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
51                         CONFIG_CMD_SPL_WRITE_SIZE,
52                         (void *)CONFIG_SYS_TEXT_BASE);
53                 /* copy to destintion */
54                 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
55                                 src = (int *)CONFIG_SYS_TEXT_BASE;
56                                 src < (int *)(CONFIG_SYS_TEXT_BASE +
57                                 CONFIG_CMD_SPL_WRITE_SIZE);
58                                 src++, dst++) {
59                         writel(readl(src), dst);
60                 }
61
62                 /* load linux */
63                 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
64                         CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
65                 spl_parse_image_header(header);
66                 if (header->ih_os == IH_OS_LINUX) {
67                         /* happy - was a linux */
68                         nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
69                                 spl_image.size, (void *)spl_image.load_addr);
70                         nand_deselect();
71                         return 0;
72                 } else {
73                         printf("The Expected Linux image was not"
74                                 "found. Please check your NAND"
75                                 "configuration.\n");
76                         printf("Trying to start u-boot now...\n");
77                 }
78         }
79 #endif
80 #ifdef CONFIG_NAND_ENV_DST
81         nand_spl_load_image(CONFIG_ENV_OFFSET,
82                 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
83         spl_parse_image_header(header);
84         nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
85                 (void *)spl_image.load_addr);
86 #ifdef CONFIG_ENV_OFFSET_REDUND
87         nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
88                 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
89         spl_parse_image_header(header);
90         nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
91                 (void *)spl_image.load_addr);
92 #endif
93 #endif
94         /* Load u-boot */
95         ret = nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
96                                 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
97         if (ret == 0) {
98                 spl_parse_image_header(header);
99                 ret = nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
100                                         spl_image.size, (void *)spl_image.load_addr);
101         }
102         nand_deselect();
103         return ret;
104 }