SecureBootConfigDriver.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /** @file
  2. The module entry point for SecureBoot configuration module.
  3. Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "SecureBootConfigImpl.h"
  7. /**
  8. The entry point for SecureBoot configuration driver.
  9. @param[in] ImageHandle The image handle of the driver.
  10. @param[in] SystemTable The system table.
  11. @retval EFI_ALREADY_STARTED The driver already exists in system.
  12. @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of resources.
  13. @retval EFI_SUCCESS All the related protocols are installed on the driver.
  14. @retval Others Fail to get the SecureBootEnable variable.
  15. **/
  16. EFI_STATUS
  17. EFIAPI
  18. SecureBootConfigDriverEntryPoint (
  19. IN EFI_HANDLE ImageHandle,
  20. IN EFI_SYSTEM_TABLE *SystemTable
  21. )
  22. {
  23. EFI_STATUS Status;
  24. SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData;
  25. //
  26. // If already started, return.
  27. //
  28. Status = gBS->OpenProtocol (
  29. ImageHandle,
  30. &gEfiCallerIdGuid,
  31. NULL,
  32. ImageHandle,
  33. ImageHandle,
  34. EFI_OPEN_PROTOCOL_TEST_PROTOCOL
  35. );
  36. if (!EFI_ERROR (Status)) {
  37. return EFI_ALREADY_STARTED;
  38. }
  39. //
  40. // Create a private data structure.
  41. //
  42. PrivateData = AllocateCopyPool (sizeof (SECUREBOOT_CONFIG_PRIVATE_DATA), &mSecureBootConfigPrivateDateTemplate);
  43. if (PrivateData == NULL) {
  44. return EFI_OUT_OF_RESOURCES;
  45. }
  46. //
  47. // Install SecureBoot configuration form
  48. //
  49. Status = InstallSecureBootConfigForm (PrivateData);
  50. if (EFI_ERROR (Status)) {
  51. goto ErrorExit;
  52. }
  53. //
  54. // Install private GUID.
  55. //
  56. Status = gBS->InstallMultipleProtocolInterfaces (
  57. &ImageHandle,
  58. &gEfiCallerIdGuid,
  59. PrivateData,
  60. NULL
  61. );
  62. if (EFI_ERROR (Status)) {
  63. goto ErrorExit;
  64. }
  65. return EFI_SUCCESS;
  66. ErrorExit:
  67. if (PrivateData != NULL) {
  68. UninstallSecureBootConfigForm (PrivateData);
  69. }
  70. return Status;
  71. }
  72. /**
  73. Unload the SecureBoot configuration form.
  74. @param[in] ImageHandle The driver's image handle.
  75. @retval EFI_SUCCESS The SecureBoot configuration form is unloaded.
  76. @retval Others Failed to unload the form.
  77. **/
  78. EFI_STATUS
  79. EFIAPI
  80. SecureBootConfigDriverUnload (
  81. IN EFI_HANDLE ImageHandle
  82. )
  83. {
  84. EFI_STATUS Status;
  85. SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData;
  86. Status = gBS->HandleProtocol (
  87. ImageHandle,
  88. &gEfiCallerIdGuid,
  89. (VOID **) &PrivateData
  90. );
  91. if (EFI_ERROR (Status)) {
  92. return Status;
  93. }
  94. ASSERT (PrivateData->Signature == SECUREBOOT_CONFIG_PRIVATE_DATA_SIGNATURE);
  95. gBS->UninstallMultipleProtocolInterfaces (
  96. ImageHandle,
  97. &gEfiCallerIdGuid,
  98. PrivateData,
  99. NULL
  100. );
  101. UninstallSecureBootConfigForm (PrivateData);
  102. return EFI_SUCCESS;
  103. }