blob: 9da021862eaf9c67c4e680564222b9aae1f319bd [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Simon Schwarze21d2d82011-09-14 15:33:34 -04006 */
7#include <common.h>
Tom Rini9ef51bd2012-08-14 14:33:02 -07008#include <config.h>
Tom Rini28591df2012-08-13 12:03:19 -07009#include <spl.h>
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000010#include <asm/io.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040011#include <nand.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040012
Simon Schwarze21d2d82011-09-14 15:33:34 -040013void spl_nand_load_image(void)
14{
15 struct image_header *header;
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000016 int *src __attribute__((unused));
17 int *dst __attribute__((unused));
18
Tom Rini09ebf1a2012-08-13 14:11:06 -070019 debug("spl: nand - using hw ecc\n");
Tom Rini09ebf1a2012-08-13 14:11:06 -070020 nand_init();
Simon Schwarze21d2d82011-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 Schwarz6c3ddde2012-03-15 04:01:36 +000024#ifdef CONFIG_SPL_OS_BOOT
Simon Schwarz305bc4c2012-03-15 04:01:38 +000025 if (!spl_start_uboot()) {
Simon Schwarz6c3ddde2012-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 Vasut6d016762012-03-31 07:47:17 +000030 * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
Simon Schwarz6c3ddde2012-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 Schwarze21d2d82011-09-14 15:33:34 -040044
Simon Schwarz6c3ddde2012-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 Schwarz305bc4c2012-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 Rini9ef51bd2012-08-14 14:33:02 -070056 puts("The Expected Linux image was not "
57 "found. Please check your NAND "
Simon Schwarz305bc4c2012-03-15 04:01:38 +000058 "configuration.\n");
Tom Rini9ef51bd2012-08-14 14:33:02 -070059 puts("Trying to start u-boot now...\n");
Simon Schwarz305bc4c2012-03-15 04:01:38 +000060 }
61 }
Simon Schwarz6c3ddde2012-03-15 04:01:36 +000062#endif
Simon Schwarze21d2d82011-09-14 15:33:34 -040063#ifdef CONFIG_NAND_ENV_DST
Simon Schwarz305bc4c2012-03-15 04:01:38 +000064 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);
Simon Schwarze21d2d82011-09-14 15:33:34 -040069#ifdef CONFIG_ENV_OFFSET_REDUND
Simon Schwarz305bc4c2012-03-15 04:01:38 +000070 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);
Simon Schwarze21d2d82011-09-14 15:33:34 -040075#endif
76#endif
Simon Schwarz305bc4c2012-03-15 04:01:38 +000077 /* 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 Schwarze21d2d82011-09-14 15:33:34 -040083 nand_deselect();
84}