blob: b7801cb4605f16c54c99f65e3e8ed93db5d3e564 [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -04006 */
7#include <common.h>
Tom Rinid97b4ce2012-08-14 14:33:02 -07008#include <config.h>
Tom Rini47f7bca2012-08-13 12:03:19 -07009#include <spl.h>
Simon Schwarzdf163a52012-03-15 04:01:36 +000010#include <asm/io.h>
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040011#include <nand.h>
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040012
Heiko Schocher0c3117b2014-10-31 08:31:00 +010013#if defined(CONFIG_SPL_NAND_RAW_ONLY)
14void spl_nand_load_image(void)
15{
16 nand_init();
17
18 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
19 CONFIG_SYS_NAND_U_BOOT_SIZE,
20 (void *)CONFIG_SYS_NAND_U_BOOT_DST);
21 spl_set_header_raw_uboot();
22 nand_deselect();
23}
24#else
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040025void spl_nand_load_image(void)
26{
27 struct image_header *header;
Simon Schwarzdf163a52012-03-15 04:01:36 +000028 int *src __attribute__((unused));
29 int *dst __attribute__((unused));
30
Tom Rini8082fda2012-08-13 14:11:06 -070031 debug("spl: nand - using hw ecc\n");
Tom Rini8082fda2012-08-13 14:11:06 -070032 nand_init();
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040033
34 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
35 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
Simon Schwarzdf163a52012-03-15 04:01:36 +000036#ifdef CONFIG_SPL_OS_BOOT
Simon Schwarz379c19a2012-03-15 04:01:38 +000037 if (!spl_start_uboot()) {
Simon Schwarzdf163a52012-03-15 04:01:36 +000038 /*
39 * load parameter image
40 * load to temp position since nand_spl_load_image reads
41 * a whole block which is typically larger than
Marek Vasutb6e95fd2012-03-31 07:47:17 +000042 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
Simon Schwarzdf163a52012-03-15 04:01:36 +000043 * following sections like BSS
44 */
45 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
46 CONFIG_CMD_SPL_WRITE_SIZE,
47 (void *)CONFIG_SYS_TEXT_BASE);
48 /* copy to destintion */
49 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
50 src = (int *)CONFIG_SYS_TEXT_BASE;
51 src < (int *)(CONFIG_SYS_TEXT_BASE +
52 CONFIG_CMD_SPL_WRITE_SIZE);
53 src++, dst++) {
54 writel(readl(src), dst);
55 }
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040056
Simon Schwarzdf163a52012-03-15 04:01:36 +000057 /* load linux */
58 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
Masahiro Yamadac13bb162014-07-10 20:43:16 +090059 sizeof(*header), (void *)header);
Simon Schwarzdf163a52012-03-15 04:01:36 +000060 spl_parse_image_header(header);
Simon Schwarz379c19a2012-03-15 04:01:38 +000061 if (header->ih_os == IH_OS_LINUX) {
62 /* happy - was a linux */
63 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
64 spl_image.size, (void *)spl_image.load_addr);
65 nand_deselect();
66 return;
67 } else {
Tom Rinid97b4ce2012-08-14 14:33:02 -070068 puts("The Expected Linux image was not "
69 "found. Please check your NAND "
Simon Schwarz379c19a2012-03-15 04:01:38 +000070 "configuration.\n");
Tom Rinid97b4ce2012-08-14 14:33:02 -070071 puts("Trying to start u-boot now...\n");
Simon Schwarz379c19a2012-03-15 04:01:38 +000072 }
Simon Schwarzdf163a52012-03-15 04:01:36 +000073 }
Simon Schwarz379c19a2012-03-15 04:01:38 +000074#endif
75#ifdef CONFIG_NAND_ENV_DST
76 nand_spl_load_image(CONFIG_ENV_OFFSET,
Masahiro Yamadac13bb162014-07-10 20:43:16 +090077 sizeof(*header), (void *)header);
Simon Schwarz379c19a2012-03-15 04:01:38 +000078 spl_parse_image_header(header);
79 nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
80 (void *)spl_image.load_addr);
81#ifdef CONFIG_ENV_OFFSET_REDUND
82 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
Masahiro Yamadac13bb162014-07-10 20:43:16 +090083 sizeof(*header), (void *)header);
Simon Schwarz379c19a2012-03-15 04:01:38 +000084 spl_parse_image_header(header);
85 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
86 (void *)spl_image.load_addr);
87#endif
88#endif
89 /* Load u-boot */
90 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
Tim Harvey50c8d662014-05-07 22:16:12 -070091 sizeof(*header), (void *)header);
Simon Schwarz379c19a2012-03-15 04:01:38 +000092 spl_parse_image_header(header);
93 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
94 spl_image.size, (void *)spl_image.load_addr);
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040095 nand_deselect();
96}
Heiko Schocher0c3117b2014-10-31 08:31:00 +010097#endif