Logo.c 4.3 KB

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