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
15 DECLARE_GLOBAL_DATA_PTR;
17 struct fw_dynamic_info opensbi_info;
19 static int spl_opensbi_find_uboot_node(void *blob, int *uboot_node)
21 int fit_images_node, node;
24 fit_images_node = fdt_path_offset(blob, "/fit-images");
25 if (fit_images_node < 0)
28 fdt_for_each_subnode(node, blob, fit_images_node) {
29 fit_os = fdt_getprop(blob, node, FIT_OS_PROP, NULL);
33 if (genimg_get_os_id(fit_os) == IH_OS_U_BOOT) {
42 void spl_invoke_opensbi(struct spl_image_info *spl_image)
46 void (*opensbi_entry)(ulong hartid, ulong dtb, ulong info);
48 if (!spl_image->fdt_addr) {
49 pr_err("No device tree specified in SPL image\n");
53 /* Find U-Boot image in /fit-images */
54 ret = spl_opensbi_find_uboot_node(spl_image->fdt_addr, &uboot_node);
56 pr_err("Can't find U-Boot node, %d", ret);
60 /* Get U-Boot entry point */
61 uboot_entry = fdt_getprop_u32(spl_image->fdt_addr, uboot_node,
63 if (uboot_entry == FDT_ERROR)
64 uboot_entry = fdt_getprop_u32(spl_image->fdt_addr, uboot_node,
67 /* Prepare obensbi_info object */
68 opensbi_info.magic = FW_DYNAMIC_INFO_MAGIC_VALUE;
69 opensbi_info.version = FW_DYNAMIC_INFO_VERSION;
70 opensbi_info.next_addr = uboot_entry;
71 opensbi_info.next_mode = FW_DYNAMIC_INFO_NEXT_MODE_S;
72 opensbi_info.options = SBI_SCRATCH_NO_BOOT_PRINTS;
73 opensbi_info.boot_hart = gd->arch.boot_hart;
75 opensbi_entry = (void (*)(ulong, ulong, ulong))spl_image->entry_point;
76 invalidate_icache_all();
80 * Start OpenSBI on all secondary harts and wait for acknowledgment.
82 * OpenSBI first relocates itself to its link address. This is done by
83 * the main hart. To make sure no hart is still running U-Boot SPL
84 * during relocation, we wait for all secondary harts to acknowledge
85 * the call-function request before entering OpenSBI on the main hart.
86 * Otherwise, code corruption can occur if the link address ranges of
87 * U-Boot SPL and OpenSBI overlap.
89 ret = smp_call_function((ulong)spl_image->entry_point,
90 (ulong)spl_image->fdt_addr,
91 (ulong)&opensbi_info, 1);
95 opensbi_entry(gd->arch.boot_hart, (ulong)spl_image->fdt_addr,
96 (ulong)&opensbi_info);