]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SignedCapsulePkg/SystemFirmwareUpdate: Add SystemFirmwareUpdate.
authorJiewen Yao <jiewen.yao@intel.com>
Wed, 21 Sep 2016 02:30:12 +0000 (10:30 +0800)
committerJiewen Yao <jiewen.yao@intel.com>
Tue, 8 Nov 2016 14:41:02 +0000 (22:41 +0800)
SystemFirmwareUpdate supports update system firmware via UEFI FMP capsule.

SystemFirmwareReportDxe.inf can be included in system BIOS. It is a
lightweight FMP protocol implementation and it only reports FMP
information, so that ESRT table can report the system firmware
information. SetImage() will dispatch the driver FV in the EDKII system
FMP image (SystemFirmwareUpdateDxe),
then pass thru the SetImage() request to latter.

SystemFirmwareUpdateDxe.inf can be included in EDKII system capsule image.
It is a full feature FMP protocol implementation and supports SetImage().
It can be used to update the system firmware.
SystemFirmwareUpdateDxe.inf can also be included in system firmware.
If so SystemFirmwareReportDxe.inf is not needed.

SystemFirmwareUpdateDxe SetImage() will perform the FMP authentication and
version check. If and only if the FMP authentication passes, and new
EDKII system capsule version is no less than current system firmware
LowestSupportedVersion, the system firmware will be updated.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
Tested-by: Michael Kinney <michael.d.kinney@intel.com>
SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c [new file with mode: 0644]
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareCommonDxe.c [new file with mode: 0644]
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareDxe.h [new file with mode: 0644]
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.c [new file with mode: 0644]
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.inf [new file with mode: 0644]
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.uni [new file with mode: 0644]
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxeExtra.uni [new file with mode: 0644]
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.c [new file with mode: 0644]
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.inf [new file with mode: 0644]
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.uni [new file with mode: 0644]
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxeExtra.uni [new file with mode: 0644]

diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/ParseConfigProfile.c
new file mode 100644 (file)
index 0000000..dcad762
--- /dev/null
@@ -0,0 +1,213 @@
+/** @file\r
+  Parse the INI configuration file and pass the information to the update driver\r
+  so that the driver can perform update accordingly.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions\r
+  of the BSD License which accompanies this distribution.  The\r
+  full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "SystemFirmwareDxe.h"\r
+#include <Library/IniParsingLib.h>\r
+#include <Library/PrintLib.h>\r
+\r
+#define MAX_LINE_LENGTH           512\r
+\r
+/**\r
+  Parse Config data file to get the updated data array.\r
+\r
+  @param[in]      DataBuffer      Config raw file buffer.\r
+  @param[in]      BufferSize      Size of raw buffer.\r
+  @param[in, out] ConfigHeader    Pointer to the config header.\r
+  @param[in, out] UpdateArray     Pointer to the config of update data.\r
+\r
+  @retval EFI_NOT_FOUND         No config data is found.\r
+  @retval EFI_OUT_OF_RESOURCES  No enough memory is allocated.\r
+  @retval EFI_SUCCESS           Parse the config file successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+ParseUpdateDataFile (\r
+  IN      UINT8                         *DataBuffer,\r
+  IN      UINTN                         BufferSize,\r
+  IN OUT  CONFIG_HEADER                 *ConfigHeader,\r
+  IN OUT  UPDATE_CONFIG_DATA            **UpdateArray\r
+  )\r
+{\r
+  EFI_STATUS                            Status;\r
+  CHAR8                                 *SectionName;\r
+  CHAR8                                 Entry[MAX_LINE_LENGTH];\r
+  UINTN                                 Num;\r
+  UINT64                                Num64;\r
+  UINTN                                 Index;\r
+  EFI_GUID                              FileGuid;\r
+  VOID                                  *Context;\r
+\r
+  //\r
+  // First process the data buffer and get all sections and entries\r
+  //\r
+  Context = OpenIniFile(DataBuffer, BufferSize);\r
+  if (Context == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Now get NumOfUpdate\r
+  //\r
+  Status = GetDecimalUintnFromDataFile(\r
+             Context,\r
+             "Head",\r
+             "NumOfUpdate",\r
+             &Num\r
+             );\r
+  if (EFI_ERROR(Status) || (Num == 0)) {\r
+    DEBUG((DEBUG_ERROR, "NumOfUpdate not found\n"));\r
+    CloseIniFile(Context);\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  ConfigHeader->NumOfUpdates = Num;\r
+  *UpdateArray = AllocateZeroPool ((sizeof (UPDATE_CONFIG_DATA) * Num));\r
+  if (*UpdateArray == NULL) {\r
+    CloseIniFile(Context);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (Index = 0 ; Index < ConfigHeader->NumOfUpdates ; Index++) {\r
+    //\r
+    // Get the section name of each update\r
+    //\r
+    AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Update");\r
+    AsciiValueToString(Entry + AsciiStrLen(Entry), 0, Index, 0);\r
+    Status = GetStringFromDataFile(\r
+               Context,\r
+               "Head",\r
+               Entry,\r
+               &SectionName\r
+               );\r
+    if (EFI_ERROR(Status) || (SectionName == NULL)) {\r
+      DEBUG((DEBUG_ERROR, "[%d] %a not found\n", Index, Entry));\r
+      CloseIniFile(Context);\r
+      return EFI_NOT_FOUND;\r
+    }\r
+\r
+    //\r
+    // The section name of this update has been found.\r
+    // Now looks for all the config data of this update\r
+    //\r
+    (*UpdateArray)[Index].Index = Index;\r
+\r
+    //\r
+    // FirmwareType\r
+    //\r
+    Status = GetDecimalUintnFromDataFile(\r
+               Context,\r
+               SectionName,\r
+               "FirmwareType",\r
+               &Num\r
+               );\r
+    if (EFI_ERROR(Status)) {\r
+      CloseIniFile(Context);\r
+      DEBUG((DEBUG_ERROR, "[%d] FirmwareType not found\n", Index));\r
+      return EFI_NOT_FOUND;\r
+    }\r
+    (*UpdateArray)[Index].FirmwareType = (PLATFORM_FIRMWARE_TYPE) Num;\r
+\r
+    //\r
+    // AddressType\r
+    //\r
+    Status = GetDecimalUintnFromDataFile(\r
+               Context,\r
+               SectionName,\r
+               "AddressType",\r
+               &Num\r
+               );\r
+    if (EFI_ERROR(Status)) {\r
+      CloseIniFile(Context);\r
+      DEBUG((DEBUG_ERROR, "[%d] AddressType not found\n", Index));\r
+      return EFI_NOT_FOUND;\r
+    }\r
+    (*UpdateArray)[Index].AddressType = (FLASH_ADDRESS_TYPE) Num;\r
+\r
+    //\r
+    // BaseAddress\r
+    //\r
+    Status = GetHexUint64FromDataFile(\r
+               Context,\r
+               SectionName,\r
+               "BaseAddress",\r
+               &Num64\r
+               );\r
+    if (EFI_ERROR(Status)) {\r
+      CloseIniFile(Context);\r
+      DEBUG((DEBUG_ERROR, "[%d] BaseAddress not found\n", Index));\r
+      return EFI_NOT_FOUND;\r
+    }\r
+    (*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS) Num64;\r
+\r
+    //\r
+    // FileBuid\r
+    //\r
+    Status = GetGuidFromDataFile(\r
+               Context,\r
+               SectionName,\r
+               "FileGuid",\r
+               &FileGuid\r
+               );\r
+    if (EFI_ERROR(Status)) {\r
+      CloseIniFile(Context);\r
+      DEBUG((DEBUG_ERROR, "[%d] FileGuid not found\n", Index));\r
+      return EFI_NOT_FOUND;\r
+    }\r
+\r
+    CopyGuid(&((*UpdateArray)[Index].FileGuid), &FileGuid);\r
+\r
+    //\r
+    // Length\r
+    //\r
+    Status = GetHexUintnFromDataFile(\r
+               Context,\r
+               SectionName,\r
+               "Length",\r
+               &Num\r
+               );\r
+    if (EFI_ERROR(Status)) {\r
+      CloseIniFile(Context);\r
+      DEBUG((DEBUG_ERROR, "[%d] Length not found\n", Index));\r
+      return EFI_NOT_FOUND;\r
+    }\r
+    (*UpdateArray)[Index].Length = (UINTN) Num;\r
+\r
+    //\r
+    // ImageOffset\r
+    //\r
+    Status = GetHexUintnFromDataFile(\r
+               Context,\r
+               SectionName,\r
+               "ImageOffset",\r
+               &Num\r
+               );\r
+    if (EFI_ERROR(Status)) {\r
+      CloseIniFile(Context);\r
+      DEBUG((DEBUG_ERROR, "[%d] ImageOffset not found\n", Index));\r
+      return EFI_NOT_FOUND;\r
+    }\r
+    (*UpdateArray)[Index].ImageOffset = (UINTN) Num;\r
+  }\r
+\r
+  //\r
+  // Now all configuration data got. Free those temporary buffers\r
+  //\r
+  CloseIniFile(Context);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareCommonDxe.c b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareCommonDxe.c
new file mode 100644 (file)
index 0000000..642a99d
--- /dev/null
@@ -0,0 +1,385 @@
+/** @file\r
+  Produce FMP instance for system firmware.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "SystemFirmwareDxe.h"\r
+\r
+EFI_GUID gSystemFmpLastAttemptVariableGuid = SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_GUID;\r
+EFI_GUID gSystemFmpProtocolGuid = SYSTEM_FMP_PROTOCOL_GUID;\r
+\r
+EFI_FIRMWARE_MANAGEMENT_PROTOCOL mFirmwareManagementProtocol = {\r
+  FmpGetImageInfo,\r
+  FmpGetImage,\r
+  FmpSetImage,\r
+  FmpCheckImage,\r
+  FmpGetPackageInfo,\r
+  FmpSetPackageInfo\r
+};\r
+\r
+/**\r
+  Returns information about the current firmware image(s) of the device.\r
+\r
+  This function allows a copy of the current firmware image to be created and saved.\r
+  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
+\r
+  @param[in]      This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in, out] ImageInfoSize      A pointer to the size, in bytes, of the ImageInfo buffer.\r
+                                     On input, this is the size of the buffer allocated by the caller.\r
+                                     On output, it is the size of the buffer returned by the firmware\r
+                                     if the buffer was large enough, or the size of the buffer needed\r
+                                     to contain the image(s) information if the buffer was too small.\r
+  @param[in, out] ImageInfo          A pointer to the buffer in which firmware places the current image(s)\r
+                                     information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r
+  @param[out]     DescriptorVersion  A pointer to the location in which firmware returns the version number\r
+                                     associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]     DescriptorCount    A pointer to the location in which firmware returns the number of\r
+                                     descriptors or firmware images within this device.\r
+  @param[out]     DescriptorSize     A pointer to the location in which firmware returns the size, in bytes,\r
+                                     of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]     PackageVersion     A version number that represents all the firmware images in the device.\r
+                                     The format is vendor specific and new version must have a greater value\r
+                                     than the old version. If PackageVersion is not supported, the value is\r
+                                     0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r
+                                     is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r
+                                     that package version update is in progress.\r
+  @param[out]     PackageVersionName A pointer to a pointer to a null-terminated string representing the\r
+                                     package version name. The buffer is allocated by this function with\r
+                                     AllocatePool(), and it is the caller's responsibility to free it with a call\r
+                                     to FreePool().\r
+\r
+  @retval EFI_SUCCESS                The device was successfully updated with the new image.\r
+  @retval EFI_BUFFER_TOO_SMALL       The ImageInfo buffer was too small. The current buffer size\r
+                                     needed to hold the image(s) information is returned in ImageInfoSize.\r
+  @retval EFI_INVALID_PARAMETER      ImageInfoSize is NULL.\r
+  @retval EFI_DEVICE_ERROR           Valid information could not be returned. Possible corrupted image.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetImageInfo (\r
+  IN        EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
+  IN OUT    UINTN                            *ImageInfoSize,\r
+  IN OUT    EFI_FIRMWARE_IMAGE_DESCRIPTOR    *ImageInfo,\r
+  OUT       UINT32                           *DescriptorVersion,\r
+  OUT       UINT8                            *DescriptorCount,\r
+  OUT       UINTN                            *DescriptorSize,\r
+  OUT       UINT32                           *PackageVersion,\r
+  OUT       CHAR16                           **PackageVersionName\r
+  )\r
+{\r
+  SYSTEM_FMP_PRIVATE_DATA                *SystemFmpPrivate;\r
+  EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor;\r
+\r
+  SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(This);\r
+\r
+  if(ImageInfoSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (*ImageInfoSize < sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount) {\r
+    *ImageInfoSize = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount;\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  if (ImageInfo == NULL ||\r
+      DescriptorVersion == NULL ||\r
+      DescriptorCount == NULL ||\r
+      DescriptorSize == NULL ||\r
+      PackageVersion == NULL ||\r
+      PackageVersionName == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *ImageInfoSize      = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount;\r
+  *DescriptorSize     = sizeof(EFI_FIRMWARE_IMAGE_DESCRIPTOR);\r
+  *DescriptorCount    = SystemFmpPrivate->DescriptorCount;\r
+  *DescriptorVersion  = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;\r
+\r
+  //\r
+  // supports 1 ImageInfo descriptor\r
+  //\r
+  ImageDescriptor = SystemFmpPrivate->ImageDescriptor;\r
+  ImageInfo->ImageIndex = ImageDescriptor->ImageIndex;\r
+  CopyGuid (&ImageInfo->ImageTypeId, &ImageDescriptor->ImageTypeId);\r
+  ImageInfo->ImageId = ImageDescriptor->ImageId;\r
+  if (ImageDescriptor->ImageIdNameStringOffset != 0) {\r
+    ImageInfo->ImageIdName = (CHAR16 *)((UINTN)ImageDescriptor + ImageDescriptor->ImageIdNameStringOffset);\r
+  } else {\r
+    ImageInfo->ImageIdName = NULL;\r
+  }\r
+  ImageInfo->Version = ImageDescriptor->Version;\r
+  if (ImageDescriptor->VersionNameStringOffset != 0) {\r
+    ImageInfo->VersionName = (CHAR16 *)((UINTN)ImageDescriptor + ImageDescriptor->VersionNameStringOffset);\r
+  } else {\r
+    ImageInfo->VersionName = NULL;\r
+  }\r
+  ImageInfo->Size = (UINTN)ImageDescriptor->Size;\r
+  ImageInfo->AttributesSupported = ImageDescriptor->AttributesSupported;\r
+  ImageInfo->AttributesSetting = ImageDescriptor->AttributesSetting;\r
+  ImageInfo->Compatibilities = ImageDescriptor->Compatibilities;\r
+  ImageInfo->LowestSupportedImageVersion = ImageDescriptor->LowestSupportedImageVersion;\r
+  ImageInfo->LastAttemptVersion = SystemFmpPrivate->LastAttempt.LastAttemptVersion;\r
+  ImageInfo->LastAttemptStatus = SystemFmpPrivate->LastAttempt.LastAttemptStatus;\r
+  ImageInfo->HardwareInstance = ImageDescriptor->HardwareInstance;\r
+\r
+  //\r
+  // package version\r
+  //\r
+  *PackageVersion = ImageDescriptor->PackageVersion;\r
+  if (ImageDescriptor->PackageVersionNameStringOffset != 0) {\r
+    *PackageVersionName = (VOID *)((UINTN)ImageDescriptor + ImageDescriptor->PackageVersionNameStringOffset);\r
+    *PackageVersionName = AllocateCopyPool(StrSize(*PackageVersionName), *PackageVersionName);\r
+  } else {\r
+    *PackageVersionName = NULL;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves a copy of the current firmware image of the device.\r
+\r
+  This function allows a copy of the current firmware image to be created and saved.\r
+  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
+\r
+  @param[in]     This            A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]     ImageIndex      A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in,out] Image           Points to the buffer where the current image is copied to.\r
+  @param[in,out] ImageSize       On entry, points to the size of the buffer pointed to by Image, in bytes.\r
+                                 On return, points to the length of the image, in bytes.\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
+  @retval EFI_BUFFER_TOO_SMALL   The buffer specified by ImageSize is too small to hold the\r
+                                 image. The current buffer size needed to hold the image is returned\r
+                                 in ImageSize.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_NOT_FOUND          The current image is not copied to the buffer.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
+  IN  UINT8                             ImageIndex,\r
+  IN  OUT  VOID                         *Image,\r
+  IN  OUT  UINTN                        *ImageSize\r
+  )\r
+{\r
+  SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate;\r
+\r
+  if (Image == NULL || ImageSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(This);\r
+\r
+  if (ImageIndex == 0 || ImageIndex > SystemFmpPrivate->DescriptorCount || ImageSize == NULL || Image == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Checks if the firmware image is valid for the device.\r
+\r
+  This function allows firmware update application to validate the firmware image without\r
+  invoking the SetImage() first.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in]  Image              Points to the new image.\r
+  @param[in]  ImageSize          Size of the new image in bytes.\r
+  @param[out] ImageUpdatable     Indicates if the new image is valid for update. It also provides,\r
+                                 if available, additional information if the image is invalid.\r
+\r
+  @retval EFI_SUCCESS            The image was successfully checked.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpCheckImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
+  IN  UINT8                             ImageIndex,\r
+  IN  CONST VOID                        *Image,\r
+  IN  UINTN                             ImageSize,\r
+  OUT UINT32                            *ImageUpdatable\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Returns information about the firmware package.\r
+\r
+  This function returns package information.\r
+\r
+  @param[in]  This                     A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[out] PackageVersion           A version number that represents all the firmware images in the device.\r
+                                       The format is vendor specific and new version must have a greater value\r
+                                       than the old version. If PackageVersion is not supported, the value is\r
+                                       0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
+                                       comparison is to be performed using PackageVersionName. A value of\r
+                                       0xFFFFFFFD indicates that package version update is in progress.\r
+  @param[out] PackageVersionName       A pointer to a pointer to a null-terminated string representing\r
+                                       the package version name. The buffer is allocated by this function with\r
+                                       AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                       call to FreePool().\r
+  @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
+                                       package version name. A value of 0 indicates the device does not support\r
+                                       update of package version name. Length is the number of Unicode characters,\r
+                                       including the terminating null character.\r
+  @param[out] AttributesSupported      Package attributes that are supported by this device. See 'Package Attribute\r
+                                       Definitions' for possible returned values of this parameter. A value of 1\r
+                                       indicates the attribute is supported and the current setting value is\r
+                                       indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
+                                       supported and the current setting value in AttributesSetting is meaningless.\r
+  @param[out] AttributesSetting        Package attributes. See 'Package Attribute Definitions' for possible returned\r
+                                       values of this parameter\r
+\r
+  @retval EFI_SUCCESS                  The package information was successfully returned.\r
+  @retval EFI_UNSUPPORTED              The operation is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetPackageInfo (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
+  OUT UINT32                           *PackageVersion,\r
+  OUT CHAR16                           **PackageVersionName,\r
+  OUT UINT32                           *PackageVersionNameMaxLen,\r
+  OUT UINT64                           *AttributesSupported,\r
+  OUT UINT64                           *AttributesSetting\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Updates information about the firmware package.\r
+\r
+  This function updates package information.\r
+  This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
+  VendorCode enables vendor to implement vendor-specific package information update policy.\r
+  Null if the caller did not specify this policy or use the default policy.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  Image              Points to the authentication image.\r
+                                 Null if authentication is not required.\r
+  @param[in]  ImageSize          Size of the authentication image in bytes.\r
+                                 0 if authentication is not required.\r
+  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware\r
+                                 image update policy.\r
+                                 Null indicates the caller did not specify this policy or use\r
+                                 the default policy.\r
+  @param[in]  PackageVersion     The new package version.\r
+  @param[in]  PackageVersionName A pointer to the new null-terminated Unicode string representing\r
+                                 the package version name.\r
+                                 The string length is equal to or less than the value returned in\r
+                                 PackageVersionNameMaxLen.\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new package\r
+                                 information.\r
+  @retval EFI_INVALID_PARAMETER  The PackageVersionName length is longer than the value\r
+                                 returned in PackageVersionNameMaxLen.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpSetPackageInfo (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL   *This,\r
+  IN  CONST VOID                         *Image,\r
+  IN  UINTN                              ImageSize,\r
+  IN  CONST VOID                         *VendorCode,\r
+  IN  UINT32                             PackageVersion,\r
+  IN  CONST CHAR16                       *PackageVersionName\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Initialize SystemFmpDriver private data structure.\r
+\r
+  @param[in] SystemFmpPrivate  private data structure to be initialized.\r
+\r
+  @return EFI_SUCCESS private data is initialized.\r
+**/\r
+EFI_STATUS\r
+InitializePrivateData (\r
+  IN SYSTEM_FMP_PRIVATE_DATA  *SystemFmpPrivate\r
+  )\r
+{\r
+  EFI_STATUS       VarStatus;\r
+  UINTN            VarSize;\r
+\r
+  SystemFmpPrivate->Signature       = SYSTEM_FMP_PRIVATE_DATA_SIGNATURE;\r
+  SystemFmpPrivate->Handle          = NULL;\r
+  SystemFmpPrivate->DescriptorCount = 1;\r
+  CopyMem(&SystemFmpPrivate->Fmp, &mFirmwareManagementProtocol, sizeof(EFI_FIRMWARE_MANAGEMENT_PROTOCOL));\r
+\r
+  SystemFmpPrivate->ImageDescriptor = PcdGetPtr(PcdEdkiiSystemFirmwareImageDescriptor);\r
+\r
+  SystemFmpPrivate->LastAttempt.LastAttemptVersion = 0x0;\r
+  SystemFmpPrivate->LastAttempt.LastAttemptStatus = 0x0;\r
+  VarSize = sizeof(SystemFmpPrivate->LastAttempt);\r
+  VarStatus = gRT->GetVariable(\r
+                     SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
+                     &gSystemFmpLastAttemptVariableGuid,\r
+                     NULL,\r
+                     &VarSize,\r
+                     &SystemFmpPrivate->LastAttempt\r
+                     );\r
+  DEBUG((DEBUG_INFO, "GetLastAttemp - %r\n", VarStatus));\r
+  DEBUG((DEBUG_INFO, "GetLastAttemp Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Return if this FMP is a system FMP or a device FMP, based upon FmpImageInfo.\r
+\r
+  @param[in] FmpImageInfo A pointer to EFI_FIRMWARE_IMAGE_DESCRIPTOR\r
+\r
+  @retval TRUE  It is a system FMP.\r
+  @retval FALSE It is a device FMP.\r
+**/\r
+BOOLEAN\r
+IsSystemFmp (\r
+  IN EFI_FIRMWARE_IMAGE_DESCRIPTOR   *FmpImageInfo\r
+  )\r
+{\r
+  GUID      *Guid;\r
+  UINTN     Count;\r
+  UINTN     Index;\r
+\r
+  Guid = PcdGetPtr(PcdSystemFmpCapsuleImageTypeIdGuid);\r
+  Count = PcdGetSize(PcdSystemFmpCapsuleImageTypeIdGuid) / sizeof(GUID);\r
+\r
+  for (Index = 0; Index < Count; Index++, Guid++) {\r
+    if (CompareGuid(&FmpImageInfo->ImageTypeId, Guid)) {\r
+      return TRUE;\r
+    }\r
+  }\r
+\r
+  return FALSE;\r
+}\r
diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareDxe.h b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareDxe.h
new file mode 100644 (file)
index 0000000..dd3a68a
--- /dev/null
@@ -0,0 +1,408 @@
+/** @file\r
+  System Firmware update header file.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _SYSTEM_FIRMWARE_UPDATE_H_\r
+#define _SYSTEM_FIRMWARE_UPDATE_H_\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Guid/SystemResourceTable.h>\r
+#include <Guid/FirmwareContentsSigned.h>\r
+#include <Guid/WinCertificate.h>\r
+#include <Guid/EdkiiSystemFmpCapsule.h>\r
+\r
+#include <Protocol/FirmwareManagement.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/DxeServicesLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/PlatformFlashAccessLib.h>\r
+#include <Library/EdkiiSystemCapsuleLib.h>\r
+\r
+typedef struct {\r
+  UINT32 LastAttemptVersion;\r
+  UINT32 LastAttemptStatus;\r
+} SYSTEM_FMP_LAST_ATTEMPT_VARIABLE;\r
+\r
+#define SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME  L"SystemLastAttempVar"\r
+\r
+#define SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_GUID {0x2f564d6f, 0xcc2c, 0x4838, { 0xb9, 0xa8, 0xbe, 0x59, 0x48, 0xb0, 0x3d, 0x59 }}\r
+\r
+#define SYSTEM_FMP_PRIVATE_DATA_SIGNATURE  SIGNATURE_32('S', 'Y', 'S', 'F')\r
+\r
+#define SYSTEM_FMP_PROTOCOL_GUID {0x6d16624a, 0x26a6, 0x4cb4, { 0x84, 0xfa, 0x6, 0x78, 0x5a, 0x7e, 0x82, 0x6a }}\r
+\r
+//\r
+// SYSTEM FMP private data structure.\r
+//\r
+\r
+struct _SYSTEM_FMP_PRIVATE_DATA {\r
+  UINT32                                          Signature;\r
+  EFI_FIRMWARE_MANAGEMENT_PROTOCOL                Fmp;\r
+  EFI_HANDLE                                      Handle;\r
+  UINT8                                           DescriptorCount;\r
+  EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR          *ImageDescriptor;\r
+  SYSTEM_FMP_LAST_ATTEMPT_VARIABLE                LastAttempt;\r
+};\r
+\r
+typedef struct _SYSTEM_FMP_PRIVATE_DATA  SYSTEM_FMP_PRIVATE_DATA;\r
+\r
+/**\r
+  Returns a pointer to the SYSTEM_FMP_PRIVATE_DATA structure from the input a as Fmp.\r
+\r
+  If the signatures matches, then a pointer to the data structure that contains\r
+  a specified field of that data structure is returned.\r
+\r
+  @param  a              Pointer to the field specified by ServiceBinding within\r
+                         a data structure of type SYSTEM_FMP_PRIVATE_DATA.\r
+\r
+**/\r
+#define SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(a) \\r
+  CR ( \\r
+  (a), \\r
+  SYSTEM_FMP_PRIVATE_DATA, \\r
+  Fmp, \\r
+  SYSTEM_FMP_PRIVATE_DATA_SIGNATURE \\r
+  )\r
+\r
+\r
+//\r
+// Update data\r
+//\r
+\r
+typedef struct {\r
+  UINTN                           NumOfUpdates;\r
+} CONFIG_HEADER;\r
+\r
+typedef struct {\r
+  UINTN                           Index;\r
+  PLATFORM_FIRMWARE_TYPE          FirmwareType;\r
+  FLASH_ADDRESS_TYPE              AddressType;\r
+  EFI_GUID                        FileGuid;\r
+  EFI_PHYSICAL_ADDRESS            BaseAddress;\r
+  UINTN                           Length;\r
+  UINTN                           ImageOffset;\r
+} UPDATE_CONFIG_DATA;\r
+\r
+//\r
+// System Firmware Update SMM Communication\r
+//\r
+\r
+#define SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_FUNCTION_SET_IMAGE 1\r
+\r
+typedef struct {\r
+  UINTN       Function;\r
+  EFI_STATUS  ReturnStatus;\r
+//UINT8       Data[];\r
+} SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_HEAD;\r
+\r
+#define  ABORT_REASON_MAX_SIZE              0x40  // UnicodeStringSize including final L'\0'\r
+\r
+#define  CAPSULE_IMAGE_ADDITIONAL_MAX_SIZE  (0x20020 + 0xA0000) // Addtional size for Capsule Header, FV block alignment + DispatchImage.\r
+\r
+typedef struct {\r
+  UINT8       ImageIndex;\r
+  UINTN       ImageSize;\r
+  UINTN       AbortReasonSize;\r
+  UINT32      LastAttemptVersion;\r
+  UINT32      LastAttemptStatus;\r
+//UINT8       Data[AbortReasonMaxSize + ImageSize];\r
+} SYSTEM_FIRMWARE_UPDATE_COMMUNICATION_SET_IMAGE;\r
+\r
+\r
+/**\r
+  Returns information about the current firmware image(s) of the device.\r
+\r
+  This function allows a copy of the current firmware image to be created and saved.\r
+  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
+\r
+  @param[in]      This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in, out] ImageInfoSize      A pointer to the size, in bytes, of the ImageInfo buffer.\r
+                                     On input, this is the size of the buffer allocated by the caller.\r
+                                     On output, it is the size of the buffer returned by the firmware\r
+                                     if the buffer was large enough, or the size of the buffer needed\r
+                                     to contain the image(s) information if the buffer was too small.\r
+  @param[in, out] ImageInfo          A pointer to the buffer in which firmware places the current image(s)\r
+                                     information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r
+  @param[out]     DescriptorVersion  A pointer to the location in which firmware returns the version number\r
+                                     associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]     DescriptorCount    A pointer to the location in which firmware returns the number of\r
+                                     descriptors or firmware images within this device.\r
+  @param[out]     DescriptorSize     A pointer to the location in which firmware returns the size, in bytes,\r
+                                     of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out]     PackageVersion     A version number that represents all the firmware images in the device.\r
+                                     The format is vendor specific and new version must have a greater value\r
+                                     than the old version. If PackageVersion is not supported, the value is\r
+                                     0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r
+                                     is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r
+                                     that package version update is in progress.\r
+  @param[out]     PackageVersionName A pointer to a pointer to a null-terminated string representing the\r
+                                     package version name. The buffer is allocated by this function with\r
+                                     AllocatePool(), and it is the caller's responsibility to free it with a call\r
+                                     to FreePool().\r
+\r
+  @retval EFI_SUCCESS                The device was successfully updated with the new image.\r
+  @retval EFI_BUFFER_TOO_SMALL       The ImageInfo buffer was too small. The current buffer size\r
+                                     needed to hold the image(s) information is returned in ImageInfoSize.\r
+  @retval EFI_INVALID_PARAMETER      ImageInfoSize is NULL.\r
+  @retval EFI_DEVICE_ERROR           Valid information could not be returned. Possible corrupted image.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetImageInfo (\r
+  IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL       *This,\r
+  IN OUT    UINTN                           *ImageInfoSize,\r
+  IN OUT    EFI_FIRMWARE_IMAGE_DESCRIPTOR   *ImageInfo,\r
+  OUT       UINT32                          *DescriptorVersion,\r
+  OUT       UINT8                           *DescriptorCount,\r
+  OUT       UINTN                           *DescriptorSize,\r
+  OUT       UINT32                          *PackageVersion,\r
+  OUT       CHAR16                          **PackageVersionName\r
+  );\r
+\r
+/**\r
+  Retrieves a copy of the current firmware image of the device.\r
+\r
+  This function allows a copy of the current firmware image to be created and saved.\r
+  The saved copy could later been used, for example, in firmware image recovery or rollback.\r
+\r
+  @param[in]     This            A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]     ImageIndex      A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in,out] Image           Points to the buffer where the current image is copied to.\r
+  @param[in,out] ImageSize       On entry, points to the size of the buffer pointed to by Image, in bytes.\r
+                                 On return, points to the length of the image, in bytes.\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
+  @retval EFI_BUFFER_TOO_SMALL   The buffer specified by ImageSize is too small to hold the\r
+                                 image. The current buffer size needed to hold the image is returned\r
+                                 in ImageSize.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_NOT_FOUND          The current image is not copied to the buffer.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
+  IN  UINT8                             ImageIndex,\r
+  IN  OUT  VOID                         *Image,\r
+  IN  OUT  UINTN                        *ImageSize\r
+  );\r
+\r
+/**\r
+  Updates the firmware image of the device.\r
+\r
+  This function updates the hardware with the new firmware image.\r
+  This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
+  If the firmware image is updatable, the function should perform the following minimal validations\r
+  before proceeding to do the firmware image update.\r
+  - Validate the image authentication if image has attribute\r
+    IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
+    EFI_SECURITY_VIOLATION if the validation fails.\r
+  - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
+    the image is unsupported. The function can optionally provide more detailed information on\r
+    why the image is not a supported image.\r
+  - Validate the data from VendorCode if not null. Image validation must be performed before\r
+    VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
+    validation failed. The function returns EFI_ABORTED if the data is invalid.\r
+\r
+  VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
+  the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
+  a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
+  firmware image version is older than the current firmware image version or bad image checksum.\r
+  Sensitive operations such as those wiping the entire firmware image and render the device to be\r
+  non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
+  AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
+  reason to the caller.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in]  Image              Points to the new image.\r
+  @param[in]  ImageSize          Size of the new image in bytes.\r
+  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware image update policy.\r
+                                 Null indicates the caller did not specify the policy or use the default policy.\r
+  @param[in]  Progress           A function used by the driver to report the progress of the firmware update.\r
+  @param[out] AbortReason        A pointer to a pointer to a null-terminated string providing more\r
+                                 details for the aborted operation. The buffer is allocated by this function\r
+                                 with AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                 call to FreePool().\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
+  @retval EFI_ABORTED            The operation is aborted.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpSetImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL                 *This,\r
+  IN  UINT8                                            ImageIndex,\r
+  IN  CONST VOID                                       *Image,\r
+  IN  UINTN                                            ImageSize,\r
+  IN  CONST VOID                                       *VendorCode,\r
+  IN  EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS    Progress,\r
+  OUT CHAR16                                           **AbortReason\r
+  );\r
+\r
+/**\r
+  Checks if the firmware image is valid for the device.\r
+\r
+  This function allows firmware update application to validate the firmware image without\r
+  invoking the SetImage() first.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in]  Image              Points to the new image.\r
+  @param[in]  ImageSize          Size of the new image in bytes.\r
+  @param[out] ImageUpdatable     Indicates if the new image is valid for update. It also provides,\r
+                                 if available, additional information if the image is invalid.\r
+\r
+  @retval EFI_SUCCESS            The image was successfully checked.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpCheckImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL  *This,\r
+  IN  UINT8                             ImageIndex,\r
+  IN  CONST VOID                        *Image,\r
+  IN  UINTN                             ImageSize,\r
+  OUT UINT32                            *ImageUpdatable\r
+  );\r
+\r
+/**\r
+  Returns information about the firmware package.\r
+\r
+  This function returns package information.\r
+\r
+  @param[in]  This                     A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[out] PackageVersion           A version number that represents all the firmware images in the device.\r
+                                       The format is vendor specific and new version must have a greater value\r
+                                       than the old version. If PackageVersion is not supported, the value is\r
+                                       0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
+                                       comparison is to be performed using PackageVersionName. A value of\r
+                                       0xFFFFFFFD indicates that package version update is in progress.\r
+  @param[out] PackageVersionName       A pointer to a pointer to a null-terminated string representing\r
+                                       the package version name. The buffer is allocated by this function with\r
+                                       AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                       call to FreePool().\r
+  @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
+                                       package version name. A value of 0 indicates the device does not support\r
+                                       update of package version name. Length is the number of Unicode characters,\r
+                                       including the terminating null character.\r
+  @param[out] AttributesSupported      Package attributes that are supported by this device. See 'Package Attribute\r
+                                       Definitions' for possible returned values of this parameter. A value of 1\r
+                                       indicates the attribute is supported and the current setting value is\r
+                                       indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
+                                       supported and the current setting value in AttributesSetting is meaningless.\r
+  @param[out] AttributesSetting        Package attributes. See 'Package Attribute Definitions' for possible returned\r
+                                       values of this parameter\r
+\r
+  @retval EFI_SUCCESS                  The package information was successfully returned.\r
+  @retval EFI_UNSUPPORTED              The operation is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpGetPackageInfo (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
+  OUT UINT32                           *PackageVersion,\r
+  OUT CHAR16                           **PackageVersionName,\r
+  OUT UINT32                           *PackageVersionNameMaxLen,\r
+  OUT UINT64                           *AttributesSupported,\r
+  OUT UINT64                           *AttributesSetting\r
+  );\r
+\r
+/**\r
+  Updates information about the firmware package.\r
+\r
+  This function updates package information.\r
+  This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
+  VendorCode enables vendor to implement vendor-specific package information update policy.\r
+  Null if the caller did not specify this policy or use the default policy.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  Image              Points to the authentication image.\r
+                                 Null if authentication is not required.\r
+  @param[in]  ImageSize          Size of the authentication image in bytes.\r
+                                 0 if authentication is not required.\r
+  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware\r
+                                 image update policy.\r
+                                 Null indicates the caller did not specify this policy or use\r
+                                 the default policy.\r
+  @param[in]  PackageVersion     The new package version.\r
+  @param[in]  PackageVersionName A pointer to the new null-terminated Unicode string representing\r
+                                 the package version name.\r
+                                 The string length is equal to or less than the value returned in\r
+                                 PackageVersionNameMaxLen.\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new package\r
+                                 information.\r
+  @retval EFI_INVALID_PARAMETER  The PackageVersionName length is longer than the value\r
+                                 returned in PackageVersionNameMaxLen.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpSetPackageInfo (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL   *This,\r
+  IN  CONST VOID                         *Image,\r
+  IN  UINTN                              ImageSize,\r
+  IN  CONST VOID                         *VendorCode,\r
+  IN  UINT32                             PackageVersion,\r
+  IN  CONST CHAR16                       *PackageVersionName\r
+  );\r
+\r
+/**\r
+  Initialize SystemFmpDriver private data structure.\r
+\r
+  @param[in] SystemFmpPrivate  private data structure to be initialized.\r
+\r
+  @return EFI_SUCCESS private data is initialized.\r
+**/\r
+EFI_STATUS\r
+InitializePrivateData (\r
+  IN SYSTEM_FMP_PRIVATE_DATA  *SystemFmpPrivate\r
+  );\r
+\r
+extern EFI_GUID gSystemFmpLastAttemptVariableGuid;\r
+extern EFI_GUID mCurrentImageTypeId;\r
+extern EFI_GUID gSystemFmpProtocolGuid;\r
+\r
+#endif\r
+\r
diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.c b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.c
new file mode 100644 (file)
index 0000000..9d5832f
--- /dev/null
@@ -0,0 +1,262 @@
+/** @file\r
+  SetImage instance to report system firmware and act as agent to system update.\r
+\r
+  Caution: This module requires additional review when modified.\r
+  This module will have external input - capsule image.\r
+  This external input must be validated carefully to avoid security issue like\r
+  buffer overflow, integer overflow.\r
+\r
+  FmpSetImage() will receive untrusted input and do basic validation.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "SystemFirmwareDxe.h"\r
+\r
+//\r
+// SystemFmp driver private data\r
+//\r
+SYSTEM_FMP_PRIVATE_DATA *mSystemFmpPrivate = NULL;\r
+\r
+/**\r
+  Dispatch system FMP images.\r
+\r
+  Caution: This function may receive untrusted input.\r
+\r
+  @param[in]  Image              The EDKII system FMP capsule image.\r
+  @param[in]  ImageSize          The size of the EDKII system FMP capsule image in bytes.\r
+  @param[out] LastAttemptVersion The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out] LastAttemptStatus  The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+\r
+  @retval EFI_SUCESS            Process Capsule Image successfully.\r
+  @retval EFI_UNSUPPORTED       Capsule image is not supported by the firmware.\r
+  @retval EFI_VOLUME_CORRUPTED  FV volume in the capsule is corrupted.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough memory.\r
+**/\r
+EFI_STATUS\r
+DispatchSystemFmpImages (\r
+  IN VOID                         *Image,\r
+  IN UINTN                        ImageSize,\r
+  OUT UINT32                      *LastAttemptVersion,\r
+  OUT UINT32                      *LastAttemptStatus\r
+  )\r
+{\r
+  EFI_STATUS                                    Status;\r
+  VOID                                          *AuthenticatedImage;\r
+  UINTN                                         AuthenticatedImageSize;\r
+  VOID                                          *DispatchFvImage;\r
+  UINTN                                         DispatchFvImageSize;\r
+  EFI_HANDLE                                    FvProtocolHandle;\r
+  EFI_FIRMWARE_VOLUME_HEADER                    *FvImage;\r
+  BOOLEAN                                       Result;\r
+\r
+  DEBUG((DEBUG_INFO, "DispatchSystemFmpImages\n"));\r
+\r
+  //\r
+  // Verify\r
+  //\r
+  Status = CapsuleAuthenticateSystemFirmware(Image, ImageSize, FALSE, LastAttemptVersion, LastAttemptStatus, &AuthenticatedImage, &AuthenticatedImageSize);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticateImage - %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Get FV\r
+  //\r
+  Result = ExtractDriverFvImage(AuthenticatedImage, AuthenticatedImageSize, &DispatchFvImage, &DispatchFvImageSize);\r
+  if (Result) {\r
+    DEBUG((DEBUG_INFO, "ExtractDriverFvImage\n"));\r
+    //\r
+    // Dispatch\r
+    //\r
+    if (((EFI_FIRMWARE_VOLUME_HEADER *)DispatchFvImage)->FvLength == DispatchFvImageSize) {\r
+      FvImage = AllocatePages(EFI_SIZE_TO_PAGES(DispatchFvImageSize));\r
+      if (FvImage != NULL) {\r
+        CopyMem(FvImage, DispatchFvImage, DispatchFvImageSize);\r
+        Status = gDS->ProcessFirmwareVolume(\r
+                        (VOID *)FvImage,\r
+                        (UINTN)FvImage->FvLength,\r
+                        &FvProtocolHandle\r
+                        );\r
+        DEBUG((DEBUG_INFO, "ProcessFirmwareVolume - %r\n", Status));\r
+        if (!EFI_ERROR(Status)) {\r
+          gDS->Dispatch();\r
+          DEBUG((DEBUG_INFO, "Dispatch Done\n"));\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Updates the firmware image of the device.\r
+\r
+  This function updates the hardware with the new firmware image.\r
+  This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
+  If the firmware image is updatable, the function should perform the following minimal validations\r
+  before proceeding to do the firmware image update.\r
+  - Validate the image authentication if image has attribute\r
+    IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
+    EFI_SECURITY_VIOLATION if the validation fails.\r
+  - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
+    the image is unsupported. The function can optionally provide more detailed information on\r
+    why the image is not a supported image.\r
+  - Validate the data from VendorCode if not null. Image validation must be performed before\r
+    VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
+    validation failed. The function returns EFI_ABORTED if the data is invalid.\r
+\r
+  VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
+  the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
+  a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
+  firmware image version is older than the current firmware image version or bad image checksum.\r
+  Sensitive operations such as those wiping the entire firmware image and render the device to be\r
+  non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
+  AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
+  reason to the caller.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in]  Image              Points to the new image.\r
+  @param[in]  ImageSize          Size of the new image in bytes.\r
+  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware image update policy.\r
+                                 Null indicates the caller did not specify the policy or use the default policy.\r
+  @param[in]  Progress           A function used by the driver to report the progress of the firmware update.\r
+  @param[out] AbortReason        A pointer to a pointer to a null-terminated string providing more\r
+                                 details for the aborted operation. The buffer is allocated by this function\r
+                                 with AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                 call to FreePool().\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
+  @retval EFI_ABORTED            The operation is aborted.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpSetImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL                 *This,\r
+  IN  UINT8                                            ImageIndex,\r
+  IN  CONST VOID                                       *Image,\r
+  IN  UINTN                                            ImageSize,\r
+  IN  CONST VOID                                       *VendorCode,\r
+  IN  EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS    Progress,\r
+  OUT CHAR16                                           **AbortReason\r
+  )\r
+{\r
+  SYSTEM_FMP_PRIVATE_DATA             *SystemFmpPrivate;\r
+  EFI_FIRMWARE_MANAGEMENT_PROTOCOL    *SystemFmp;\r
+  EFI_STATUS                          Status;\r
+  EFI_STATUS                          VarStatus;\r
+\r
+  if (Image == NULL || ImageSize == 0 || AbortReason == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(This);\r
+  *AbortReason     = NULL;\r
+\r
+  if (ImageIndex == 0 || ImageIndex > SystemFmpPrivate->DescriptorCount) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Process FV\r
+  //\r
+  Status = DispatchSystemFmpImages((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus);\r
+  DEBUG((DEBUG_INFO, "(Agent)SetImage - LastAttemp Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));\r
+  if (EFI_ERROR(Status)) {\r
+    VarStatus = gRT->SetVariable(\r
+                       SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
+                       &gSystemFmpLastAttemptVariableGuid,\r
+                       EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                       sizeof(SystemFmpPrivate->LastAttempt),\r
+                       &SystemFmpPrivate->LastAttempt\r
+                       );\r
+    DEBUG((DEBUG_INFO, "(Agent)SetLastAttemp - %r\n", VarStatus));\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Pass Thru\r
+  //\r
+  Status = gBS->LocateProtocol(&gSystemFmpProtocolGuid, NULL, (VOID **)&SystemFmp);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((DEBUG_INFO, "(Agent)SetImage - SystemFmpProtocol - %r\n", Status));\r
+    SystemFmpPrivate->LastAttempt.LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;\r
+    VarStatus = gRT->SetVariable(\r
+                       SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
+                       &gSystemFmpLastAttemptVariableGuid,\r
+                       EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                       sizeof(SystemFmpPrivate->LastAttempt),\r
+                       &SystemFmpPrivate->LastAttempt\r
+                       );\r
+    DEBUG((DEBUG_INFO, "(Agent)SetLastAttemp - %r\n", VarStatus));\r
+    return Status;\r
+  }\r
+\r
+  return SystemFmp->SetImage(SystemFmp, ImageIndex, Image, ImageSize, VendorCode, Progress, AbortReason);\r
+}\r
+\r
+/**\r
+  System FMP module entrypoint\r
+\r
+  @param[in]  ImageHandle       The firmware allocated handle for the EFI image.\r
+  @param[in]  SystemTable       A pointer to the EFI System Table.\r
+\r
+  @return EFI_SUCCESS System FMP module is initialized.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SystemFirmwareReportMainDxe (\r
+  IN EFI_HANDLE                         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                                      Status;\r
+\r
+  //\r
+  // Initialize SystemFmpPrivateData\r
+  //\r
+  mSystemFmpPrivate = AllocateZeroPool (sizeof(SYSTEM_FMP_PRIVATE_DATA));\r
+  if (mSystemFmpPrivate == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = InitializePrivateData(mSystemFmpPrivate);\r
+  if (EFI_ERROR(Status)) {\r
+    FreePool(mSystemFmpPrivate);\r
+    mSystemFmpPrivate = NULL;\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Install FMP protocol.\r
+  //\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &mSystemFmpPrivate->Handle,\r
+                  &gEfiFirmwareManagementProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mSystemFmpPrivate->Fmp\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool(mSystemFmpPrivate);\r
+    mSystemFmpPrivate = NULL;\r
+    return Status;\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.inf b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.inf
new file mode 100644 (file)
index 0000000..89a86ff
--- /dev/null
@@ -0,0 +1,69 @@
+## @file\r
+# SystemFirmware FMP report driver.\r
+#\r
+# Produce FMP instance to report system firmware EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+#\r
+#  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SystemFirmwareReportDxe\r
+  MODULE_UNI_FILE                = SystemFirmwareReportDxe.uni\r
+  FILE_GUID                      = BC1A046C-7DBD-41F2-94E5-D7595554CAF4\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = SystemFirmwareReportMainDxe\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = X64\r
+#\r
+\r
+[Sources]\r
+  SystemFirmwareCommonDxe.c\r
+  SystemFirmwareReportDxe.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  SignedCapsulePkg/SignedCapsulePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  UefiLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  PcdLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  HobLib\r
+  UefiRuntimeServicesTableLib\r
+  UefiDriverEntryPoint\r
+  DxeServicesLib\r
+  DxeServicesTableLib\r
+  PrintLib\r
+  EdkiiSystemCapsuleLib\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid  ## CONSUMES\r
+  gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareImageDescriptor    ## CONSUMES\r
+\r
+[Protocols]\r
+  gEfiFirmwareManagementProtocolGuid     ## PRODUCES\r
+\r
+[Depex]\r
+  gEfiVariableArchProtocolGuid\r
+\r
+[UserExtensions.TianoCore."ExtraFiles"]\r
+  SystemFirmwareReportDxeExtra.uni\r
+\r
diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.uni b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.uni
new file mode 100644 (file)
index 0000000..34edeba
--- /dev/null
@@ -0,0 +1,21 @@
+// /** @file\r
+// SystemFirmware FMP report driver.\r
+//\r
+// Produce FMP instance to report system firmware EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+//\r
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "SystemFirmware FMP report driver."\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "Produce FMP instance to report system firmware EFI_FIRMWARE_IMAGE_DESCRIPTOR."\r
diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxeExtra.uni b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxeExtra.uni
new file mode 100644 (file)
index 0000000..212134d
--- /dev/null
@@ -0,0 +1,20 @@
+// /** @file\r
+// SystemFirmwareReportDxe Localized Strings and Content\r
+//\r
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+#string STR_PROPERTIES_MODULE_NAME\r
+#language en-US\r
+"SystemFirmwareReport DXE Driver"\r
+\r
+\r
diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.c b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.c
new file mode 100644 (file)
index 0000000..ae783ff
--- /dev/null
@@ -0,0 +1,526 @@
+/** @file\r
+  SetImage instance to update system firmware.\r
+\r
+  Caution: This module requires additional review when modified.\r
+  This module will have external input - capsule image.\r
+  This external input must be validated carefully to avoid security issue like\r
+  buffer overflow, integer overflow.\r
+\r
+  FmpSetImage() will receive untrusted input and do basic validation.\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "SystemFirmwareDxe.h"\r
+\r
+//\r
+// SystemFmp driver private data\r
+//\r
+SYSTEM_FMP_PRIVATE_DATA *mSystemFmpPrivate = NULL;\r
+\r
+EFI_GUID mCurrentImageTypeId;\r
+\r
+BOOLEAN  mNvRamUpdated = FALSE;\r
+\r
+/**\r
+  Parse Config data file to get the updated data array.\r
+\r
+  @param[in]      DataBuffer      Config raw file buffer.\r
+  @param[in]      BufferSize      Size of raw buffer.\r
+  @param[in, out] ConfigHeader    Pointer to the config header.\r
+  @param[in, out] UpdateArray     Pointer to the config of update data.\r
+\r
+  @retval EFI_NOT_FOUND         No config data is found.\r
+  @retval EFI_OUT_OF_RESOURCES  No enough memory is allocated.\r
+  @retval EFI_SUCCESS           Parse the config file successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+ParseUpdateDataFile (\r
+  IN      UINT8                         *DataBuffer,\r
+  IN      UINTN                         BufferSize,\r
+  IN OUT  CONFIG_HEADER                 *ConfigHeader,\r
+  IN OUT  UPDATE_CONFIG_DATA            **UpdateArray\r
+  );\r
+\r
+/**\r
+  Update System Firmware image component.\r
+\r
+  @param[in]  SystemFirmwareImage     Points to the System Firmware image.\r
+  @param[in]  SystemFirmwareImageSize The length of the System Firmware image in bytes.\r
+  @param[in]  ConfigData              Points to the component configuration structure.\r
+  @param[out] LastAttemptVersion      The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out] LastAttemptStatus       The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+\r
+  @retval EFI_SUCCESS             The System Firmware image is updated.\r
+  @retval EFI_WRITE_PROTECTED     The flash device is read only.\r
+**/\r
+EFI_STATUS\r
+PerformUpdate (\r
+  IN VOID                         *SystemFirmwareImage,\r
+  IN UINTN                        SystemFirmwareImageSize,\r
+  IN UPDATE_CONFIG_DATA           *ConfigData,\r
+  OUT UINT32                      *LastAttemptVersion,\r
+  OUT UINT32                      *LastAttemptStatus\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+\r
+  DEBUG((DEBUG_INFO, "PlatformUpdate:"));\r
+  DEBUG((DEBUG_INFO, "  BaseAddress - 0x%lx,", ConfigData->BaseAddress));\r
+  DEBUG((DEBUG_INFO, "  ImageOffset - 0x%x,", ConfigData->ImageOffset));\r
+  DEBUG((DEBUG_INFO, "  Legnth - 0x%x\n", ConfigData->Length));\r
+  Status = PerformFlashWrite (\r
+             ConfigData->FirmwareType,\r
+             ConfigData->BaseAddress,\r
+             ConfigData->AddressType,\r
+             (VOID *)((UINTN)SystemFirmwareImage + (UINTN)ConfigData->ImageOffset),\r
+             ConfigData->Length\r
+             );\r
+  if (!EFI_ERROR(Status)) {\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
+    if (ConfigData->FirmwareType == PlatformFirmwareTypeNvRam) {\r
+      mNvRamUpdated = TRUE;\r
+    }\r
+  } else {\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;\r
+  }\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Update System Firmware image.\r
+\r
+  @param[in]  SystemFirmwareImage     Points to the System Firmware image.\r
+  @param[in]  SystemFirmwareImageSize The length of the System Firmware image in bytes.\r
+  @param[in]  ConfigImage             Points to the config file image.\r
+  @param[in]  ConfigImageSize         The length of the config file image in bytes.\r
+  @param[out] LastAttemptVersion      The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out] LastAttemptStatus       The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+\r
+  @retval EFI_SUCCESS             The System Firmware image is updated.\r
+  @retval EFI_WRITE_PROTECTED     The flash device is read only.\r
+**/\r
+EFI_STATUS\r
+UpdateImage (\r
+  IN VOID                         *SystemFirmwareImage,\r
+  IN UINTN                        SystemFirmwareImageSize,\r
+  IN VOID                         *ConfigImage,\r
+  IN UINTN                        ConfigImageSize,\r
+  OUT UINT32                      *LastAttemptVersion,\r
+  OUT UINT32                      *LastAttemptStatus\r
+  )\r
+{\r
+  EFI_STATUS                            Status;\r
+  UPDATE_CONFIG_DATA                    *ConfigData;\r
+  UPDATE_CONFIG_DATA                    *UpdateConfigData;\r
+  CONFIG_HEADER                         ConfigHeader;\r
+  UINTN                                 Index;\r
+\r
+  if (ConfigImage == NULL) {\r
+    DEBUG((DEBUG_INFO, "PlatformUpdate (NoConfig):"));\r
+    DEBUG((DEBUG_INFO, "  BaseAddress - 0x%x,", 0));\r
+    DEBUG((DEBUG_INFO, "  Length - 0x%x\n", SystemFirmwareImageSize));\r
+    // ASSUME the whole System Firmware include NVRAM region.\r
+    Status = PerformFlashWrite (\r
+               PlatformFirmwareTypeNvRam,\r
+               0,\r
+               FlashAddressTypeRelativeAddress,\r
+               SystemFirmwareImage,\r
+               SystemFirmwareImageSize\r
+               );\r
+    if (!EFI_ERROR(Status)) {\r
+      *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;\r
+      mNvRamUpdated = TRUE;\r
+    } else {\r
+      *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;\r
+    }\r
+    return Status;\r
+  }\r
+\r
+  DEBUG((DEBUG_INFO, "PlatformUpdate (With Config):\n"));\r
+  ConfigData        = NULL;\r
+  ZeroMem (&ConfigHeader, sizeof(ConfigHeader));\r
+  Status            = ParseUpdateDataFile (\r
+                        ConfigImage,\r
+                        ConfigImageSize,\r
+                        &ConfigHeader,\r
+                        &ConfigData\r
+                        );\r
+  DEBUG((DEBUG_INFO, "ParseUpdateDataFile - %r\n", Status));\r
+  if (EFI_ERROR(Status)) {\r
+    *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  DEBUG((DEBUG_INFO, "ConfigHeader.NumOfUpdates - 0x%x\n", ConfigHeader.NumOfUpdates));\r
+  DEBUG((DEBUG_INFO, "PcdEdkiiSystemFirmwareFileGuid - %g\n", PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid)));\r
+\r
+  Index = 0;\r
+  UpdateConfigData = ConfigData;\r
+  while (Index < ConfigHeader.NumOfUpdates) {\r
+    if (CompareGuid(&UpdateConfigData->FileGuid, PcdGetPtr(PcdEdkiiSystemFirmwareFileGuid))) {\r
+      DEBUG((DEBUG_INFO, "FileGuid - %g (processing)\n", &UpdateConfigData->FileGuid));\r
+      Status = PerformUpdate (\r
+                 SystemFirmwareImage,\r
+                 SystemFirmwareImageSize,\r
+                 UpdateConfigData,\r
+                 LastAttemptVersion,\r
+                 LastAttemptStatus\r
+                 );\r
+      //\r
+      // Shall updates be serialized so that if an update is not successfully completed,\r
+      // the remaining updates won't be performed.\r
+      //\r
+      if (EFI_ERROR (Status)) {\r
+        break;\r
+      }\r
+    } else {\r
+      DEBUG((DEBUG_INFO, "FileGuid - %g (ignored)\n", &UpdateConfigData->FileGuid));\r
+    }\r
+\r
+    Index++;\r
+    UpdateConfigData++;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Authenticate and update System Firmware image.\r
+\r
+  Caution: This function may receive untrusted input.\r
+\r
+  @param[in]  Image              The EDKII system FMP capsule image.\r
+  @param[in]  ImageSize          The size of the EDKII system FMP capsule image in bytes.\r
+  @param[out] LastAttemptVersion The last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+  @param[out] LastAttemptStatus  The last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
+\r
+  @retval EFI_SUCCESS             EDKII system FMP capsule passes authentication and the System Firmware image is updated.\r
+  @retval EFI_SECURITY_VIOLATION  EDKII system FMP capsule fails authentication and the System Firmware image is not updated.\r
+  @retval EFI_WRITE_PROTECTED     The flash device is read only.\r
+**/\r
+EFI_STATUS\r
+SystemFirmwareAuthenticatedUpdate (\r
+  IN VOID                         *Image,\r
+  IN UINTN                        ImageSize,\r
+  OUT UINT32                      *LastAttemptVersion,\r
+  OUT UINT32                      *LastAttemptStatus\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  VOID                        *SystemFirmwareImage;\r
+  UINTN                       SystemFirmwareImageSize;\r
+  VOID                        *ConfigImage;\r
+  UINTN                       ConfigImageSize;\r
+  VOID                        *AuthenticatedImage;\r
+  UINTN                       AuthenticatedImageSize;\r
+\r
+  DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticatedUpdate...\n"));\r
+\r
+  Status = CapsuleAuthenticateSystemFirmware(Image, ImageSize, FALSE, LastAttemptVersion, LastAttemptStatus, &AuthenticatedImage, &AuthenticatedImageSize);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticateImage - %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  DEBUG((DEBUG_INFO, "ExtractSystemFirmwareImage ...\n"));\r
+  ExtractSystemFirmwareImage(AuthenticatedImage, AuthenticatedImageSize, &SystemFirmwareImage, &SystemFirmwareImageSize);\r
+  DEBUG((DEBUG_INFO, "ExtractConfigImage ...\n"));\r
+  ExtractConfigImage(AuthenticatedImage, AuthenticatedImageSize, &ConfigImage, &ConfigImageSize);\r
+\r
+  DEBUG((DEBUG_INFO, "UpdateImage ...\n"));\r
+  Status = UpdateImage(SystemFirmwareImage, SystemFirmwareImageSize, ConfigImage, ConfigImageSize, LastAttemptVersion, LastAttemptStatus);\r
+  if (EFI_ERROR(Status)) {\r
+    DEBUG((DEBUG_INFO, "UpdateImage - %r\n", Status));\r
+    return Status;\r
+  }\r
+\r
+  DEBUG((DEBUG_INFO, "SystemFirmwareAuthenticatedUpdate Done\n"));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+\r
+  This code finds variable in storage blocks (Volatile or Non-Volatile).\r
+\r
+  @param[in]      VariableName               Name of Variable to be found.\r
+  @param[in]      VendorGuid                 Variable vendor GUID.\r
+  @param[out]     Attributes                 Attribute value of the variable found.\r
+  @param[in, out] DataSize                   Size of Data found. If size is less than the\r
+                                             data, this value contains the required size.\r
+  @param[out]     Data                       Data pointer.\r
+\r
+  @return EFI_INVALID_PARAMETER     Invalid parameter.\r
+  @return EFI_SUCCESS               Find the specified variable.\r
+  @return EFI_NOT_FOUND             Not found.\r
+  @return EFI_BUFFER_TO_SMALL       DataSize is too small for the result.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetVariableHook (\r
+  IN      CHAR16            *VariableName,\r
+  IN      EFI_GUID          *VendorGuid,\r
+  OUT     UINT32            *Attributes OPTIONAL,\r
+  IN OUT  UINTN             *DataSize,\r
+  OUT     VOID              *Data\r
+  )\r
+{\r
+  DEBUG((DEBUG_INFO, "GetVariableHook - %S, %g\n", VariableName, VendorGuid));\r
+  return EFI_NOT_AVAILABLE_YET;\r
+}\r
+\r
+/**\r
+\r
+  This code Finds the Next available variable.\r
+\r
+  @param[in, out] VariableNameSize           Size of the variable name.\r
+  @param[in, out] VariableName               Pointer to variable name.\r
+  @param[in, out] VendorGuid                 Variable Vendor Guid.\r
+\r
+  @return EFI_INVALID_PARAMETER     Invalid parameter.\r
+  @return EFI_SUCCESS               Find the specified variable.\r
+  @return EFI_NOT_FOUND             Not found.\r
+  @return EFI_BUFFER_TO_SMALL       DataSize is too small for the result.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetNextVariableNameHook (\r
+  IN OUT  UINTN             *VariableNameSize,\r
+  IN OUT  CHAR16            *VariableName,\r
+  IN OUT  EFI_GUID          *VendorGuid\r
+  )\r
+{\r
+  DEBUG((DEBUG_INFO, "GetNextVariableNameHook - %S, %g\n", VariableName, VendorGuid));\r
+  return EFI_NOT_AVAILABLE_YET;\r
+}\r
+\r
+/**\r
+\r
+  This code sets variable in storage blocks (Volatile or Non-Volatile).\r
+\r
+  @param[in] VariableName                     Name of Variable to be found.\r
+  @param[in] VendorGuid                       Variable vendor GUID.\r
+  @param[in] Attributes                       Attribute value of the variable found\r
+  @param[in] DataSize                         Size of Data found. If size is less than the\r
+                                              data, this value contains the required size.\r
+  @param[in] Data                             Data pointer.\r
+\r
+  @return EFI_INVALID_PARAMETER           Invalid parameter.\r
+  @return EFI_SUCCESS                     Set successfully.\r
+  @return EFI_OUT_OF_RESOURCES            Resource not enough to set variable.\r
+  @return EFI_NOT_FOUND                   Not found.\r
+  @return EFI_WRITE_PROTECTED             Variable is read-only.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetVariableHook (\r
+  IN CHAR16                  *VariableName,\r
+  IN EFI_GUID                *VendorGuid,\r
+  IN UINT32                  Attributes,\r
+  IN UINTN                   DataSize,\r
+  IN VOID                    *Data\r
+  )\r
+{\r
+  DEBUG((DEBUG_INFO, "SetVariableHook - %S, %g, 0x%x (0x%x)\n", VariableName, VendorGuid, Attributes, DataSize));\r
+  return EFI_NOT_AVAILABLE_YET;\r
+}\r
+\r
+/**\r
+\r
+  This code returns information about the EFI variables.\r
+\r
+  @param[in]  Attributes                     Attributes bitmask to specify the type of variables\r
+                                             on which to return information.\r
+  @param[out] MaximumVariableStorageSize     Pointer to the maximum size of the storage space available\r
+                                             for the EFI variables associated with the attributes specified.\r
+  @param[out] RemainingVariableStorageSize   Pointer to the remaining size of the storage space available\r
+                                             for EFI variables associated with the attributes specified.\r
+  @param[out] MaximumVariableSize            Pointer to the maximum size of an individual EFI variables\r
+                                             associated with the attributes specified.\r
+\r
+  @return EFI_SUCCESS                   Query successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+QueryVariableInfoHook (\r
+  IN  UINT32                 Attributes,\r
+  OUT UINT64                 *MaximumVariableStorageSize,\r
+  OUT UINT64                 *RemainingVariableStorageSize,\r
+  OUT UINT64                 *MaximumVariableSize\r
+  )\r
+{\r
+  DEBUG((DEBUG_INFO, "QueryVariableInfoHook - 0x%x\n", Attributes));\r
+  return EFI_NOT_AVAILABLE_YET;\r
+}\r
+\r
+/**\r
+  Updates the firmware image of the device.\r
+\r
+  This function updates the hardware with the new firmware image.\r
+  This function returns EFI_UNSUPPORTED if the firmware image is not updatable.\r
+  If the firmware image is updatable, the function should perform the following minimal validations\r
+  before proceeding to do the firmware image update.\r
+  - Validate the image authentication if image has attribute\r
+    IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns\r
+    EFI_SECURITY_VIOLATION if the validation fails.\r
+  - Validate the image is a supported image for this device. The function returns EFI_ABORTED if\r
+    the image is unsupported. The function can optionally provide more detailed information on\r
+    why the image is not a supported image.\r
+  - Validate the data from VendorCode if not null. Image validation must be performed before\r
+    VendorCode data validation. VendorCode data is ignored or considered invalid if image\r
+    validation failed. The function returns EFI_ABORTED if the data is invalid.\r
+\r
+  VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if\r
+  the caller did not specify the policy or use the default policy. As an example, vendor can implement\r
+  a policy to allow an option to force a firmware image update when the abort reason is due to the new\r
+  firmware image version is older than the current firmware image version or bad image checksum.\r
+  Sensitive operations such as those wiping the entire firmware image and render the device to be\r
+  non-functional should be encoded in the image itself rather than passed with the VendorCode.\r
+  AbortReason enables vendor to have the option to provide a more detailed description of the abort\r
+  reason to the caller.\r
+\r
+  @param[in]  This               A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
+  @param[in]  ImageIndex         A unique number identifying the firmware image(s) within the device.\r
+                                 The number is between 1 and DescriptorCount.\r
+  @param[in]  Image              Points to the new image.\r
+  @param[in]  ImageSize          Size of the new image in bytes.\r
+  @param[in]  VendorCode         This enables vendor to implement vendor-specific firmware image update policy.\r
+                                 Null indicates the caller did not specify the policy or use the default policy.\r
+  @param[in]  Progress           A function used by the driver to report the progress of the firmware update.\r
+  @param[out] AbortReason        A pointer to a pointer to a null-terminated string providing more\r
+                                 details for the aborted operation. The buffer is allocated by this function\r
+                                 with AllocatePool(), and it is the caller's responsibility to free it with a\r
+                                 call to FreePool().\r
+\r
+  @retval EFI_SUCCESS            The device was successfully updated with the new image.\r
+  @retval EFI_ABORTED            The operation is aborted.\r
+  @retval EFI_INVALID_PARAMETER  The Image was NULL.\r
+  @retval EFI_UNSUPPORTED        The operation is not supported.\r
+  @retval EFI_SECURITY_VIOLATIO  The operation could not be performed due to an authentication failure.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FmpSetImage (\r
+  IN  EFI_FIRMWARE_MANAGEMENT_PROTOCOL                 *This,\r
+  IN  UINT8                                            ImageIndex,\r
+  IN  CONST VOID                                       *Image,\r
+  IN  UINTN                                            ImageSize,\r
+  IN  CONST VOID                                       *VendorCode,\r
+  IN  EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS    Progress,\r
+  OUT CHAR16                                           **AbortReason\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_STATUS              VarStatus;\r
+  SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate;\r
+\r
+  if (Image == NULL || ImageSize == 0 || AbortReason == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(This);\r
+  *AbortReason     = NULL;\r
+\r
+  if (ImageIndex == 0 || ImageIndex > SystemFmpPrivate->DescriptorCount) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = SystemFirmwareAuthenticatedUpdate((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus);\r
+  DEBUG((DEBUG_INFO, "SetImage - LastAttemp Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));\r
+\r
+  //\r
+  // If NVRAM is updated, we should no longer touch variable services, because\r
+  // the current variable driver may not manage the new NVRAM region.\r
+  //\r
+  if (mNvRamUpdated) {\r
+    DEBUG ((DEBUG_INFO, "NvRamUpdated, Update Variable Serivces\n"));\r
+    gRT->GetVariable         = GetVariableHook;\r
+    gRT->GetNextVariableName = GetNextVariableNameHook;\r
+    gRT->SetVariable         = SetVariableHook;\r
+    gRT->QueryVariableInfo   = QueryVariableInfoHook;\r
+\r
+    gRT->Hdr.CRC32 = 0;\r
+    gBS->CalculateCrc32 (\r
+          (UINT8 *) &gRT->Hdr,\r
+          gRT->Hdr.HeaderSize,\r
+          &gRT->Hdr.CRC32\r
+          );\r
+  }\r
+\r
+  VarStatus = gRT->SetVariable(\r
+                     SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
+                     &gSystemFmpLastAttemptVariableGuid,\r
+                     EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                     sizeof(SystemFmpPrivate->LastAttempt),\r
+                     &SystemFmpPrivate->LastAttempt\r
+                     );\r
+  DEBUG((DEBUG_INFO, "SetLastAttemp - %r\n", VarStatus));\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  System FMP module entrypoint\r
+\r
+  @param  ImageHandle       The firmware allocated handle for the EFI image.\r
+  @param  SystemTable       A pointer to the EFI System Table.\r
+\r
+  @return EFI_SUCCESS System FMP module is initialized.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SystemFirmwareUpdateMainDxe (\r
+  IN EFI_HANDLE                         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                                      Status;\r
+\r
+  //\r
+  // Initialize SystemFmpPrivateData\r
+  //\r
+  mSystemFmpPrivate = AllocateZeroPool (sizeof(SYSTEM_FMP_PRIVATE_DATA));\r
+  if (mSystemFmpPrivate == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = InitializePrivateData(mSystemFmpPrivate);\r
+  if (EFI_ERROR(Status)) {\r
+    FreePool(mSystemFmpPrivate);\r
+    mSystemFmpPrivate = NULL;\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Install FMP protocol.\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &mSystemFmpPrivate->Handle,\r
+                  &gEfiFirmwareManagementProtocolGuid,\r
+                  &mSystemFmpPrivate->Fmp,\r
+                  &gSystemFmpProtocolGuid,\r
+                  &mSystemFmpPrivate->Fmp,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool(mSystemFmpPrivate);\r
+    mSystemFmpPrivate = NULL;\r
+    return Status;\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.inf b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.inf
new file mode 100644 (file)
index 0000000..7a6ca54
--- /dev/null
@@ -0,0 +1,72 @@
+## @file\r
+# SystemFirmware FMP update driver.\r
+#\r
+# Produce FMP instance to update system firmware.\r
+#\r
+#  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SystemFirmwareUpdateDxe\r
+  MODULE_UNI_FILE                = SystemFirmwareUpdateDxe.uni\r
+  FILE_GUID                      = 0A2FBD15-1C25-407E-8915-60C5652BC2AA\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = SystemFirmwareUpdateMainDxe\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = X64\r
+#\r
+\r
+[Sources]\r
+  SystemFirmwareCommonDxe.c\r
+  SystemFirmwareUpdateDxe.c\r
+  ParseConfigProfile.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  SignedCapsulePkg/SignedCapsulePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  UefiLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  PcdLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  HobLib\r
+  UefiRuntimeServicesTableLib\r
+  UefiDriverEntryPoint\r
+  DxeServicesLib\r
+  EdkiiSystemCapsuleLib\r
+  PlatformFlashAccessLib\r
+  IniParsingLib\r
+  PrintLib\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid           ## CONSUMES\r
+  gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareFileGuid           ## CONSUMES\r
+  gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareImageDescriptor    ## CONSUMES\r
+\r
+[Protocols]\r
+  gEfiFirmwareManagementProtocolGuid     ## PRODUCES\r
+\r
+[Depex]\r
+  gEfiVariableArchProtocolGuid\r
+\r
+[UserExtensions.TianoCore."ExtraFiles"]\r
+  SystemFirmwareUpdateDxeExtra.uni\r
+\r
diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.uni b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.uni
new file mode 100644 (file)
index 0000000..40eb154
--- /dev/null
@@ -0,0 +1,21 @@
+// /** @file\r
+// SystemFirmware FMP update driver.\r
+//\r
+// Produce FMP instance to update system firmware.\r
+//\r
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "SystemFirmware FMP update driver."\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "Produce FMP instance to update system firmware."\r
diff --git a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxeExtra.uni b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxeExtra.uni
new file mode 100644 (file)
index 0000000..6588abc
--- /dev/null
@@ -0,0 +1,20 @@
+// /** @file\r
+// SystemFirmwareUpdateDxe Localized Strings and Content\r
+//\r
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+#string STR_PROPERTIES_MODULE_NAME\r
+#language en-US\r
+"SystemFirmwareUpdate DXE Driver"\r
+\r
+\r