2018-05-06 22:27:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
|
2016-07-12 18:28:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016
|
|
|
|
* Ladislav Michl <ladis@linux-mips.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <config.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <image.h>
|
2016-07-12 18:28:13 +00:00
|
|
|
#include <nand.h>
|
|
|
|
#include <onenand_uboot.h>
|
|
|
|
#include <ubispl.h>
|
|
|
|
#include <spl.h>
|
|
|
|
|
2016-09-25 00:20:13 +00:00
|
|
|
int spl_ubi_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
2016-07-12 18:28:13 +00:00
|
|
|
{
|
|
|
|
struct image_header *header;
|
|
|
|
struct ubispl_info info;
|
|
|
|
struct ubispl_load volumes[2];
|
|
|
|
int ret = 1;
|
|
|
|
|
2016-09-25 00:19:57 +00:00
|
|
|
switch (bootdev->boot_device) {
|
2016-07-12 18:28:13 +00:00
|
|
|
#ifdef CONFIG_SPL_NAND_SUPPORT
|
|
|
|
case BOOT_DEVICE_NAND:
|
|
|
|
nand_init();
|
|
|
|
info.read = nand_spl_read_block;
|
|
|
|
info.peb_size = CONFIG_SYS_NAND_BLOCK_SIZE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SPL_ONENAND_SUPPORT
|
|
|
|
case BOOT_DEVICE_ONENAND:
|
|
|
|
info.read = onenand_spl_read_block;
|
|
|
|
info.peb_size = CONFIG_SYS_ONENAND_BLOCK_SIZE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
info.ubi = (struct ubi_scan_info *)CONFIG_SPL_UBI_INFO_ADDR;
|
2017-06-25 08:26:11 +00:00
|
|
|
info.fastmap = IS_ENABLED(CONFIG_MTD_UBI_FASTMAP);
|
2016-07-12 18:28:13 +00:00
|
|
|
|
|
|
|
info.peb_offset = CONFIG_SPL_UBI_PEB_OFFSET;
|
|
|
|
info.vid_offset = CONFIG_SPL_UBI_VID_OFFSET;
|
|
|
|
info.leb_start = CONFIG_SPL_UBI_LEB_START;
|
|
|
|
info.peb_count = CONFIG_SPL_UBI_MAX_PEBS - info.peb_offset;
|
|
|
|
|
2021-10-31 03:03:48 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OS_BOOT)
|
2016-07-12 18:28:13 +00:00
|
|
|
if (!spl_start_uboot()) {
|
|
|
|
volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_KERNEL_ID;
|
|
|
|
volumes[0].load_addr = (void *)CONFIG_SYS_LOAD_ADDR;
|
|
|
|
volumes[1].vol_id = CONFIG_SPL_UBI_LOAD_ARGS_ID;
|
|
|
|
volumes[1].load_addr = (void *)CONFIG_SYS_SPL_ARGS_ADDR;
|
|
|
|
|
|
|
|
ret = ubispl_load_volumes(&info, volumes, 2);
|
|
|
|
if (!ret) {
|
|
|
|
header = (struct image_header *)volumes[0].load_addr;
|
2016-09-25 00:20:13 +00:00
|
|
|
spl_parse_image_header(spl_image, header);
|
2016-07-12 18:28:13 +00:00
|
|
|
puts("Linux loaded.\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
puts("Loading Linux failed, falling back to U-Boot.\n");
|
|
|
|
}
|
|
|
|
#endif
|
2018-08-14 09:27:02 +00:00
|
|
|
header = spl_get_load_buffer(-sizeof(*header), sizeof(header));
|
2019-05-15 13:15:59 +00:00
|
|
|
#ifdef CONFIG_SPL_UBI_LOAD_BY_VOLNAME
|
|
|
|
volumes[0].vol_id = -1;
|
|
|
|
strncpy(volumes[0].name,
|
|
|
|
CONFIG_SPL_UBI_LOAD_MONITOR_VOLNAME,
|
|
|
|
UBI_VOL_NAME_MAX + 1);
|
|
|
|
#else
|
2016-07-12 18:28:13 +00:00
|
|
|
volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_MONITOR_ID;
|
2019-05-15 13:15:59 +00:00
|
|
|
#endif
|
2016-07-12 18:28:13 +00:00
|
|
|
volumes[0].load_addr = (void *)header;
|
|
|
|
|
|
|
|
ret = ubispl_load_volumes(&info, volumes, 1);
|
|
|
|
if (!ret)
|
2016-09-25 00:20:13 +00:00
|
|
|
spl_parse_image_header(spl_image, header);
|
2016-07-12 18:28:13 +00:00
|
|
|
out:
|
|
|
|
#ifdef CONFIG_SPL_NAND_SUPPORT
|
2016-09-25 00:19:57 +00:00
|
|
|
if (bootdev->boot_device == BOOT_DEVICE_NAND)
|
2016-07-12 18:28:13 +00:00
|
|
|
nand_deselect();
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
2016-09-25 00:20:01 +00:00
|
|
|
/* Use priorty 0 so that Ubi will override NAND and ONENAND methods */
|
2016-11-30 22:30:50 +00:00
|
|
|
SPL_LOAD_IMAGE_METHOD("NAND", 0, BOOT_DEVICE_NAND, spl_ubi_load_image);
|
|
|
|
SPL_LOAD_IMAGE_METHOD("OneNAND", 0, BOOT_DEVICE_ONENAND, spl_ubi_load_image);
|