spl_opensbi.c 2.1 KB

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