blob: 39221d5e7a9109892a1f3db7312d270fa0bd26b0 [file] [log] [blame]
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -04001/*
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 <asm/u-boot.h>
25#include <asm/utils.h>
26#include <asm/arch/sys_proto.h>
Simon Schwarzdf163a52012-03-15 04:01:36 +000027#include <asm/io.h>
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040028#include <nand.h>
Simon Glassefb21722011-10-10 08:55:19 +000029#include <version.h>
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040030#include <asm/omap_common.h>
31
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040032void spl_nand_load_image(void)
33{
34 struct image_header *header;
Simon Schwarzdf163a52012-03-15 04:01:36 +000035 int *src __attribute__((unused));
36 int *dst __attribute__((unused));
37
Tom Rini8082fda2012-08-13 14:11:06 -070038 debug("spl: nand - using hw ecc\n");
39 gpmc_init();
40 nand_init();
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040041
42 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
43 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
Simon Schwarzdf163a52012-03-15 04:01:36 +000044#ifdef CONFIG_SPL_OS_BOOT
Simon Schwarz379c19a2012-03-15 04:01:38 +000045 if (!spl_start_uboot()) {
Simon Schwarzdf163a52012-03-15 04:01:36 +000046 /*
47 * load parameter image
48 * load to temp position since nand_spl_load_image reads
49 * a whole block which is typically larger than
Marek Vasutb6e95fd2012-03-31 07:47:17 +000050 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
Simon Schwarzdf163a52012-03-15 04:01:36 +000051 * following sections like BSS
52 */
53 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
54 CONFIG_CMD_SPL_WRITE_SIZE,
55 (void *)CONFIG_SYS_TEXT_BASE);
56 /* copy to destintion */
57 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
58 src = (int *)CONFIG_SYS_TEXT_BASE;
59 src < (int *)(CONFIG_SYS_TEXT_BASE +
60 CONFIG_CMD_SPL_WRITE_SIZE);
61 src++, dst++) {
62 writel(readl(src), dst);
63 }
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040064
Simon Schwarzdf163a52012-03-15 04:01:36 +000065 /* load linux */
66 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
67 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
68 spl_parse_image_header(header);
Simon Schwarz379c19a2012-03-15 04:01:38 +000069 if (header->ih_os == IH_OS_LINUX) {
70 /* happy - was a linux */
71 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
72 spl_image.size, (void *)spl_image.load_addr);
73 nand_deselect();
74 return;
75 } else {
76 printf("The Expected Linux image was not"
77 "found. Please check your NAND"
78 "configuration.\n");
79 printf("Trying to start u-boot now...\n");
80 }
Simon Schwarzdf163a52012-03-15 04:01:36 +000081 }
Simon Schwarz379c19a2012-03-15 04:01:38 +000082#endif
83#ifdef CONFIG_NAND_ENV_DST
84 nand_spl_load_image(CONFIG_ENV_OFFSET,
85 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
86 spl_parse_image_header(header);
87 nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
88 (void *)spl_image.load_addr);
89#ifdef CONFIG_ENV_OFFSET_REDUND
90 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
91 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
92 spl_parse_image_header(header);
93 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
94 (void *)spl_image.load_addr);
95#endif
96#endif
97 /* Load u-boot */
98 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
99 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
100 spl_parse_image_header(header);
101 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
102 spl_image.size, (void *)spl_image.load_addr);
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -0400103 nand_deselect();
104}