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 DECLARE_GLOBAL_DATA_PTR;
16 struct fw_dynamic_info opensbi_info;
18 static int spl_opensbi_find_uboot_node(void *blob, int *uboot_node)
20 int fit_images_node, node;
23 fit_images_node = fdt_path_offset(blob, "/fit-images");
24 if (fit_images_node < 0)
27 fdt_for_each_subnode(node, blob, fit_images_node) {
28 fit_os = fdt_getprop(blob, node, FIT_OS_PROP, NULL);
32 if (genimg_get_os_id(fit_os) == IH_OS_U_BOOT) {
41 void spl_invoke_opensbi(struct spl_image_info *spl_image)
45 void (*opensbi_entry)(ulong hartid, ulong dtb, ulong info);
47 if (!spl_image->fdt_addr) {
48 pr_err("No device tree specified in SPL image\n");
52 /* Find U-Boot image in /fit-images */
53 ret = spl_opensbi_find_uboot_node(spl_image->fdt_addr, &uboot_node);
55 pr_err("Can't find U-Boot node, %d", ret);
59 /* Get U-Boot entry point */
60 uboot_entry = fdt_getprop_u32(spl_image->fdt_addr, uboot_node,
62 if (uboot_entry == FDT_ERROR)
63 uboot_entry = fdt_getprop_u32(spl_image->fdt_addr, uboot_node,
66 /* Prepare obensbi_info object */
67 opensbi_info.magic = FW_DYNAMIC_INFO_MAGIC_VALUE;
68 opensbi_info.version = FW_DYNAMIC_INFO_VERSION;
69 opensbi_info.next_addr = uboot_entry;
70 opensbi_info.next_mode = FW_DYNAMIC_INFO_NEXT_MODE_S;
71 opensbi_info.options = SBI_SCRATCH_NO_BOOT_PRINTS;
73 opensbi_entry = (void (*)(ulong, ulong, ulong))spl_image->entry_point;
74 invalidate_icache_all();
77 ret = smp_call_function((ulong)spl_image->entry_point,
78 (ulong)spl_image->fdt_addr,
79 (ulong)&opensbi_info);
83 opensbi_entry(gd->arch.boot_hart, (ulong)spl_image->fdt_addr,
84 (ulong)&opensbi_info);