efi_root_node.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_loader.h>
  10. const efi_guid_t efi_u_boot_guid = U_BOOT_GUID;
  11. struct efi_root_dp {
  12. struct efi_device_path_vendor vendor;
  13. struct efi_device_path end;
  14. } __packed;
  15. /**
  16. * efi_root_node_register() - create root node
  17. *
  18. * Create the root node on which we install all protocols that are
  19. * not related to a loaded image or a driver.
  20. *
  21. * Return: status code
  22. */
  23. efi_status_t efi_root_node_register(void)
  24. {
  25. efi_handle_t root;
  26. efi_status_t ret;
  27. struct efi_root_dp *dp;
  28. /* Create handle */
  29. ret = efi_create_handle(&root);
  30. if (ret != EFI_SUCCESS)
  31. return ret;
  32. /* Install device path protocol */
  33. dp = calloc(1, sizeof(*dp));
  34. if (!dp)
  35. return EFI_OUT_OF_RESOURCES;
  36. /* Fill vendor node */
  37. dp->vendor.dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
  38. dp->vendor.dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
  39. dp->vendor.dp.length = sizeof(struct efi_device_path_vendor);
  40. dp->vendor.guid = efi_u_boot_guid;
  41. /* Fill end node */
  42. dp->end.type = DEVICE_PATH_TYPE_END;
  43. dp->end.sub_type = DEVICE_PATH_SUB_TYPE_END;
  44. dp->end.length = sizeof(struct efi_device_path);
  45. /* Install device path protocol */
  46. ret = efi_add_protocol(root, &efi_guid_device_path, dp);
  47. if (ret != EFI_SUCCESS)
  48. goto failure;
  49. /* Install device path to text protocol */
  50. ret = efi_add_protocol(root, &efi_guid_device_path_to_text_protocol,
  51. (void *)&efi_device_path_to_text);
  52. if (ret != EFI_SUCCESS)
  53. goto failure;
  54. /* Install device path utilities protocol */
  55. ret = efi_add_protocol(root, &efi_guid_device_path_utilities_protocol,
  56. (void *)&efi_device_path_utilities);
  57. if (ret != EFI_SUCCESS)
  58. goto failure;
  59. /* Install Unicode collation protocol */
  60. ret = efi_add_protocol(root, &efi_guid_unicode_collation_protocol,
  61. (void *)&efi_unicode_collation_protocol);
  62. if (ret != EFI_SUCCESS)
  63. goto failure;
  64. failure:
  65. return ret;
  66. }