VariableSupport.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /** @file
  2. UEFI variable support functions for Firmware Management Protocol based
  3. firmware updates.
  4. Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
  5. Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #ifndef __VARIABLE_SUPPORT_H__
  9. #define __VARIABLE_SUPPORT_H__
  10. ///
  11. /// Default values for FMP Controller State information
  12. ///
  13. #define DEFAULT_VERSION 0x1
  14. #define DEFAULT_LOWESTSUPPORTEDVERSION 0x0
  15. #define DEFAULT_LASTATTEMPTSTATUS 0x0
  16. #define DEFAULT_LASTATTEMPTVERSION 0x0
  17. ///
  18. /// Base UEFI Variable names for FMP Controller State information stored in
  19. /// separate variables.
  20. ///
  21. #define VARNAME_VERSION L"FmpVersion"
  22. #define VARNAME_LSV L"FmpLsv"
  23. #define VARNAME_LASTATTEMPTSTATUS L"LastAttemptStatus"
  24. #define VARNAME_LASTATTEMPTVERSION L"LastAttemptVersion"
  25. ///
  26. /// Base UEFI Variable name for FMP Controller State information stored in a
  27. /// merged UEFI Variable. If the separate UEFI Variables above are detected,
  28. /// then they are merged into a single variable and the separate variables are
  29. /// deleted.
  30. ///
  31. #define VARNAME_FMPSTATE L"FmpState"
  32. ///
  33. /// FMP Controller State structure that is used to store the state of
  34. /// a controller in one combined UEFI Variable.
  35. ///
  36. typedef struct {
  37. BOOLEAN VersionValid;
  38. BOOLEAN LsvValid;
  39. BOOLEAN LastAttemptStatusValid;
  40. BOOLEAN LastAttemptVersionValid;
  41. UINT32 Version;
  42. UINT32 Lsv;
  43. UINT32 LastAttemptStatus;
  44. UINT32 LastAttemptVersion;
  45. } FMP_CONTROLLER_STATE;
  46. /**
  47. Generate the names of the UEFI Variables used to store state information for
  48. a managed controller. The UEFI Variables names are a combination of a base
  49. name and an optional hardware instance value as a 16 character hex value. If
  50. the hardware instance value is 0, then the 16 character hex value is not
  51. included. These storage for the UEFI Variable names are allocated using the
  52. UEFI Boot Service AllocatePool() and the pointers are stored in the Private.
  53. The following are examples of variable names produces for hardware instance
  54. value 0 and value 0x1234567812345678.
  55. FmpVersion
  56. FmpLsv
  57. LastAttemptStatus
  58. LastAttemptVersion
  59. FmpDxe
  60. FmpVersion1234567812345678
  61. FmpLsv1234567812345678
  62. LastAttemptStatus1234567812345678
  63. LastAttemptVersion1234567812345678
  64. FmpDxe1234567812345678
  65. @param[in,out] Private Private context structure for the managed controller.
  66. **/
  67. VOID
  68. GenerateFmpVariableNames (
  69. IN OUT FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private
  70. );
  71. /**
  72. Returns the value used to fill in the Version field of the
  73. EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
  74. service of the Firmware Management Protocol. The value is read from a UEFI
  75. variable. If the UEFI variables does not exist, then a default version value
  76. is returned.
  77. UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"
  78. @param[in] Private Private context structure for the managed controller.
  79. @return The version of the firmware image in the firmware device.
  80. **/
  81. UINT32
  82. GetVersionFromVariable (
  83. IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private
  84. );
  85. /**
  86. Returns the value used to fill in the LowestSupportedVersion field of the
  87. EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
  88. service of the Firmware Management Protocol. The value is read from a UEFI
  89. variable. If the UEFI variables does not exist, then a default lowest
  90. supported version value is returned.
  91. UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"
  92. @param[in] Private Private context structure for the managed controller.
  93. @return The lowest supported version of the firmware image in the firmware
  94. device.
  95. **/
  96. UINT32
  97. GetLowestSupportedVersionFromVariable (
  98. IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private
  99. );
  100. /**
  101. Returns the value used to fill in the LastAttemptStatus field of the
  102. EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
  103. service of the Firmware Management Protocol. The value is read from a UEFI
  104. variable. If the UEFI variables does not exist, then a default last attempt
  105. status value is returned.
  106. UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"
  107. @param[in] Private Private context structure for the managed controller.
  108. @return The last attempt status value for the most recent capsule update.
  109. **/
  110. UINT32
  111. GetLastAttemptStatusFromVariable (
  112. IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private
  113. );
  114. /**
  115. Returns the value used to fill in the LastAttemptVersion field of the
  116. EFI_FIRMWARE_IMAGE_DESCRIPTOR structure that is returned by the GetImageInfo()
  117. service of the Firmware Management Protocol. The value is read from a UEFI
  118. variable. If the UEFI variables does not exist, then a default last attempt
  119. version value is returned.
  120. UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"
  121. @param[in] Private Private context structure for the managed controller.
  122. @return The last attempt version value for the most recent capsule update.
  123. **/
  124. UINT32
  125. GetLastAttemptVersionFromVariable (
  126. IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private
  127. );
  128. /**
  129. Saves the version current of the firmware image in the firmware device to a
  130. UEFI variable.
  131. UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"
  132. @param[in] Private Private context structure for the managed controller.
  133. @param[in] Version The version of the firmware image in the firmware device.
  134. **/
  135. VOID
  136. SetVersionInVariable (
  137. IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private,
  138. IN UINT32 Version
  139. );
  140. /**
  141. Saves the lowest supported version current of the firmware image in the
  142. firmware device to a UEFI variable.
  143. UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"
  144. @param[in] Private Private context structure for the managed
  145. controller.
  146. @param[in] LowestSupportedVersion The lowest supported version of the
  147. firmware image in the firmware device.
  148. **/
  149. VOID
  150. SetLowestSupportedVersionInVariable (
  151. IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private,
  152. IN UINT32 LowestSupportedVersion
  153. );
  154. /**
  155. Saves the last attempt status value of the most recent FMP capsule update to a
  156. UEFI variable.
  157. UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"
  158. @param[in] Private Private context structure for the managed
  159. controller.
  160. @param[in] LastAttemptStatus The last attempt status of the most recent FMP
  161. capsule update.
  162. **/
  163. VOID
  164. SetLastAttemptStatusInVariable (
  165. IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private,
  166. IN UINT32 LastAttemptStatus
  167. );
  168. /**
  169. Saves the last attempt version value of the most recent FMP capsule update to
  170. a UEFI variable.
  171. UEFI Variable accessed: GUID = gEfiCallerIdGuid, Name = L"FmpDxe"
  172. @param[in] Private Private context structure for the managed
  173. controller.
  174. @param[in] LastAttemptVersion The last attempt version value of the most
  175. recent FMP capsule update.
  176. **/
  177. VOID
  178. SetLastAttemptVersionInVariable (
  179. IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private,
  180. IN UINT32 LastAttemptVersion
  181. );
  182. /**
  183. Locks all the UEFI Variables that use gEfiCallerIdGuid of the currently
  184. executing module.
  185. @param[in] Private Private context structure for the managed controller.
  186. @retval EFI_SUCCESS All UEFI variables are locked.
  187. @retval EFI_UNSUPPORTED Variable Lock Protocol not found.
  188. @retval Other One of the UEFI variables could not be locked.
  189. **/
  190. EFI_STATUS
  191. LockAllFmpVariables (
  192. IN FIRMWARE_MANAGEMENT_PRIVATE_DATA *Private
  193. );
  194. #endif