FvbInfo.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*++ @file
  2. Defines data structure that is the volume header found.These data is intent
  3. to decouple FVB driver with FV header.
  4. Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
  5. Portions copyright (c) 2011, Apple Inc. All rights reserved.
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include <PiDxe.h>
  9. #include <Guid/EventGroup.h>
  10. #include <Guid/FirmwareFileSystem2.h>
  11. #include <Guid/SystemNvDataGuid.h>
  12. #include <Protocol/FirmwareVolumeBlock.h>
  13. #include <Protocol/DevicePath.h>
  14. #include <Library/UefiLib.h>
  15. #include <Library/UefiDriverEntryPoint.h>
  16. #include <Library/BaseLib.h>
  17. #include <Library/DxeServicesTableLib.h>
  18. #include <Library/UefiRuntimeLib.h>
  19. #include <Library/DebugLib.h>
  20. #include <Library/HobLib.h>
  21. #include <Library/BaseMemoryLib.h>
  22. #include <Library/MemoryAllocationLib.h>
  23. #include <Library/UefiBootServicesTableLib.h>
  24. #include <Library/PcdLib.h>
  25. #include <Library/DevicePathLib.h>
  26. typedef struct {
  27. UINT64 FvLength;
  28. EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
  29. //
  30. // EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0
  31. //
  32. EFI_FV_BLOCK_MAP_ENTRY End[1];
  33. } EFI_FVB_MEDIA_INFO;
  34. EFI_FVB_MEDIA_INFO mPlatformFvbMediaInfo[] = {
  35. //
  36. // Recovery BOIS FVB
  37. //
  38. {
  39. FixedPcdGet32 (PcdEmuFlashFvRecoverySize),
  40. {
  41. {
  42. 0,
  43. }, // ZeroVector[16]
  44. EFI_FIRMWARE_FILE_SYSTEM2_GUID,
  45. FixedPcdGet32 (PcdEmuFlashFvRecoverySize),
  46. EFI_FVH_SIGNATURE,
  47. EFI_FVB2_READ_ENABLED_CAP |
  48. EFI_FVB2_READ_STATUS |
  49. EFI_FVB2_WRITE_ENABLED_CAP |
  50. EFI_FVB2_WRITE_STATUS |
  51. EFI_FVB2_ERASE_POLARITY,
  52. sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
  53. 0, // CheckSum
  54. 0, // ExtHeaderOffset
  55. {
  56. 0,
  57. }, // Reserved[1]
  58. 2, // Revision
  59. {
  60. {
  61. FixedPcdGet32 (PcdEmuFlashFvRecoverySize)/FixedPcdGet32 (PcdEmuFirmwareBlockSize),
  62. FixedPcdGet32 (PcdEmuFirmwareBlockSize),
  63. }
  64. }
  65. },
  66. {
  67. {
  68. 0,
  69. 0
  70. }
  71. }
  72. },
  73. //
  74. // Systen NvStorage FVB
  75. //
  76. {
  77. FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
  78. FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
  79. FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
  80. FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize),
  81. {
  82. {
  83. 0,
  84. }, // ZeroVector[16]
  85. EFI_SYSTEM_NV_DATA_FV_GUID,
  86. FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
  87. FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
  88. FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
  89. FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize),
  90. EFI_FVH_SIGNATURE,
  91. EFI_FVB2_READ_ENABLED_CAP |
  92. EFI_FVB2_READ_STATUS |
  93. EFI_FVB2_WRITE_ENABLED_CAP |
  94. EFI_FVB2_WRITE_STATUS |
  95. EFI_FVB2_ERASE_POLARITY,
  96. sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
  97. 0, // CheckSum
  98. 0, // ExtHeaderOffset
  99. {
  100. 0,
  101. }, // Reserved[1]
  102. 2, // Revision
  103. {
  104. {
  105. (FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
  106. FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
  107. FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
  108. FixedPcdGet32 (PcdEmuFlashNvStorageEventLogSize)) / FixedPcdGet32 (PcdEmuFirmwareBlockSize),
  109. FixedPcdGet32 (PcdEmuFirmwareBlockSize),
  110. }
  111. }
  112. },
  113. {
  114. {
  115. 0,
  116. 0
  117. }
  118. }
  119. }
  120. };
  121. EFI_STATUS
  122. GetFvbInfo (
  123. IN UINT64 FvLength,
  124. OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
  125. )
  126. {
  127. UINTN Index;
  128. for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) {
  129. if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {
  130. *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;
  131. return EFI_SUCCESS;
  132. }
  133. }
  134. return EFI_NOT_FOUND;
  135. }