blob: 2345f949f05b48d86b2e51d844ffe6138afe253a [file] [log] [blame]
Lukas Auer5e30e452019-08-21 21:14:44 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019 Fraunhofer AISEC,
4 * Lukas Auer <lukas.auer@aisec.fraunhofer.de>
5 *
6 * Based on common/spl/spl_atf.c
7 */
8#include <common.h>
Simon Glass1eb69ae2019-11-14 12:57:39 -07009#include <cpu_func.h>
Lukas Auer5e30e452019-08-21 21:14:44 +020010#include <errno.h>
11#include <spl.h>
12#include <asm/smp.h>
13#include <opensbi.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17struct fw_dynamic_info opensbi_info;
18
19static int spl_opensbi_find_uboot_node(void *blob, int *uboot_node)
20{
21 int fit_images_node, node;
22 const char *fit_os;
23
24 fit_images_node = fdt_path_offset(blob, "/fit-images");
25 if (fit_images_node < 0)
26 return -ENODEV;
27
28 fdt_for_each_subnode(node, blob, fit_images_node) {
29 fit_os = fdt_getprop(blob, node, FIT_OS_PROP, NULL);
30 if (!fit_os)
31 continue;
32
33 if (genimg_get_os_id(fit_os) == IH_OS_U_BOOT) {
34 *uboot_node = node;
35 return 0;
36 }
37 }
38
39 return -ENODEV;
40}
41
42void spl_invoke_opensbi(struct spl_image_info *spl_image)
43{
44 int ret, uboot_node;
45 ulong uboot_entry;
46 void (*opensbi_entry)(ulong hartid, ulong dtb, ulong info);
47
48 if (!spl_image->fdt_addr) {
49 pr_err("No device tree specified in SPL image\n");
50 hang();
51 }
52
53 /* Find U-Boot image in /fit-images */
54 ret = spl_opensbi_find_uboot_node(spl_image->fdt_addr, &uboot_node);
55 if (ret) {
56 pr_err("Can't find U-Boot node, %d", ret);
57 hang();
58 }
59
60 /* Get U-Boot entry point */
61 uboot_entry = fdt_getprop_u32(spl_image->fdt_addr, uboot_node,
62 "entry-point");
63 if (uboot_entry == FDT_ERROR)
64 uboot_entry = fdt_getprop_u32(spl_image->fdt_addr, uboot_node,
65 "load-addr");
66
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
74 opensbi_entry = (void (*)(ulong, ulong, ulong))spl_image->entry_point;
75 invalidate_icache_all();
76
77#ifdef CONFIG_SMP
78 ret = smp_call_function((ulong)spl_image->entry_point,
79 (ulong)spl_image->fdt_addr,
80 (ulong)&opensbi_info);
81 if (ret)
82 hang();
83#endif
84 opensbi_entry(gd->arch.boot_hart, (ulong)spl_image->fdt_addr,
85 (ulong)&opensbi_info);
86}