FmpPayloadHeaderLib.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /** @file
  2. Provides services to retrieve values from Version 1 of a capsule's FMP Payload
  3. Header. The FMP Payload Header structure is not defined in the library class.
  4. Instead, services are provided to retrieve information from the FMP Payload
  5. Header. If information is added to the FMP Payload Header, then new services
  6. may be added to this library class to retrieve the new information.
  7. Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
  8. Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
  9. SPDX-License-Identifier: BSD-2-Clause-Patent
  10. **/
  11. #include <PiDxe.h>
  12. #include <Library/FmpPayloadHeaderLib.h>
  13. ///
  14. /// Define FMP Payload Header structure here so it is not public
  15. ///
  16. #pragma pack(1)
  17. typedef struct {
  18. UINT32 Signature;
  19. UINT32 HeaderSize;
  20. UINT32 FwVersion;
  21. UINT32 LowestSupportedVersion;
  22. } FMP_PAYLOAD_HEADER;
  23. #pragma pack()
  24. ///
  25. /// Identifier is used to make sure the data in the header is for this structure
  26. /// and version. If the structure changes update the last digit.
  27. ///
  28. #define FMP_PAYLOAD_HEADER_SIGNATURE SIGNATURE_32 ('M', 'S', 'S', '1')
  29. /**
  30. Returns the FMP Payload Header size in bytes.
  31. @param[in] Header FMP Payload Header to evaluate
  32. @param[in] FmpPayloadSize Size of FMP payload
  33. @param[out] Size The size, in bytes, of the FMP Payload Header.
  34. @retval EFI_SUCCESS The firmware version was returned.
  35. @retval EFI_INVALID_PARAMETER Header is NULL.
  36. @retval EFI_INVALID_PARAMETER Size is NULL.
  37. @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
  38. **/
  39. EFI_STATUS
  40. EFIAPI
  41. GetFmpPayloadHeaderSize (
  42. IN CONST VOID *Header,
  43. IN CONST UINTN FmpPayloadSize,
  44. OUT UINT32 *Size
  45. )
  46. {
  47. FMP_PAYLOAD_HEADER *FmpPayloadHeader;
  48. FmpPayloadHeader = NULL;
  49. if ((Header == NULL) || (Size == NULL)) {
  50. return EFI_INVALID_PARAMETER;
  51. }
  52. FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;
  53. if (((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader) ||
  54. ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize) ||
  55. (FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)))
  56. {
  57. return EFI_INVALID_PARAMETER;
  58. }
  59. if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {
  60. return EFI_INVALID_PARAMETER;
  61. }
  62. *Size = FmpPayloadHeader->HeaderSize;
  63. return EFI_SUCCESS;
  64. }
  65. /**
  66. Returns the version described in the FMP Payload Header.
  67. @param[in] Header FMP Payload Header to evaluate
  68. @param[in] FmpPayloadSize Size of FMP payload
  69. @param[out] Version The firmware version described in the FMP Payload
  70. Header.
  71. @retval EFI_SUCCESS The firmware version was returned.
  72. @retval EFI_INVALID_PARAMETER Header is NULL.
  73. @retval EFI_INVALID_PARAMETER Version is NULL.
  74. @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
  75. **/
  76. EFI_STATUS
  77. EFIAPI
  78. GetFmpPayloadHeaderVersion (
  79. IN CONST VOID *Header,
  80. IN CONST UINTN FmpPayloadSize,
  81. OUT UINT32 *Version
  82. )
  83. {
  84. FMP_PAYLOAD_HEADER *FmpPayloadHeader;
  85. FmpPayloadHeader = NULL;
  86. if ((Header == NULL) || (Version == NULL)) {
  87. return EFI_INVALID_PARAMETER;
  88. }
  89. FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;
  90. if (((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader) ||
  91. ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize) ||
  92. (FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)))
  93. {
  94. return EFI_INVALID_PARAMETER;
  95. }
  96. if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {
  97. return EFI_INVALID_PARAMETER;
  98. }
  99. *Version = FmpPayloadHeader->FwVersion;
  100. return EFI_SUCCESS;
  101. }
  102. /**
  103. Returns the lowest supported version described in the FMP Payload Header.
  104. @param[in] Header FMP Payload Header to evaluate
  105. @param[in] FmpPayloadSize Size of FMP payload
  106. @param[out] LowestSupportedVersion The lowest supported version described in
  107. the FMP Payload Header.
  108. @retval EFI_SUCCESS The lowest support version was returned.
  109. @retval EFI_INVALID_PARAMETER Header is NULL.
  110. @retval EFI_INVALID_PARAMETER LowestSupportedVersion is NULL.
  111. @retval EFI_INVALID_PARAMETER Header is not a valid FMP Payload Header.
  112. **/
  113. EFI_STATUS
  114. EFIAPI
  115. GetFmpPayloadHeaderLowestSupportedVersion (
  116. IN CONST VOID *Header,
  117. IN CONST UINTN FmpPayloadSize,
  118. OUT UINT32 *LowestSupportedVersion
  119. )
  120. {
  121. FMP_PAYLOAD_HEADER *FmpPayloadHeader;
  122. FmpPayloadHeader = NULL;
  123. if ((Header == NULL) || (LowestSupportedVersion == NULL)) {
  124. return EFI_INVALID_PARAMETER;
  125. }
  126. FmpPayloadHeader = (FMP_PAYLOAD_HEADER *)Header;
  127. if (((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) < (UINTN)FmpPayloadHeader) ||
  128. ((UINTN)FmpPayloadHeader + sizeof (FMP_PAYLOAD_HEADER) >= (UINTN)FmpPayloadHeader + FmpPayloadSize) ||
  129. (FmpPayloadHeader->HeaderSize < sizeof (FMP_PAYLOAD_HEADER)))
  130. {
  131. return EFI_INVALID_PARAMETER;
  132. }
  133. if (FmpPayloadHeader->Signature != FMP_PAYLOAD_HEADER_SIGNATURE) {
  134. return EFI_INVALID_PARAMETER;
  135. }
  136. *LowestSupportedVersion = FmpPayloadHeader->LowestSupportedVersion;
  137. return EFI_SUCCESS;
  138. }