SystemFirmwareDxe.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /** @file
  2. System Firmware update header file.
  3. Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _SYSTEM_FIRMWARE_UPDATE_H_
  7. #define _SYSTEM_FIRMWARE_UPDATE_H_
  8. #include <PiDxe.h>
  9. #include <Guid/SystemResourceTable.h>
  10. #include <Guid/FirmwareContentsSigned.h>
  11. #include <Guid/WinCertificate.h>
  12. #include <Guid/EdkiiSystemFmpCapsule.h>
  13. #include <Protocol/FirmwareManagement.h>
  14. #include <Protocol/FirmwareVolumeBlock.h>
  15. #include <Library/BaseLib.h>
  16. #include <Library/BaseMemoryLib.h>
  17. #include <Library/DebugLib.h>
  18. #include <Library/MemoryAllocationLib.h>
  19. #include <Library/PcdLib.h>
  20. #include <Library/UefiBootServicesTableLib.h>
  21. #include <Library/UefiLib.h>
  22. #include <Library/UefiRuntimeServicesTableLib.h>
  23. #include <Library/UefiDriverEntryPoint.h>
  24. #include <Library/DevicePathLib.h>
  25. #include <Library/HobLib.h>
  26. #include <Library/DxeServicesTableLib.h>
  27. #include <Library/PlatformFlashAccessLib.h>
  28. #include <Library/EdkiiSystemCapsuleLib.h>
  29. typedef struct {
  30. UINT32 LastAttemptVersion;
  31. UINT32 LastAttemptStatus;
  32. } SYSTEM_FMP_LAST_ATTEMPT_VARIABLE;
  33. #define SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME L"SystemLastAttempVar"
  34. #define SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_GUID {0x2f564d6f, 0xcc2c, 0x4838, { 0xb9, 0xa8, 0xbe, 0x59, 0x48, 0xb0, 0x3d, 0x59 }}
  35. #define SYSTEM_FMP_PRIVATE_DATA_SIGNATURE SIGNATURE_32('S', 'Y', 'S', 'F')
  36. #define SYSTEM_FMP_PROTOCOL_GUID {0x6d16624a, 0x26a6, 0x4cb4, { 0x84, 0xfa, 0x6, 0x78, 0x5a, 0x7e, 0x82, 0x6a }}
  37. //
  38. // SYSTEM FMP private data structure.
  39. //
  40. struct _SYSTEM_FMP_PRIVATE_DATA {
  41. UINT32 Signature;
  42. EFI_FIRMWARE_MANAGEMENT_PROTOCOL Fmp;
  43. EFI_HANDLE Handle;
  44. UINT8 DescriptorCount;
  45. EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor;
  46. SYSTEM_FMP_LAST_ATTEMPT_VARIABLE LastAttempt;
  47. };
  48. typedef struct _SYSTEM_FMP_PRIVATE_DATA SYSTEM_FMP_PRIVATE_DATA;
  49. /**
  50. Returns a pointer to the SYSTEM_FMP_PRIVATE_DATA structure from the input a as Fmp.
  51. If the signatures matches, then a pointer to the data structure that contains
  52. a specified field of that data structure is returned.
  53. @param a Pointer to the field specified by ServiceBinding within
  54. a data structure of type SYSTEM_FMP_PRIVATE_DATA.
  55. **/
  56. #define SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(a) \
  57. CR ( \
  58. (a), \
  59. SYSTEM_FMP_PRIVATE_DATA, \
  60. Fmp, \
  61. SYSTEM_FMP_PRIVATE_DATA_SIGNATURE \
  62. )
  63. //
  64. // Update data
  65. //
  66. typedef struct {
  67. UINTN NumOfUpdates;
  68. } CONFIG_HEADER;
  69. typedef struct {
  70. UINTN Index;
  71. PLATFORM_FIRMWARE_TYPE FirmwareType;
  72. FLASH_ADDRESS_TYPE AddressType;
  73. EFI_GUID FileGuid;
  74. EFI_PHYSICAL_ADDRESS BaseAddress;
  75. UINTN Length;
  76. UINTN ImageOffset;
  77. } UPDATE_CONFIG_DATA;
  78. //
  79. // System Firmware Update SMM Communication
  80. //
  81. #define SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_FUNCTION_SET_IMAGE 1
  82. typedef struct {
  83. UINTN Function;
  84. EFI_STATUS ReturnStatus;
  85. // UINT8 Data[];
  86. } SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_HEAD;
  87. #define ABORT_REASON_MAX_SIZE 0x40 // UnicodeStringSize including final L'\0'
  88. #define CAPSULE_IMAGE_ADDITIONAL_MAX_SIZE (0x20020 + 0xA0000) // Additional size for Capsule Header, FV block alignment + DispatchImage.
  89. typedef struct {
  90. UINT8 ImageIndex;
  91. UINTN ImageSize;
  92. UINTN AbortReasonSize;
  93. UINT32 LastAttemptVersion;
  94. UINT32 LastAttemptStatus;
  95. // UINT8 Data[AbortReasonMaxSize + ImageSize];
  96. } SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_SET_IMAGE;
  97. /**
  98. Returns information about the current firmware image(s) of the device.
  99. This function allows a copy of the current firmware image to be created and saved.
  100. The saved copy could later been used, for example, in firmware image recovery or rollback.
  101. @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
  102. @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.
  103. On input, this is the size of the buffer allocated by the caller.
  104. On output, it is the size of the buffer returned by the firmware
  105. if the buffer was large enough, or the size of the buffer needed
  106. to contain the image(s) information if the buffer was too small.
  107. @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)
  108. information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.
  109. @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number
  110. associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.
  111. @param[out] DescriptorCount A pointer to the location in which firmware returns the number of
  112. descriptors or firmware images within this device.
  113. @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,
  114. of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.
  115. @param[out] PackageVersion A version number that represents all the firmware images in the device.
  116. The format is vendor specific and new version must have a greater value
  117. than the old version. If PackageVersion is not supported, the value is
  118. 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison
  119. is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates
  120. that package version update is in progress.
  121. @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the
  122. package version name. The buffer is allocated by this function with
  123. AllocatePool(), and it is the caller's responsibility to free it with a call
  124. to FreePool().
  125. @retval EFI_SUCCESS The device was successfully updated with the new image.
  126. @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size
  127. needed to hold the image(s) information is returned in ImageInfoSize.
  128. @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.
  129. @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.
  130. **/
  131. EFI_STATUS
  132. EFIAPI
  133. FmpGetImageInfo (
  134. IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
  135. IN OUT UINTN *ImageInfoSize,
  136. IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,
  137. OUT UINT32 *DescriptorVersion,
  138. OUT UINT8 *DescriptorCount,
  139. OUT UINTN *DescriptorSize,
  140. OUT UINT32 *PackageVersion,
  141. OUT CHAR16 **PackageVersionName
  142. );
  143. /**
  144. Retrieves a copy of the current firmware image of the device.
  145. This function allows a copy of the current firmware image to be created and saved.
  146. The saved copy could later been used, for example, in firmware image recovery or rollback.
  147. @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
  148. @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
  149. The number is between 1 and DescriptorCount.
  150. @param[in,out] Image Points to the buffer where the current image is copied to.
  151. @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.
  152. On return, points to the length of the image, in bytes.
  153. @retval EFI_SUCCESS The device was successfully updated with the new image.
  154. @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the
  155. image. The current buffer size needed to hold the image is returned
  156. in ImageSize.
  157. @retval EFI_INVALID_PARAMETER The Image was NULL.
  158. @retval EFI_NOT_FOUND The current image is not copied to the buffer.
  159. @retval EFI_UNSUPPORTED The operation is not supported.
  160. @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
  161. **/
  162. EFI_STATUS
  163. EFIAPI
  164. FmpGetImage (
  165. IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
  166. IN UINT8 ImageIndex,
  167. IN OUT VOID *Image,
  168. IN OUT UINTN *ImageSize
  169. );
  170. /**
  171. Updates the firmware image of the device.
  172. This function updates the hardware with the new firmware image.
  173. This function returns EFI_UNSUPPORTED if the firmware image is not updatable.
  174. If the firmware image is updatable, the function should perform the following minimal validations
  175. before proceeding to do the firmware image update.
  176. - Validate the image authentication if image has attribute
  177. IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns
  178. EFI_SECURITY_VIOLATION if the validation fails.
  179. - Validate the image is a supported image for this device. The function returns EFI_ABORTED if
  180. the image is unsupported. The function can optionally provide more detailed information on
  181. why the image is not a supported image.
  182. - Validate the data from VendorCode if not null. Image validation must be performed before
  183. VendorCode data validation. VendorCode data is ignored or considered invalid if image
  184. validation failed. The function returns EFI_ABORTED if the data is invalid.
  185. VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if
  186. the caller did not specify the policy or use the default policy. As an example, vendor can implement
  187. a policy to allow an option to force a firmware image update when the abort reason is due to the new
  188. firmware image version is older than the current firmware image version or bad image checksum.
  189. Sensitive operations such as those wiping the entire firmware image and render the device to be
  190. non-functional should be encoded in the image itself rather than passed with the VendorCode.
  191. AbortReason enables vendor to have the option to provide a more detailed description of the abort
  192. reason to the caller.
  193. @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
  194. @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
  195. The number is between 1 and DescriptorCount.
  196. @param[in] Image Points to the new image.
  197. @param[in] ImageSize Size of the new image in bytes.
  198. @param[in] VendorCode This enables vendor to implement vendor-specific firmware image update policy.
  199. Null indicates the caller did not specify the policy or use the default policy.
  200. @param[in] Progress A function used by the driver to report the progress of the firmware update.
  201. @param[out] AbortReason A pointer to a pointer to a null-terminated string providing more
  202. details for the aborted operation. The buffer is allocated by this function
  203. with AllocatePool(), and it is the caller's responsibility to free it with a
  204. call to FreePool().
  205. @retval EFI_SUCCESS The device was successfully updated with the new image.
  206. @retval EFI_ABORTED The operation is aborted.
  207. @retval EFI_INVALID_PARAMETER The Image was NULL.
  208. @retval EFI_UNSUPPORTED The operation is not supported.
  209. @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
  210. **/
  211. EFI_STATUS
  212. EFIAPI
  213. FmpSetImage (
  214. IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
  215. IN UINT8 ImageIndex,
  216. IN CONST VOID *Image,
  217. IN UINTN ImageSize,
  218. IN CONST VOID *VendorCode,
  219. IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress,
  220. OUT CHAR16 **AbortReason
  221. );
  222. /**
  223. Checks if the firmware image is valid for the device.
  224. This function allows firmware update application to validate the firmware image without
  225. invoking the SetImage() first.
  226. @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
  227. @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.
  228. The number is between 1 and DescriptorCount.
  229. @param[in] Image Points to the new image.
  230. @param[in] ImageSize Size of the new image in bytes.
  231. @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,
  232. if available, additional information if the image is invalid.
  233. @retval EFI_SUCCESS The image was successfully checked.
  234. @retval EFI_INVALID_PARAMETER The Image was NULL.
  235. @retval EFI_UNSUPPORTED The operation is not supported.
  236. @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
  237. **/
  238. EFI_STATUS
  239. EFIAPI
  240. FmpCheckImage (
  241. IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
  242. IN UINT8 ImageIndex,
  243. IN CONST VOID *Image,
  244. IN UINTN ImageSize,
  245. OUT UINT32 *ImageUpdatable
  246. );
  247. /**
  248. Returns information about the firmware package.
  249. This function returns package information.
  250. @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
  251. @param[out] PackageVersion A version number that represents all the firmware images in the device.
  252. The format is vendor specific and new version must have a greater value
  253. than the old version. If PackageVersion is not supported, the value is
  254. 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version
  255. comparison is to be performed using PackageVersionName. A value of
  256. 0xFFFFFFFD indicates that package version update is in progress.
  257. @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing
  258. the package version name. The buffer is allocated by this function with
  259. AllocatePool(), and it is the caller's responsibility to free it with a
  260. call to FreePool().
  261. @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of
  262. package version name. A value of 0 indicates the device does not support
  263. update of package version name. Length is the number of Unicode characters,
  264. including the terminating null character.
  265. @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute
  266. Definitions' for possible returned values of this parameter. A value of 1
  267. indicates the attribute is supported and the current setting value is
  268. indicated in AttributesSetting. A value of 0 indicates the attribute is not
  269. supported and the current setting value in AttributesSetting is meaningless.
  270. @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned
  271. values of this parameter
  272. @retval EFI_SUCCESS The package information was successfully returned.
  273. @retval EFI_UNSUPPORTED The operation is not supported.
  274. **/
  275. EFI_STATUS
  276. EFIAPI
  277. FmpGetPackageInfo (
  278. IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
  279. OUT UINT32 *PackageVersion,
  280. OUT CHAR16 **PackageVersionName,
  281. OUT UINT32 *PackageVersionNameMaxLen,
  282. OUT UINT64 *AttributesSupported,
  283. OUT UINT64 *AttributesSetting
  284. );
  285. /**
  286. Updates information about the firmware package.
  287. This function updates package information.
  288. This function returns EFI_UNSUPPORTED if the package information is not updatable.
  289. VendorCode enables vendor to implement vendor-specific package information update policy.
  290. Null if the caller did not specify this policy or use the default policy.
  291. @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
  292. @param[in] Image Points to the authentication image.
  293. Null if authentication is not required.
  294. @param[in] ImageSize Size of the authentication image in bytes.
  295. 0 if authentication is not required.
  296. @param[in] VendorCode This enables vendor to implement vendor-specific firmware
  297. image update policy.
  298. Null indicates the caller did not specify this policy or use
  299. the default policy.
  300. @param[in] PackageVersion The new package version.
  301. @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing
  302. the package version name.
  303. The string length is equal to or less than the value returned in
  304. PackageVersionNameMaxLen.
  305. @retval EFI_SUCCESS The device was successfully updated with the new package
  306. information.
  307. @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value
  308. returned in PackageVersionNameMaxLen.
  309. @retval EFI_UNSUPPORTED The operation is not supported.
  310. @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.
  311. **/
  312. EFI_STATUS
  313. EFIAPI
  314. FmpSetPackageInfo (
  315. IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,
  316. IN CONST VOID *Image,
  317. IN UINTN ImageSize,
  318. IN CONST VOID *VendorCode,
  319. IN UINT32 PackageVersion,
  320. IN CONST CHAR16 *PackageVersionName
  321. );
  322. /**
  323. Initialize SystemFmpDriver private data structure.
  324. @param[in] SystemFmpPrivate private data structure to be initialized.
  325. @return EFI_SUCCESS private data is initialized.
  326. **/
  327. EFI_STATUS
  328. InitializePrivateData (
  329. IN SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate
  330. );
  331. extern EFI_GUID gSystemFmpLastAttemptVariableGuid;
  332. extern EFI_GUID mCurrentImageTypeId;
  333. extern EFI_GUID gSystemFmpProtocolGuid;
  334. #endif