2011-09-14 19:33:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011
|
|
|
|
* Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2011-09-14 19:33:34 +00:00
|
|
|
*/
|
|
|
|
#include <common.h>
|
2012-08-14 21:33:02 +00:00
|
|
|
#include <config.h>
|
2012-08-13 19:03:19 +00:00
|
|
|
#include <spl.h>
|
2012-03-15 04:01:36 +00:00
|
|
|
#include <asm/io.h>
|
2011-09-14 19:33:34 +00:00
|
|
|
#include <nand.h>
|
2016-05-24 05:04:42 +00:00
|
|
|
#include <libfdt_env.h>
|
|
|
|
#include <fdt.h>
|
2011-09-14 19:33:34 +00:00
|
|
|
|
2014-10-31 07:31:00 +00:00
|
|
|
#if defined(CONFIG_SPL_NAND_RAW_ONLY)
|
2016-09-25 00:20:13 +00:00
|
|
|
int spl_nand_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
2014-10-31 07:31:00 +00:00
|
|
|
{
|
|
|
|
nand_init();
|
|
|
|
|
|
|
|
nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
|
|
|
|
CONFIG_SYS_NAND_U_BOOT_SIZE,
|
|
|
|
(void *)CONFIG_SYS_NAND_U_BOOT_DST);
|
2016-09-25 00:20:13 +00:00
|
|
|
spl_set_header_raw_uboot(spl_image);
|
2014-10-31 07:31:00 +00:00
|
|
|
nand_deselect();
|
2015-11-08 15:11:49 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-10-31 07:31:00 +00:00
|
|
|
}
|
|
|
|
#else
|
2016-05-24 05:04:42 +00:00
|
|
|
|
|
|
|
static ulong spl_nand_fit_read(struct spl_load_info *load, ulong offs,
|
|
|
|
ulong size, void *dst)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = nand_spl_load_image(offs, size, dst);
|
|
|
|
if (!ret)
|
|
|
|
return size;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-25 00:20:13 +00:00
|
|
|
static int spl_nand_load_element(struct spl_image_info *spl_image,
|
|
|
|
int offset, struct image_header *header)
|
2015-11-08 15:11:42 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2016-05-24 05:04:42 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
|
|
|
|
image_get_magic(header) == FDT_MAGIC) {
|
|
|
|
struct spl_load_info load;
|
2016-04-28 22:44:54 +00:00
|
|
|
|
2016-05-24 05:04:42 +00:00
|
|
|
debug("Found FIT\n");
|
|
|
|
load.dev = NULL;
|
|
|
|
load.priv = NULL;
|
|
|
|
load.filename = NULL;
|
|
|
|
load.bl_len = 1;
|
|
|
|
load.read = spl_nand_fit_read;
|
2016-09-25 00:20:16 +00:00
|
|
|
return spl_load_simple_fit(spl_image, &load, offset, header);
|
2016-05-24 05:04:42 +00:00
|
|
|
} else {
|
2016-09-25 00:20:13 +00:00
|
|
|
err = spl_parse_image_header(spl_image, header);
|
2016-05-24 05:04:42 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2016-09-25 00:20:13 +00:00
|
|
|
return nand_spl_load_image(offset, spl_image->size,
|
|
|
|
(void *)(ulong)spl_image->load_addr);
|
2016-05-24 05:04:42 +00:00
|
|
|
}
|
2015-11-08 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
2016-09-25 00:20:13 +00:00
|
|
|
static int spl_nand_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
2011-09-14 19:33:34 +00:00
|
|
|
{
|
2015-11-08 15:11:49 +00:00
|
|
|
int err;
|
2011-09-14 19:33:34 +00:00
|
|
|
struct image_header *header;
|
2012-03-15 04:01:36 +00:00
|
|
|
int *src __attribute__((unused));
|
|
|
|
int *dst __attribute__((unused));
|
|
|
|
|
2016-03-25 12:13:17 +00:00
|
|
|
#ifdef CONFIG_SPL_NAND_SOFTECC
|
|
|
|
debug("spl: nand - using sw ecc\n");
|
|
|
|
#else
|
2012-08-13 21:11:06 +00:00
|
|
|
debug("spl: nand - using hw ecc\n");
|
2016-03-25 12:13:17 +00:00
|
|
|
#endif
|
2012-08-13 21:11:06 +00:00
|
|
|
nand_init();
|
2011-09-14 19:33:34 +00:00
|
|
|
|
|
|
|
/*use CONFIG_SYS_TEXT_BASE as temporary storage area */
|
|
|
|
header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
|
2012-03-15 04:01:36 +00:00
|
|
|
#ifdef CONFIG_SPL_OS_BOOT
|
2012-03-15 04:01:38 +00:00
|
|
|
if (!spl_start_uboot()) {
|
2012-03-15 04:01:36 +00:00
|
|
|
/*
|
|
|
|
* load parameter image
|
|
|
|
* load to temp position since nand_spl_load_image reads
|
|
|
|
* a whole block which is typically larger than
|
2012-03-31 07:47:17 +00:00
|
|
|
* CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
|
2012-03-15 04:01:36 +00:00
|
|
|
* following sections like BSS
|
|
|
|
*/
|
|
|
|
nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
|
|
|
|
CONFIG_CMD_SPL_WRITE_SIZE,
|
|
|
|
(void *)CONFIG_SYS_TEXT_BASE);
|
|
|
|
/* copy to destintion */
|
|
|
|
for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
|
|
|
|
src = (int *)CONFIG_SYS_TEXT_BASE;
|
|
|
|
src < (int *)(CONFIG_SYS_TEXT_BASE +
|
|
|
|
CONFIG_CMD_SPL_WRITE_SIZE);
|
|
|
|
src++, dst++) {
|
|
|
|
writel(readl(src), dst);
|
|
|
|
}
|
2011-09-14 19:33:34 +00:00
|
|
|
|
2012-03-15 04:01:36 +00:00
|
|
|
/* load linux */
|
|
|
|
nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
|
2014-07-10 11:43:16 +00:00
|
|
|
sizeof(*header), (void *)header);
|
2016-09-25 00:20:13 +00:00
|
|
|
err = spl_parse_image_header(spl_image, header);
|
2016-04-28 22:44:54 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2012-03-15 04:01:38 +00:00
|
|
|
if (header->ih_os == IH_OS_LINUX) {
|
|
|
|
/* happy - was a linux */
|
2015-11-08 15:11:49 +00:00
|
|
|
err = nand_spl_load_image(
|
|
|
|
CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
|
2016-09-25 00:20:13 +00:00
|
|
|
spl_image->size,
|
|
|
|
(void *)spl_image->load_addr);
|
2012-03-15 04:01:38 +00:00
|
|
|
nand_deselect();
|
2015-11-08 15:11:49 +00:00
|
|
|
return err;
|
2012-03-15 04:01:38 +00:00
|
|
|
} else {
|
2012-08-14 21:33:02 +00:00
|
|
|
puts("The Expected Linux image was not "
|
|
|
|
"found. Please check your NAND "
|
2012-03-15 04:01:38 +00:00
|
|
|
"configuration.\n");
|
2012-08-14 21:33:02 +00:00
|
|
|
puts("Trying to start u-boot now...\n");
|
2012-03-15 04:01:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-15 04:01:36 +00:00
|
|
|
#endif
|
2011-09-14 19:33:34 +00:00
|
|
|
#ifdef CONFIG_NAND_ENV_DST
|
2016-09-25 00:20:13 +00:00
|
|
|
spl_nand_load_element(spl_image, CONFIG_ENV_OFFSET, header);
|
2011-09-14 19:33:34 +00:00
|
|
|
#ifdef CONFIG_ENV_OFFSET_REDUND
|
2016-09-25 00:20:13 +00:00
|
|
|
spl_nand_load_element(spl_image, CONFIG_ENV_OFFSET_REDUND, header);
|
2011-09-14 19:33:34 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2012-03-15 04:01:38 +00:00
|
|
|
/* Load u-boot */
|
2016-09-25 00:20:13 +00:00
|
|
|
err = spl_nand_load_element(spl_image, CONFIG_SYS_NAND_U_BOOT_OFFS,
|
|
|
|
header);
|
2016-06-06 08:16:58 +00:00
|
|
|
#ifdef CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
|
|
|
|
#if CONFIG_SYS_NAND_U_BOOT_OFFS != CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
|
|
|
|
if (err)
|
2016-09-25 00:20:13 +00:00
|
|
|
err = spl_nand_load_element(spl_image,
|
|
|
|
CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND,
|
2016-06-06 08:16:58 +00:00
|
|
|
header);
|
|
|
|
#endif
|
|
|
|
#endif
|
2011-09-14 19:33:34 +00:00
|
|
|
nand_deselect();
|
2015-11-08 15:11:49 +00:00
|
|
|
return err;
|
2011-09-14 19:33:34 +00:00
|
|
|
}
|
2014-10-31 07:31:00 +00:00
|
|
|
#endif
|
2016-09-25 00:20:02 +00:00
|
|
|
/* Use priorty 1 so that Ubi can override this */
|
2016-11-30 22:30:50 +00:00
|
|
|
SPL_LOAD_IMAGE_METHOD("NAND", 1, BOOT_DEVICE_NAND, spl_nand_load_image);
|