FvbInfo.c 3.3 KB

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