spl: nand: refactor spl_nand_load_image for falcon mode
This patch moves the falcon mode handling logic out of spl_ubi_load_image to spl_ubi_load_image_os, this allows for cleaner handling for fallback to U-Boot in case falcon mode fails. Signed-off-by: Anshul Dalal <anshuld@ti.com>
This commit is contained in:
@@ -75,6 +75,52 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
|
||||
return spl_load(spl_image, bootdev, &load, 0, offset);
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_SPL_OS_BOOT)
|
||||
static int spl_nand_load_image_os(struct spl_image_info *spl_image,
|
||||
struct spl_boot_device *bootdev)
|
||||
{
|
||||
int *src, *dst, err;
|
||||
struct legacy_img_hdr *header = spl_get_load_buffer(0, sizeof(*header));
|
||||
|
||||
/* load linux */
|
||||
nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS, sizeof(*header),
|
||||
(void *)header);
|
||||
err = spl_parse_image_header(spl_image, bootdev, header);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (header->ih_os != IH_OS_LINUX)
|
||||
return -EINVAL;
|
||||
|
||||
/* happy - was a linux */
|
||||
err = nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
|
||||
spl_image->size,
|
||||
(void *)spl_image->load_addr);
|
||||
nand_deselect();
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/*
|
||||
* load parameter image load to temp position since nand_spl_load_image
|
||||
* reads a whole block which is typically larger than
|
||||
* CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite following sections
|
||||
* like BSS
|
||||
*/
|
||||
nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS, CONFIG_CMD_SPL_WRITE_SIZE,
|
||||
(void *)CONFIG_TEXT_BASE);
|
||||
/* copy to destintion */
|
||||
for (dst = (int *)CONFIG_SPL_PAYLOAD_ARGS_ADDR,
|
||||
src = (int *)CONFIG_TEXT_BASE;
|
||||
src < (int *)(CONFIG_TEXT_BASE + CONFIG_CMD_SPL_WRITE_SIZE);
|
||||
src++, dst++) {
|
||||
writel(readl(src), dst);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int spl_nand_load_image(struct spl_image_info *spl_image,
|
||||
struct spl_boot_device *bootdev)
|
||||
{
|
||||
@@ -89,51 +135,14 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,
|
||||
|
||||
#if CONFIG_IS_ENABLED(OS_BOOT)
|
||||
if (!spl_start_uboot()) {
|
||||
int *src, *dst;
|
||||
struct legacy_img_hdr *header =
|
||||
spl_get_load_buffer(0, sizeof(*header));
|
||||
|
||||
/*
|
||||
* load parameter image
|
||||
* load to temp position since nand_spl_load_image reads
|
||||
* a whole block which is typically larger than
|
||||
* CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
|
||||
* following sections like BSS
|
||||
*/
|
||||
nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
|
||||
CONFIG_CMD_SPL_WRITE_SIZE,
|
||||
(void *)CONFIG_TEXT_BASE);
|
||||
/* copy to destintion */
|
||||
for (dst = (int *)CONFIG_SPL_PAYLOAD_ARGS_ADDR,
|
||||
src = (int *)CONFIG_TEXT_BASE;
|
||||
src < (int *)(CONFIG_TEXT_BASE +
|
||||
CONFIG_CMD_SPL_WRITE_SIZE);
|
||||
src++, dst++) {
|
||||
writel(readl(src), dst);
|
||||
}
|
||||
|
||||
/* load linux */
|
||||
nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
|
||||
sizeof(*header), (void *)header);
|
||||
err = spl_parse_image_header(spl_image, bootdev, header);
|
||||
if (err)
|
||||
return err;
|
||||
if (header->ih_os == IH_OS_LINUX) {
|
||||
/* happy - was a linux */
|
||||
err = nand_spl_load_image(
|
||||
CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
|
||||
spl_image->size,
|
||||
(void *)spl_image->load_addr);
|
||||
nand_deselect();
|
||||
return err;
|
||||
} else {
|
||||
puts("The Expected Linux image was not "
|
||||
"found. Please check your NAND "
|
||||
"configuration.\n");
|
||||
puts("Trying to start u-boot now...\n");
|
||||
}
|
||||
err = spl_nand_load_image_os(spl_image, bootdev);
|
||||
if (!err)
|
||||
return 0;
|
||||
printf("%s: Failed in falcon boot: %d, fallback to U-Boot",
|
||||
__func__, err);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NAND_ENV_DST
|
||||
spl_nand_load_element(spl_image, bootdev, CONFIG_ENV_OFFSET);
|
||||
#ifdef CONFIG_ENV_OFFSET_REDUND
|
||||
|
||||
Reference in New Issue
Block a user