Logo.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /** @file
  2. Logo DXE Driver, install Edkii Platform Logo protocol.
  3. Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Uefi.h>
  7. #include <Protocol/HiiDatabase.h>
  8. #include <Protocol/GraphicsOutput.h>
  9. #include <Protocol/HiiImageEx.h>
  10. #include <Protocol/PlatformLogo.h>
  11. #include <Protocol/HiiPackageList.h>
  12. #include <Library/UefiBootServicesTableLib.h>
  13. #include <Library/DebugLib.h>
  14. typedef struct {
  15. EFI_IMAGE_ID ImageId;
  16. EDKII_PLATFORM_LOGO_DISPLAY_ATTRIBUTE Attribute;
  17. INTN OffsetX;
  18. INTN OffsetY;
  19. } LOGO_ENTRY;
  20. EFI_HII_IMAGE_EX_PROTOCOL *mHiiImageEx;
  21. EFI_HII_HANDLE mHiiHandle;
  22. LOGO_ENTRY mLogos[] = {
  23. {
  24. IMAGE_TOKEN (IMG_LOGO),
  25. EdkiiPlatformLogoDisplayAttributeCenter,
  26. 0,
  27. 0
  28. }
  29. };
  30. /**
  31. Load a platform logo image and return its data and attributes.
  32. @param This The pointer to this protocol instance.
  33. @param Instance The visible image instance is found.
  34. @param Image Points to the image.
  35. @param Attribute The display attributes of the image returned.
  36. @param OffsetX The X offset of the image regarding the Attribute.
  37. @param OffsetY The Y offset of the image regarding the Attribute.
  38. @retval EFI_SUCCESS The image was fetched successfully.
  39. @retval EFI_NOT_FOUND The specified image could not be found.
  40. **/
  41. EFI_STATUS
  42. EFIAPI
  43. GetImage (
  44. IN EDKII_PLATFORM_LOGO_PROTOCOL *This,
  45. IN OUT UINT32 *Instance,
  46. OUT EFI_IMAGE_INPUT *Image,
  47. OUT EDKII_PLATFORM_LOGO_DISPLAY_ATTRIBUTE *Attribute,
  48. OUT INTN *OffsetX,
  49. OUT INTN *OffsetY
  50. )
  51. {
  52. UINT32 Current;
  53. if ((Instance == NULL) || (Image == NULL) ||
  54. (Attribute == NULL) || (OffsetX == NULL) || (OffsetY == NULL))
  55. {
  56. return EFI_INVALID_PARAMETER;
  57. }
  58. Current = *Instance;
  59. if (Current >= ARRAY_SIZE (mLogos)) {
  60. return EFI_NOT_FOUND;
  61. }
  62. (*Instance)++;
  63. *Attribute = mLogos[Current].Attribute;
  64. *OffsetX = mLogos[Current].OffsetX;
  65. *OffsetY = mLogos[Current].OffsetY;
  66. return mHiiImageEx->GetImageEx (mHiiImageEx, mHiiHandle, mLogos[Current].ImageId, Image);
  67. }
  68. EDKII_PLATFORM_LOGO_PROTOCOL mPlatformLogo = {
  69. GetImage
  70. };
  71. /**
  72. Entrypoint of this module.
  73. This function is the entrypoint of this module. It installs the Edkii
  74. Platform Logo protocol.
  75. @param ImageHandle The firmware allocated handle for the EFI image.
  76. @param SystemTable A pointer to the EFI System Table.
  77. @retval EFI_SUCCESS The entry point is executed successfully.
  78. **/
  79. EFI_STATUS
  80. EFIAPI
  81. InitializeLogo (
  82. IN EFI_HANDLE ImageHandle,
  83. IN EFI_SYSTEM_TABLE *SystemTable
  84. )
  85. {
  86. EFI_STATUS Status;
  87. EFI_HII_PACKAGE_LIST_HEADER *PackageList;
  88. EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
  89. EFI_HANDLE Handle;
  90. Status = gBS->LocateProtocol (
  91. &gEfiHiiDatabaseProtocolGuid,
  92. NULL,
  93. (VOID **)&HiiDatabase
  94. );
  95. ASSERT_EFI_ERROR (Status);
  96. Status = gBS->LocateProtocol (
  97. &gEfiHiiImageExProtocolGuid,
  98. NULL,
  99. (VOID **)&mHiiImageEx
  100. );
  101. ASSERT_EFI_ERROR (Status);
  102. //
  103. // Retrieve HII package list from ImageHandle
  104. //
  105. Status = gBS->OpenProtocol (
  106. ImageHandle,
  107. &gEfiHiiPackageListProtocolGuid,
  108. (VOID **)&PackageList,
  109. ImageHandle,
  110. NULL,
  111. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  112. );
  113. if (EFI_ERROR (Status)) {
  114. DEBUG ((DEBUG_ERROR, "HII Image Package with logo not found in PE/COFF resource section\n"));
  115. return Status;
  116. }
  117. //
  118. // Publish HII package list to HII Database.
  119. //
  120. Status = HiiDatabase->NewPackageList (
  121. HiiDatabase,
  122. PackageList,
  123. NULL,
  124. &mHiiHandle
  125. );
  126. if (!EFI_ERROR (Status)) {
  127. Handle = NULL;
  128. Status = gBS->InstallMultipleProtocolInterfaces (
  129. &Handle,
  130. &gEdkiiPlatformLogoProtocolGuid,
  131. &mPlatformLogo,
  132. NULL
  133. );
  134. }
  135. return Status;
  136. }