FvbInfo.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**@file
  2. Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. FvbInfo.c
  6. Abstract:
  7. Defines data structure that is the volume header found.These data is intent
  8. to decouple FVB driver with FV header.
  9. **/
  10. //
  11. // The package level header files this module uses
  12. //
  13. #include <Pi/PiFirmwareVolume.h>
  14. //
  15. // The protocols, PPI and GUID definitions for this module
  16. //
  17. #include <Guid/SystemNvDataGuid.h>
  18. //
  19. // The Library classes this module consumes
  20. //
  21. #include <Library/BaseLib.h>
  22. #include <Library/PcdLib.h>
  23. typedef struct {
  24. UINT64 FvLength;
  25. EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
  26. //
  27. // EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0
  28. //
  29. EFI_FV_BLOCK_MAP_ENTRY End[1];
  30. } EFI_FVB_MEDIA_INFO;
  31. EFI_FVB_MEDIA_INFO mPlatformFvbMediaInfo[] = {
  32. //
  33. // System NvStorage FVB
  34. //
  35. {
  36. FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
  37. FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
  38. FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
  39. FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize),
  40. {
  41. {
  42. 0,
  43. }, // ZeroVector[16]
  44. EFI_SYSTEM_NV_DATA_FV_GUID,
  45. FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
  46. FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
  47. FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
  48. FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize),
  49. EFI_FVH_SIGNATURE,
  50. EFI_FVB2_MEMORY_MAPPED |
  51. EFI_FVB2_READ_ENABLED_CAP |
  52. EFI_FVB2_READ_STATUS |
  53. EFI_FVB2_WRITE_ENABLED_CAP |
  54. EFI_FVB2_WRITE_STATUS |
  55. EFI_FVB2_ERASE_POLARITY |
  56. EFI_FVB2_ALIGNMENT_16,
  57. sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
  58. 0, // CheckSum
  59. 0, // ExtHeaderOffset
  60. {
  61. 0,
  62. }, // Reserved[1]
  63. 2, // Revision
  64. {
  65. {
  66. (FixedPcdGet32 (PcdFlashNvStorageVariableSize) +
  67. FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
  68. FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) +
  69. FixedPcdGet32 (PcdOvmfFlashNvStorageEventLogSize)) /
  70. FixedPcdGet32 (PcdOvmfFirmwareBlockSize),
  71. FixedPcdGet32 (PcdOvmfFirmwareBlockSize),
  72. }
  73. } // BlockMap[1]
  74. },
  75. {
  76. {
  77. 0,
  78. 0
  79. }
  80. } // End[1]
  81. }
  82. };
  83. EFI_STATUS
  84. GetFvbInfo (
  85. IN UINT64 FvLength,
  86. OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
  87. )
  88. {
  89. STATIC BOOLEAN Checksummed = FALSE;
  90. UINTN Index;
  91. if (!Checksummed) {
  92. for (Index = 0;
  93. Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO);
  94. Index += 1)
  95. {
  96. UINT16 Checksum;
  97. mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = 0;
  98. Checksum = CalculateCheckSum16 (
  99. (UINT16 *)&mPlatformFvbMediaInfo[Index].FvbInfo,
  100. mPlatformFvbMediaInfo[Index].FvbInfo.HeaderLength
  101. );
  102. mPlatformFvbMediaInfo[Index].FvbInfo.Checksum = Checksum;
  103. }
  104. Checksummed = TRUE;
  105. }
  106. for (Index = 0;
  107. Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO);
  108. Index += 1)
  109. {
  110. if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {
  111. *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;
  112. return EFI_SUCCESS;
  113. }
  114. }
  115. return EFI_NOT_FOUND;
  116. }