blob: 2a6621492e984f2a36dd85b51abe2dc49cecc766 [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>
24#include <asm/u-boot.h>
25#include <asm/utils.h>
26#include <asm/arch/sys_proto.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#include <asm/omap_common.h>
31
32
33void spl_nand_load_image(void)
34{
35 struct image_header *header;
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000036 int *src __attribute__((unused));
37 int *dst __attribute__((unused));
38
Simon Schwarze21d2d82011-09-14 15:33:34 -040039 switch (omap_boot_mode()) {
40 case NAND_MODE_HW_ECC:
41 debug("spl: nand - using hw ecc\n");
42 gpmc_init();
43 nand_init();
44 break;
45 default:
46 puts("spl: ERROR: This bootmode is not implemented - hanging");
47 hang();
48 }
49
50 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
51 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000052#ifdef CONFIG_SPL_OS_BOOT
53 if (!spl_uboot_key()) {
54 /*
55 * load parameter image
56 * load to temp position since nand_spl_load_image reads
57 * a whole block which is typically larger than
58 * CONFIG_CMD_SAVEBP_WRITE_SIZE therefore may overwrite
59 * following sections like BSS
60 */
61 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
62 CONFIG_CMD_SPL_WRITE_SIZE,
63 (void *)CONFIG_SYS_TEXT_BASE);
64 /* copy to destintion */
65 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
66 src = (int *)CONFIG_SYS_TEXT_BASE;
67 src < (int *)(CONFIG_SYS_TEXT_BASE +
68 CONFIG_CMD_SPL_WRITE_SIZE);
69 src++, dst++) {
70 writel(readl(src), dst);
71 }
Simon Schwarze21d2d82011-09-14 15:33:34 -040072
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000073 /* load linux */
74 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
75 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
76 spl_parse_image_header(header);
77 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
78 spl_image.size, (void *)spl_image.load_addr);
79 } else
80#endif
81 {
Simon Schwarze21d2d82011-09-14 15:33:34 -040082#ifdef CONFIG_NAND_ENV_DST
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000083 nand_spl_load_image(CONFIG_ENV_OFFSET,
84 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
85 spl_parse_image_header(header);
86 nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
87 (void *)spl_image.load_addr);
Simon Schwarze21d2d82011-09-14 15:33:34 -040088#ifdef CONFIG_ENV_OFFSET_REDUND
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000089 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
90 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
91 spl_parse_image_header(header);
92 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
93 (void *)spl_image.load_addr);
Simon Schwarze21d2d82011-09-14 15:33:34 -040094#endif
95#endif
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000096 /* Load u-boot */
97 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
98 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
99 spl_parse_image_header(header);
100 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
101 spl_image.size, (void *)spl_image.load_addr);
102 }
Simon Schwarze21d2d82011-09-14 15:33:34 -0400103 nand_deselect();
104}