spl_opensbi.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // 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>
  9. #include <cpu_func.h>
  10. #include <errno.h>
  11. #include <spl.h>
  12. #include <asm/smp.h>
  13. #include <opensbi.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. struct fw_dynamic_info opensbi_info;
  16. static int spl_opensbi_find_uboot_node(void *blob, int *uboot_node)
  17. {
  18. int fit_images_node, node;
  19. const char *fit_os;
  20. fit_images_node = fdt_path_offset(blob, "/fit-images");
  21. if (fit_images_node < 0)
  22. return -ENODEV;
  23. fdt_for_each_subnode(node, blob, fit_images_node) {
  24. fit_os = fdt_getprop(blob, node, FIT_OS_PROP, NULL);
  25. if (!fit_os)
  26. continue;
  27. if (genimg_get_os_id(fit_os) == IH_OS_U_BOOT) {
  28. *uboot_node = node;
  29. return 0;
  30. }
  31. }
  32. return -ENODEV;
  33. }
  34. void spl_invoke_opensbi(struct spl_image_info *spl_image)
  35. {
  36. int ret, uboot_node;
  37. ulong uboot_entry;
  38. void (*opensbi_entry)(ulong hartid, ulong dtb, ulong info);
  39. if (!spl_image->fdt_addr) {
  40. pr_err("No device tree specified in SPL image\n");
  41. hang();
  42. }
  43. /* Find U-Boot image in /fit-images */
  44. ret = spl_opensbi_find_uboot_node(spl_image->fdt_addr, &uboot_node);
  45. if (ret) {
  46. pr_err("Can't find U-Boot node, %d", ret);
  47. hang();
  48. }
  49. /* Get U-Boot entry point */
  50. uboot_entry = fdt_getprop_u32(spl_image->fdt_addr, uboot_node,
  51. "entry-point");
  52. if (uboot_entry == FDT_ERROR)
  53. uboot_entry = fdt_getprop_u32(spl_image->fdt_addr, uboot_node,
  54. "load-addr");
  55. /* Prepare obensbi_info object */
  56. opensbi_info.magic = FW_DYNAMIC_INFO_MAGIC_VALUE;
  57. opensbi_info.version = FW_DYNAMIC_INFO_VERSION;
  58. opensbi_info.next_addr = uboot_entry;
  59. opensbi_info.next_mode = FW_DYNAMIC_INFO_NEXT_MODE_S;
  60. opensbi_info.options = SBI_SCRATCH_NO_BOOT_PRINTS;
  61. opensbi_info.boot_hart = gd->arch.boot_hart;
  62. opensbi_entry = (void (*)(ulong, ulong, ulong))spl_image->entry_point;
  63. invalidate_icache_all();
  64. #ifdef CONFIG_SMP
  65. ret = smp_call_function((ulong)spl_image->entry_point,
  66. (ulong)spl_image->fdt_addr,
  67. (ulong)&opensbi_info);
  68. if (ret)
  69. hang();
  70. #endif
  71. opensbi_entry(gd->arch.boot_hart, (ulong)spl_image->fdt_addr,
  72. (ulong)&opensbi_info);
  73. }