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>
|
|
|
|
|
2014-10-31 07:31:00 +00:00
|
|
|
#if defined(CONFIG_SPL_NAND_RAW_ONLY)
|
2015-11-08 15:11:49 +00:00
|
|
|
int spl_nand_load_image(void)
|
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);
|
|
|
|
spl_set_header_raw_uboot();
|
|
|
|
nand_deselect();
|
2015-11-08 15:11:49 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-10-31 07:31:00 +00:00
|
|
|
}
|
|
|
|
#else
|
2015-11-08 15:11:42 +00:00
|
|
|
static int spl_nand_load_element(int offset, struct image_header *header)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
spl_parse_image_header(header);
|
|
|
|
return nand_spl_load_image(offset, spl_image.size,
|
|
|
|
(void *)(unsigned long)spl_image.load_addr);
|
|
|
|
}
|
|
|
|
|
2015-11-08 15:11:49 +00:00
|
|
|
int spl_nand_load_image(void)
|
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));
|
|
|
|
|
2012-08-13 21:11:06 +00:00
|
|
|
debug("spl: nand - using hw ecc\n");
|
|
|
|
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);
|
2012-03-15 04:01:36 +00:00
|
|
|
spl_parse_image_header(header);
|
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,
|
|
|
|
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
|
2015-11-08 15:11:42 +00:00
|
|
|
spl_nand_load_element(CONFIG_ENV_OFFSET, header);
|
2011-09-14 19:33:34 +00:00
|
|
|
#ifdef CONFIG_ENV_OFFSET_REDUND
|
2015-11-08 15:11:42 +00:00
|
|
|
spl_nand_load_element(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 */
|
2015-11-08 15:11:49 +00:00
|
|
|
err = spl_nand_load_element(CONFIG_SYS_NAND_U_BOOT_OFFS, header);
|
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
|