2019-08-21 19:14:44 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Fraunhofer AISEC,
|
|
|
|
* Lukas Auer <lukas.auer@aisec.fraunhofer.de>
|
|
|
|
*
|
|
|
|
* Based on common/spl/spl_atf.c
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2019-08-21 19:14:44 +00:00
|
|
|
#include <errno.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <image.h>
|
2019-08-21 19:14:44 +00:00
|
|
|
#include <spl.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2019-08-21 19:14:44 +00:00
|
|
|
#include <asm/smp.h>
|
|
|
|
#include <opensbi.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <linux/libfdt.h>
|
2023-09-15 00:21:46 +00:00
|
|
|
#include <linux/printk.h>
|
2019-08-21 19:14:44 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
struct fw_dynamic_info opensbi_info;
|
|
|
|
|
2023-10-12 06:35:03 +00:00
|
|
|
static int spl_opensbi_find_os_node(void *blob, int *uboot_node, int os_type)
|
2019-08-21 19:14:44 +00:00
|
|
|
{
|
|
|
|
int fit_images_node, node;
|
|
|
|
const char *fit_os;
|
|
|
|
|
|
|
|
fit_images_node = fdt_path_offset(blob, "/fit-images");
|
|
|
|
if (fit_images_node < 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
fdt_for_each_subnode(node, blob, fit_images_node) {
|
|
|
|
fit_os = fdt_getprop(blob, node, FIT_OS_PROP, NULL);
|
|
|
|
if (!fit_os)
|
|
|
|
continue;
|
|
|
|
|
2023-10-12 06:35:03 +00:00
|
|
|
if (genimg_get_os_id(fit_os) == os_type) {
|
2019-08-21 19:14:44 +00:00
|
|
|
*uboot_node = node;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2023-08-29 01:20:14 +00:00
|
|
|
void __noreturn spl_invoke_opensbi(struct spl_image_info *spl_image)
|
2019-08-21 19:14:44 +00:00
|
|
|
{
|
2023-10-12 06:35:03 +00:00
|
|
|
int ret, os_node;
|
|
|
|
ulong os_entry;
|
|
|
|
int os_type;
|
2023-08-29 01:20:14 +00:00
|
|
|
typedef void __noreturn (*opensbi_entry_t)(ulong hartid, ulong dtb, ulong info);
|
|
|
|
opensbi_entry_t opensbi_entry;
|
2019-08-21 19:14:44 +00:00
|
|
|
|
|
|
|
if (!spl_image->fdt_addr) {
|
|
|
|
pr_err("No device tree specified in SPL image\n");
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
2023-10-12 06:35:03 +00:00
|
|
|
/*
|
|
|
|
* Find next os image in /fit-images
|
2023-10-12 06:35:07 +00:00
|
|
|
* The next os image default is u-boot proper, once enable
|
|
|
|
* OpenSBI OS boot mode, the OS image should be linux.
|
2023-10-12 06:35:03 +00:00
|
|
|
*/
|
2023-10-12 06:35:07 +00:00
|
|
|
if (CONFIG_IS_ENABLED(LOAD_FIT_OPENSBI_OS_BOOT))
|
|
|
|
os_type = IH_OS_LINUX;
|
|
|
|
else
|
|
|
|
os_type = IH_OS_U_BOOT;
|
|
|
|
|
2023-10-12 06:35:03 +00:00
|
|
|
ret = spl_opensbi_find_os_node(spl_image->fdt_addr, &os_node, os_type);
|
2019-08-21 19:14:44 +00:00
|
|
|
if (ret) {
|
2023-10-12 06:35:03 +00:00
|
|
|
pr_err("Can't find %s node for opensbi, %d\n",
|
|
|
|
genimg_get_os_name(os_type), ret);
|
2019-08-21 19:14:44 +00:00
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get U-Boot entry point */
|
2023-10-12 06:35:03 +00:00
|
|
|
ret = fit_image_get_entry(spl_image->fdt_addr, os_node, &os_entry);
|
2020-09-03 09:24:28 +00:00
|
|
|
if (ret)
|
2023-10-12 06:35:03 +00:00
|
|
|
ret = fit_image_get_load(spl_image->fdt_addr, os_node, &os_entry);
|
2019-08-21 19:14:44 +00:00
|
|
|
|
2022-08-08 10:24:25 +00:00
|
|
|
/* Prepare opensbi_info object */
|
2019-08-21 19:14:44 +00:00
|
|
|
opensbi_info.magic = FW_DYNAMIC_INFO_MAGIC_VALUE;
|
|
|
|
opensbi_info.version = FW_DYNAMIC_INFO_VERSION;
|
2023-10-12 06:35:03 +00:00
|
|
|
opensbi_info.next_addr = os_entry;
|
2019-08-21 19:14:44 +00:00
|
|
|
opensbi_info.next_mode = FW_DYNAMIC_INFO_NEXT_MODE_S;
|
2022-08-08 10:28:52 +00:00
|
|
|
opensbi_info.options = CONFIG_SPL_OPENSBI_SCRATCH_OPTIONS;
|
2019-12-08 22:28:49 +00:00
|
|
|
opensbi_info.boot_hart = gd->arch.boot_hart;
|
2019-08-21 19:14:44 +00:00
|
|
|
|
2023-08-29 01:20:14 +00:00
|
|
|
opensbi_entry = (opensbi_entry_t)spl_image->entry_point;
|
2019-08-21 19:14:44 +00:00
|
|
|
invalidate_icache_all();
|
|
|
|
|
2020-04-16 15:09:30 +00:00
|
|
|
#ifdef CONFIG_SPL_SMP
|
2019-12-08 22:28:52 +00:00
|
|
|
/*
|
|
|
|
* Start OpenSBI on all secondary harts and wait for acknowledgment.
|
|
|
|
*
|
|
|
|
* OpenSBI first relocates itself to its link address. This is done by
|
|
|
|
* the main hart. To make sure no hart is still running U-Boot SPL
|
|
|
|
* during relocation, we wait for all secondary harts to acknowledge
|
|
|
|
* the call-function request before entering OpenSBI on the main hart.
|
|
|
|
* Otherwise, code corruption can occur if the link address ranges of
|
|
|
|
* U-Boot SPL and OpenSBI overlap.
|
|
|
|
*/
|
2019-08-21 19:14:44 +00:00
|
|
|
ret = smp_call_function((ulong)spl_image->entry_point,
|
|
|
|
(ulong)spl_image->fdt_addr,
|
2019-12-08 22:28:52 +00:00
|
|
|
(ulong)&opensbi_info, 1);
|
2019-08-21 19:14:44 +00:00
|
|
|
if (ret)
|
|
|
|
hang();
|
|
|
|
#endif
|
|
|
|
opensbi_entry(gd->arch.boot_hart, (ulong)spl_image->fdt_addr,
|
|
|
|
(ulong)&opensbi_info);
|
|
|
|
}
|