2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-09-14 19:33:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011
|
|
|
|
* Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2012-08-14 21:33:02 +00:00
|
|
|
#include <config.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <fdt_support.h>
|
|
|
|
#include <image.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.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>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt_env.h>
|
2016-05-24 05:04:42 +00:00
|
|
|
#include <fdt.h>
|
2011-09-14 19:33:34 +00:00
|
|
|
|
2019-09-23 02:18:43 +00:00
|
|
|
uint32_t __weak spl_nand_get_uboot_raw_page(void)
|
|
|
|
{
|
|
|
|
return CONFIG_SYS_NAND_U_BOOT_OFFS;
|
|
|
|
}
|
|
|
|
|
2014-10-31 07:31:00 +00:00
|
|
|
#if defined(CONFIG_SPL_NAND_RAW_ONLY)
|
2018-07-04 13:53:37 +00:00
|
|
|
static int spl_nand_load_image(struct spl_image_info *spl_image,
|
2016-09-25 00:20:13 +00:00
|
|
|
struct spl_boot_device *bootdev)
|
2014-10-31 07:31:00 +00:00
|
|
|
{
|
|
|
|
nand_init();
|
|
|
|
|
2019-03-26 12:04:00 +00:00
|
|
|
printf("Loading U-Boot from 0x%08x (size 0x%08x) to 0x%08x\n",
|
|
|
|
CONFIG_SYS_NAND_U_BOOT_OFFS, CONFIG_SYS_NAND_U_BOOT_SIZE,
|
|
|
|
CONFIG_SYS_NAND_U_BOOT_DST);
|
|
|
|
|
2019-09-23 02:18:43 +00:00
|
|
|
nand_spl_load_image(spl_nand_get_uboot_raw_page(),
|
2014-10-31 07:31:00 +00:00
|
|
|
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)
|
|
|
|
{
|
2020-05-27 11:56:21 +00:00
|
|
|
int err;
|
2021-03-01 22:33:27 +00:00
|
|
|
#ifdef CONFIG_SYS_NAND_BLOCK_SIZE
|
|
|
|
ulong sector;
|
2016-05-24 05:04:42 +00:00
|
|
|
|
2020-05-27 11:56:20 +00:00
|
|
|
sector = *(int *)load->priv;
|
|
|
|
offs = sector + nand_spl_adjust_offset(sector, offs - sector);
|
2021-03-01 22:33:28 +00:00
|
|
|
#else
|
|
|
|
offs *= load->bl_len;
|
|
|
|
size *= load->bl_len;
|
2021-03-01 22:33:27 +00:00
|
|
|
#endif
|
2020-05-27 11:56:21 +00:00
|
|
|
err = nand_spl_load_image(offs, size, dst);
|
|
|
|
if (err)
|
2016-05-24 05:04:42 +00:00
|
|
|
return 0;
|
2020-05-27 11:56:21 +00:00
|
|
|
|
2021-03-01 22:33:28 +00:00
|
|
|
return size / load->bl_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mtd_info * __weak nand_get_mtd(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
2016-05-24 05:04:42 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-03-01 22:33:28 +00:00
|
|
|
struct mtd_info *mtd = nand_get_mtd();
|
|
|
|
int bl_len = mtd ? mtd->writesize : 1;
|
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;
|
2020-05-27 11:56:20 +00:00
|
|
|
load.priv = &offset;
|
2016-05-24 05:04:42 +00:00
|
|
|
load.filename = NULL;
|
2021-03-01 22:33:28 +00:00
|
|
|
load.bl_len = bl_len;
|
2016-05-24 05:04:42 +00:00
|
|
|
load.read = spl_nand_fit_read;
|
2021-03-01 22:33:28 +00:00
|
|
|
return spl_load_simple_fit(spl_image, &load, offset / bl_len, header);
|
2019-09-23 02:18:46 +00:00
|
|
|
} else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
|
|
|
|
struct spl_load_info load;
|
|
|
|
|
|
|
|
load.dev = NULL;
|
|
|
|
load.priv = NULL;
|
|
|
|
load.filename = NULL;
|
2021-03-01 22:33:28 +00:00
|
|
|
load.bl_len = bl_len;
|
2019-09-23 02:18:46 +00:00
|
|
|
load.read = spl_nand_fit_read;
|
2021-03-01 22:33:28 +00:00
|
|
|
return spl_load_imx_container(spl_image, &load, offset / bl_len);
|
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
|
|
|
|
2018-08-14 09:27:02 +00:00
|
|
|
header = spl_get_load_buffer(0, sizeof(*header));
|
|
|
|
|
2021-10-31 03:03:48 +00:00
|
|
|
#if CONFIG_IS_ENABLED(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 */
|
2019-09-23 02:18:43 +00:00
|
|
|
err = spl_nand_load_element(spl_image, spl_nand_get_uboot_raw_page(),
|
2016-09-25 00:20:13 +00:00
|
|
|
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);
|