blob: 9da021862eaf9c67c4e680564222b9aae1f319bd [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
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040013void spl_nand_load_image(void)
14{
15 struct image_header *header;
Simon Schwarzdf163a52012-03-15 04:01:36 +000016 int *src __attribute__((unused));
17 int *dst __attribute__((unused));
18
Tom Rini8082fda2012-08-13 14:11:06 -070019 debug("spl: nand - using hw ecc\n");
Tom Rini8082fda2012-08-13 14:11:06 -070020 nand_init();
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040021
22 /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
23 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
Simon Schwarzdf163a52012-03-15 04:01:36 +000024#ifdef CONFIG_SPL_OS_BOOT
Simon Schwarz379c19a2012-03-15 04:01:38 +000025 if (!spl_start_uboot()) {
Simon Schwarzdf163a52012-03-15 04:01:36 +000026 /*
27 * load parameter image
28 * load to temp position since nand_spl_load_image reads
29 * a whole block which is typically larger than
Marek Vasutb6e95fd2012-03-31 07:47:17 +000030 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
Simon Schwarzdf163a52012-03-15 04:01:36 +000031 * following sections like BSS
32 */
33 nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
34 CONFIG_CMD_SPL_WRITE_SIZE,
35 (void *)CONFIG_SYS_TEXT_BASE);
36 /* copy to destintion */
37 for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
38 src = (int *)CONFIG_SYS_TEXT_BASE;
39 src < (int *)(CONFIG_SYS_TEXT_BASE +
40 CONFIG_CMD_SPL_WRITE_SIZE);
41 src++, dst++) {
42 writel(readl(src), dst);
43 }
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040044
Simon Schwarzdf163a52012-03-15 04:01:36 +000045 /* load linux */
46 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
47 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
48 spl_parse_image_header(header);
Simon Schwarz379c19a2012-03-15 04:01:38 +000049 if (header->ih_os == IH_OS_LINUX) {
50 /* happy - was a linux */
51 nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
52 spl_image.size, (void *)spl_image.load_addr);
53 nand_deselect();
54 return;
55 } else {
Tom Rinid97b4ce2012-08-14 14:33:02 -070056 puts("The Expected Linux image was not "
57 "found. Please check your NAND "
Simon Schwarz379c19a2012-03-15 04:01:38 +000058 "configuration.\n");
Tom Rinid97b4ce2012-08-14 14:33:02 -070059 puts("Trying to start u-boot now...\n");
Simon Schwarz379c19a2012-03-15 04:01:38 +000060 }
Simon Schwarzdf163a52012-03-15 04:01:36 +000061 }
Simon Schwarz379c19a2012-03-15 04:01:38 +000062#endif
63#ifdef CONFIG_NAND_ENV_DST
64 nand_spl_load_image(CONFIG_ENV_OFFSET,
65 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
66 spl_parse_image_header(header);
67 nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
68 (void *)spl_image.load_addr);
69#ifdef CONFIG_ENV_OFFSET_REDUND
70 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
71 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
72 spl_parse_image_header(header);
73 nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
74 (void *)spl_image.load_addr);
75#endif
76#endif
77 /* Load u-boot */
78 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
79 CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
80 spl_parse_image_header(header);
81 nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
82 spl_image.size, (void *)spl_image.load_addr);
Simon Schwarz9ea5c6e2011-09-14 15:33:34 -040083 nand_deselect();
84}