mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-11 22:03:15 +00:00
04ce5427bd
The SPL loaders assume that the CONFIG_SYS_TEXT_BASE memory location is available and can be corrupted by loading ie. uImage or fitImage headers there. Sometimes it could be beneficial to load the headers elsewhere, ie. if CONFIG_SYS_TEXT_BASE is not yet writable while we still want to parse the image headers in some local onchip memory to ie. extract firmware from that image. Add the possibility to override the location where the headers get loaded by introducing new function, spl_get_load_buffer() which takes two arguments -- offset from the CONFIG_SYS_TEXT_BASE and size of the data that are to be loaded there -- and returns a valid buffer address or hangs the system. The default behavior is the same as before, add the offset to CONFIG_SYS_TEXT_BASE and return that address. User can override the weak spl_get_load_buffer() function though. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
80 lines
2.3 KiB
C
80 lines
2.3 KiB
C
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
|
|
/*
|
|
* Copyright (C) 2016
|
|
* Ladislav Michl <ladis@linux-mips.org>
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <config.h>
|
|
#include <nand.h>
|
|
#include <onenand_uboot.h>
|
|
#include <ubispl.h>
|
|
#include <spl.h>
|
|
|
|
int spl_ubi_load_image(struct spl_image_info *spl_image,
|
|
struct spl_boot_device *bootdev)
|
|
{
|
|
struct image_header *header;
|
|
struct ubispl_info info;
|
|
struct ubispl_load volumes[2];
|
|
int ret = 1;
|
|
|
|
switch (bootdev->boot_device) {
|
|
#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;
|
|
info.fastmap = IS_ENABLED(CONFIG_MTD_UBI_FASTMAP);
|
|
|
|
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;
|
|
|
|
#ifdef CONFIG_SPL_OS_BOOT
|
|
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;
|
|
spl_parse_image_header(spl_image, header);
|
|
puts("Linux loaded.\n");
|
|
goto out;
|
|
}
|
|
puts("Loading Linux failed, falling back to U-Boot.\n");
|
|
}
|
|
#endif
|
|
header = spl_get_load_buffer(-sizeof(*header), sizeof(header));
|
|
volumes[0].vol_id = CONFIG_SPL_UBI_LOAD_MONITOR_ID;
|
|
volumes[0].load_addr = (void *)header;
|
|
|
|
ret = ubispl_load_volumes(&info, volumes, 1);
|
|
if (!ret)
|
|
spl_parse_image_header(spl_image, header);
|
|
out:
|
|
#ifdef CONFIG_SPL_NAND_SUPPORT
|
|
if (bootdev->boot_device == BOOT_DEVICE_NAND)
|
|
nand_deselect();
|
|
#endif
|
|
return ret;
|
|
}
|
|
/* Use priorty 0 so that Ubi will override NAND and ONENAND methods */
|
|
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);
|