blob: 9e9206ce3b62092973e28508d764de3968ca3f0b [file] [log] [blame]
Simon Schwarze21d2d82011-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>
Tom Rini28591df2012-08-13 12:03:19 -070024#include <spl.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040025#include <asm/u-boot.h>
26#include <asm/utils.h>
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000027#include <asm/io.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040028#include <nand.h>
Simon Glass50402412011-10-10 08:55:19 +000029#include <version.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040030
Simon Schwarze21d2d82011-09-14 15:33:34 -040031void spl_nand_load_image(void)
32{
33 struct image_header *header;
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000034 int *src __attribute__((unused));
35 int *dst __attribute__((unused));
36
Tom Rini09ebf1a2012-08-13 14:11:06 -070037 debug("spl: nand - using hw ecc\n");
Tom Rini09ebf1a2012-08-13 14:11:06 -070038 nand_init();
Simon Schwarze21d2d82011-09-14 15:33:34 -040039
40 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
41 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000042#ifdef CONFIG_SPL_OS_BOOT
Simon Schwarz305bc4c2012-03-15 04:01:38 +000043 if (!spl_start_uboot()) {
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000044 /*
45 * load parameter image
46 * load to temp position since nand_spl_load_image reads
47 * a whole block which is typically larger than
Marek Vasut6d016762012-03-31 07:47:17 +000048 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000049 * following sections like BSS
50 */
51 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
52 CONFIG_CMD_SPL_WRITE_SIZE,
53 (void *)CONFIG_SYS_TEXT_BASE);
54 /* copy to destintion */
55 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
56 src = (int *)CONFIG_SYS_TEXT_BASE;
57 src < (int *)(CONFIG_SYS_TEXT_BASE +
58 CONFIG_CMD_SPL_WRITE_SIZE);
59 src++, dst++) {
60 writel(readl(src), dst);
61 }
Simon Schwarze21d2d82011-09-14 15:33:34 -040062
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000063 /* load linux */
64 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
65 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
66 spl_parse_image_header(header);
Simon Schwarz305bc4c2012-03-15 04:01:38 +000067 if (header->ih_os == IH_OS_LINUX) {
68 /* happy - was a linux */
69 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
70 spl_image.size, (void *)spl_image.load_addr);
71 nand_deselect();
72 return;
73 } else {
74 printf("The Expected Linux image was not"
75 "found. Please check your NAND"
76 "configuration.\n");
77 printf("Trying to start u-boot now...\n");
78 }
79 }
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000080#endif
Simon Schwarze21d2d82011-09-14 15:33:34 -040081#ifdef CONFIG_NAND_ENV_DST
Simon Schwarz305bc4c2012-03-15 04:01:38 +000082 nand_spl_load_image(CONFIG_ENV_OFFSET,
83 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
84 spl_parse_image_header(header);
85 nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
86 (void *)spl_image.load_addr);
Simon Schwarze21d2d82011-09-14 15:33:34 -040087#ifdef CONFIG_ENV_OFFSET_REDUND
Simon Schwarz305bc4c2012-03-15 04:01:38 +000088 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
89 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
90 spl_parse_image_header(header);
91 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
92 (void *)spl_image.load_addr);
Simon Schwarze21d2d82011-09-14 15:33:34 -040093#endif
94#endif
Simon Schwarz305bc4c2012-03-15 04:01:38 +000095 /* Load u-boot */
96 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
97 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
98 spl_parse_image_header(header);
99 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
100 spl_image.size, (void *)spl_image.load_addr);
Simon Schwarze21d2d82011-09-14 15:33:34 -0400101 nand_deselect();
102}