efi_root_node.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Root node for system services
  4. *
  5. * Copyright (c) 2018 Heinrich Schuchardt
  6. */
  7. #include <common.h>
  8. #include <malloc.h>
  9. #include <efi_dt_fixup.h>
  10. #include <efi_loader.h>
  11. const efi_guid_t efi_u_boot_guid = U_BOOT_GUID;
  12. efi_handle_t efi_root = NULL;
  13. struct efi_root_dp {
  14. struct efi_device_path_vendor vendor;
  15. struct efi_device_path end;
  16. } __packed;
  17. /**
  18. * efi_root_node_register() - create root node
  19. *
  20. * Create the root node on which we install all protocols that are
  21. * not related to a loaded image or a driver.
  22. *
  23. * Return: status code
  24. */
  25. efi_status_t efi_root_node_register(void)
  26. {
  27. efi_status_t ret;
  28. struct efi_root_dp *dp;
  29. /* Create device path protocol */
  30. dp = calloc(1, sizeof(*dp));
  31. if (!dp)
  32. return EFI_OUT_OF_RESOURCES;
  33. /* Fill vendor node */
  34. dp->vendor.dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
  35. dp->vendor.dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
  36. dp->vendor.dp.length = sizeof(struct efi_device_path_vendor);
  37. dp->vendor.guid = efi_u_boot_guid;
  38. /* Fill end node */
  39. dp->end.type = DEVICE_PATH_TYPE_END;
  40. dp->end.sub_type = DEVICE_PATH_SUB_TYPE_END;
  41. dp->end.length = sizeof(struct efi_device_path);
  42. /* Create root node and install protocols */
  43. ret = EFI_CALL(efi_install_multiple_protocol_interfaces
  44. (&efi_root,
  45. /* Device path protocol */
  46. &efi_guid_device_path, dp,
  47. #if CONFIG_IS_ENABLED(EFI_DEVICE_PATH_TO_TEXT)
  48. /* Device path to text protocol */
  49. &efi_guid_device_path_to_text_protocol,
  50. (void *)&efi_device_path_to_text,
  51. #endif
  52. #ifdef CONFIG_EFI_DEVICE_PATH_UTIL
  53. /* Device path utilities protocol */
  54. &efi_guid_device_path_utilities_protocol,
  55. (void *)&efi_device_path_utilities,
  56. #endif
  57. #ifdef CONFIG_EFI_DT_FIXUP
  58. /* Device-tree fix-up protocol */
  59. &efi_guid_dt_fixup_protocol,
  60. (void *)&efi_dt_fixup_prot,
  61. #endif
  62. #if CONFIG_IS_ENABLED(EFI_UNICODE_COLLATION_PROTOCOL2)
  63. &efi_guid_unicode_collation_protocol2,
  64. (void *)&efi_unicode_collation_protocol2,
  65. #endif
  66. #if CONFIG_IS_ENABLED(EFI_LOADER_HII)
  67. /* HII string protocol */
  68. &efi_guid_hii_string_protocol,
  69. (void *)&efi_hii_string,
  70. /* HII database protocol */
  71. &efi_guid_hii_database_protocol,
  72. (void *)&efi_hii_database,
  73. #endif
  74. NULL));
  75. efi_root->type = EFI_OBJECT_TYPE_U_BOOT_FIRMWARE;
  76. return ret;
  77. }