1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019 Fraunhofer AISEC,
4 * Lukas Auer <lukas.auer@aisec.fraunhofer.de>
6 * Based on common/spl/spl_atf.c
14 #include <asm/global_data.h>
17 #include <linux/libfdt.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 struct fw_dynamic_info opensbi_info;
23 static int spl_opensbi_find_uboot_node(void *blob, int *uboot_node)
25 int fit_images_node, node;
28 fit_images_node = fdt_path_offset(blob, "/fit-images");
29 if (fit_images_node < 0)
32 fdt_for_each_subnode(node, blob, fit_images_node) {
33 fit_os = fdt_getprop(blob, node, FIT_OS_PROP, NULL);
37 if (genimg_get_os_id(fit_os) == IH_OS_U_BOOT) {
46 void spl_invoke_opensbi(struct spl_image_info *spl_image)
50 void (*opensbi_entry)(ulong hartid, ulong dtb, ulong info);
52 if (!spl_image->fdt_addr) {
53 pr_err("No device tree specified in SPL image\n");
57 /* Find U-Boot image in /fit-images */
58 ret = spl_opensbi_find_uboot_node(spl_image->fdt_addr, &uboot_node);
60 pr_err("Can't find U-Boot node, %d\n", ret);
64 /* Get U-Boot entry point */
65 ret = fit_image_get_entry(spl_image->fdt_addr, uboot_node, &uboot_entry);
67 ret = fit_image_get_load(spl_image->fdt_addr, uboot_node, &uboot_entry);
69 /* Prepare opensbi_info object */
70 opensbi_info.magic = FW_DYNAMIC_INFO_MAGIC_VALUE;
71 opensbi_info.version = FW_DYNAMIC_INFO_VERSION;
72 opensbi_info.next_addr = uboot_entry;
73 opensbi_info.next_mode = FW_DYNAMIC_INFO_NEXT_MODE_S;
74 opensbi_info.options = CONFIG_SPL_OPENSBI_SCRATCH_OPTIONS;
75 opensbi_info.boot_hart = gd->arch.boot_hart;
77 opensbi_entry = (void (*)(ulong, ulong, ulong))spl_image->entry_point;
78 invalidate_icache_all();
82 * Start OpenSBI on all secondary harts and wait for acknowledgment.
84 * OpenSBI first relocates itself to its link address. This is done by
85 * the main hart. To make sure no hart is still running U-Boot SPL
86 * during relocation, we wait for all secondary harts to acknowledge
87 * the call-function request before entering OpenSBI on the main hart.
88 * Otherwise, code corruption can occur if the link address ranges of
89 * U-Boot SPL and OpenSBI overlap.
91 ret = smp_call_function((ulong)spl_image->entry_point,
92 (ulong)spl_image->fdt_addr,
93 (ulong)&opensbi_info, 1);
97 opensbi_entry(gd->arch.boot_hart, (ulong)spl_image->fdt_addr,
98 (ulong)&opensbi_info);