TianoCore EDK2 master
Loading...
Searching...
No Matches
SystemFirmwareUpdateDxe.c File Reference

Go to the source code of this file.

Functions

EFI_STATUS ParseUpdateDataFile (IN UINT8 *DataBuffer, IN UINTN BufferSize, IN OUT CONFIG_HEADER *ConfigHeader, IN OUT UPDATE_CONFIG_DATA **UpdateArray)
 
EFI_STATUS PerformUpdate (IN VOID *SystemFirmwareImage, IN UINTN SystemFirmwareImageSize, IN UPDATE_CONFIG_DATA *ConfigData, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus, IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, IN UINTN StartPercentage, IN UINTN EndPercentage)
 
EFI_STATUS UpdateImage (IN VOID *SystemFirmwareImage, IN UINTN SystemFirmwareImageSize, IN VOID *ConfigImage, IN UINTN ConfigImageSize, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus, IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress)
 
EFI_STATUS SystemFirmwareAuthenticatedUpdate (IN VOID *Image, IN UINTN ImageSize, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus, IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress)
 
EFI_STATUS EFIAPI GetVariableHook (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, OUT VOID *Data)
 
EFI_STATUS EFIAPI GetNextVariableNameHook (IN OUT UINTN *VariableNameSize, IN OUT CHAR16 *VariableName, IN OUT EFI_GUID *VendorGuid)
 
EFI_STATUS EFIAPI SetVariableHook (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
 
EFI_STATUS EFIAPI QueryVariableInfoHook (IN UINT32 Attributes, OUT UINT64 *MaximumVariableStorageSize, OUT UINT64 *RemainingVariableStorageSize, OUT UINT64 *MaximumVariableSize)
 
EFI_STATUS EFIAPI FmpSetImage (IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This, IN UINT8 ImageIndex, IN CONST VOID *Image, IN UINTN ImageSize, IN CONST VOID *VendorCode, IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OUT CHAR16 **AbortReason)
 
EFI_FIRMWARE_IMAGE_DESCRIPTORGetFmpImageDescriptors (IN EFI_HANDLE Handle, IN EFI_GUID *ProtocolGuid, OUT UINT8 *FmpImageInfoCount, OUT UINTN *DescriptorSize)
 
EFI_HANDLEFindMatchingFmpHandles (IN EFI_GUID *ProtocolGuid, OUT UINTN *HandleCount)
 
EFI_STATUS UninstallMatchingSystemFmpProtocols (VOID)
 
EFI_STATUS EFIAPI SystemFirmwareUpdateMainDxe (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

SYSTEM_FMP_PRIVATE_DATAmSystemFmpPrivate = NULL
 
EFI_GUID mCurrentImageTypeId
 
BOOLEAN mNvRamUpdated = FALSE
 

Detailed Description

SetImage instance to update system firmware.

Caution: This module requires additional review when modified. This module will have external input - capsule image. This external input must be validated carefully to avoid security issue like buffer overflow, integer overflow.

FmpSetImage() will receive untrusted input and do basic validation.

Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file SystemFirmwareUpdateDxe.c.

Function Documentation

◆ FindMatchingFmpHandles()

EFI_HANDLE * FindMatchingFmpHandles ( IN EFI_GUID ProtocolGuid,
OUT UINTN HandleCount 
)

Search for handles with an FMP protocol whose EFI_FIRMWARE_IMAGE_DESCRIPTOR ImageTypeId matches the ImageTypeId produced by this module.

Parameters
[in]ProtocolGuidPointer to the GUID of the protocol to search.
[out]HandleCountPointer to the number of returned handles.
Returns
NULL No matching handles found.
!NULL Pointer to a buffer of handles allocated using AllocatePool(). Caller must free buffer with FreePool().

Definition at line 650 of file SystemFirmwareUpdateDxe.c.

◆ FmpSetImage()

EFI_STATUS EFIAPI FmpSetImage ( IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL This,
IN UINT8  ImageIndex,
IN CONST VOID *  Image,
IN UINTN  ImageSize,
IN CONST VOID *  VendorCode,
IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS  Progress,
OUT CHAR16 **  AbortReason 
)

Updates the firmware image of the device.

This function updates the hardware with the new firmware image. This function returns EFI_UNSUPPORTED if the firmware image is not updatable. If the firmware image is updatable, the function should perform the following minimal validations before proceeding to do the firmware image update.

  • Validate the image authentication if image has attribute IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED. The function returns EFI_SECURITY_VIOLATION if the validation fails.
  • Validate the image is a supported image for this device. The function returns EFI_ABORTED if the image is unsupported. The function can optionally provide more detailed information on why the image is not a supported image.
  • Validate the data from VendorCode if not null. Image validation must be performed before VendorCode data validation. VendorCode data is ignored or considered invalid if image validation failed. The function returns EFI_ABORTED if the data is invalid.

VendorCode enables vendor to implement vendor-specific firmware image update policy. Null if the caller did not specify the policy or use the default policy. As an example, vendor can implement a policy to allow an option to force a firmware image update when the abort reason is due to the new firmware image version is older than the current firmware image version or bad image checksum. Sensitive operations such as those wiping the entire firmware image and render the device to be non-functional should be encoded in the image itself rather than passed with the VendorCode. AbortReason enables vendor to have the option to provide a more detailed description of the abort reason to the caller.

Parameters
[in]ThisA pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.
[in]ImageIndexA unique number identifying the firmware image(s) within the device. The number is between 1 and DescriptorCount.
[in]ImagePoints to the new image.
[in]ImageSizeSize of the new image in bytes.
[in]VendorCodeThis enables vendor to implement vendor-specific firmware image update policy. Null indicates the caller did not specify the policy or use the default policy.
[in]ProgressA function used by the driver to report the progress of the firmware update.
[out]AbortReasonA pointer to a pointer to a null-terminated string providing more details for the aborted operation. The buffer is allocated by this function with AllocatePool(), and it is the caller's responsibility to free it with a call to FreePool().
Return values
EFI_SUCCESSThe device was successfully updated with the new image.
EFI_ABORTEDThe operation is aborted.
EFI_INVALID_PARAMETERThe Image was NULL.
EFI_UNSUPPORTEDThe operation is not supported.
EFI_SECURITY_VIOLATIONThe operation could not be performed due to an authentication failure.

Definition at line 470 of file SystemFirmwareUpdateDxe.c.

◆ GetFmpImageDescriptors()

EFI_FIRMWARE_IMAGE_DESCRIPTOR * GetFmpImageDescriptors ( IN EFI_HANDLE  Handle,
IN EFI_GUID ProtocolGuid,
OUT UINT8 *  FmpImageInfoCount,
OUT UINTN DescriptorSize 
)

Get the set of EFI_FIRMWARE_IMAGE_DESCRIPTOR structures from an FMP Protocol.

Parameters
[in]HandleHandle with an FMP Protocol or a System FMP Protocol.
[in]ProtocolGuidPointer to the FMP Protocol GUID or System FMP Protocol GUID.
[out]FmpImageInfoCountPointer to the number of EFI_FIRMWARE_IMAGE_DESCRIPTOR structures.
[out]DescriptorSizePointer to the size, in bytes, of each EFI_FIRMWARE_IMAGE_DESCRIPTOR structure.
Returns
NULL No EFI_FIRMWARE_IMAGE_DESCRIPTOR structures found.
!NULL Pointer to a buffer of EFI_FIRMWARE_IMAGE_DESCRIPTOR structures allocated using AllocatePool(). Caller must free buffer with FreePool().

Definition at line 547 of file SystemFirmwareUpdateDxe.c.

◆ GetNextVariableNameHook()

EFI_STATUS EFIAPI GetNextVariableNameHook ( IN OUT UINTN VariableNameSize,
IN OUT CHAR16 *  VariableName,
IN OUT EFI_GUID VendorGuid 
)

This code Finds the Next available variable.

Parameters
[in,out]VariableNameSizeSize of the variable name.
[in,out]VariableNamePointer to variable name.
[in,out]VendorGuidVariable Vendor Guid.
Returns
EFI_INVALID_PARAMETER Invalid parameter.
EFI_SUCCESS Find the specified variable.
EFI_NOT_FOUND Not found.
EFI_BUFFER_TO_SMALL DataSize is too small for the result.

Definition at line 351 of file SystemFirmwareUpdateDxe.c.

◆ GetVariableHook()

EFI_STATUS EFIAPI GetVariableHook ( IN CHAR16 *  VariableName,
IN EFI_GUID VendorGuid,
OUT UINT32 *Attributes  OPTIONAL,
IN OUT UINTN DataSize,
OUT VOID *  Data 
)

This code finds variable in storage blocks (Volatile or Non-Volatile).

Parameters
[in]VariableNameName of Variable to be found.
[in]VendorGuidVariable vendor GUID.
[out]AttributesAttribute value of the variable found.
[in,out]DataSizeSize of Data found. If size is less than the data, this value contains the required size.
[out]DataData pointer.
Returns
EFI_INVALID_PARAMETER Invalid parameter.
EFI_SUCCESS Find the specified variable.
EFI_NOT_FOUND Not found.
EFI_BUFFER_TO_SMALL DataSize is too small for the result.

Definition at line 323 of file SystemFirmwareUpdateDxe.c.

◆ ParseUpdateDataFile()

EFI_STATUS ParseUpdateDataFile ( IN UINT8 *  DataBuffer,
IN UINTN  BufferSize,
IN OUT CONFIG_HEADER ConfigHeader,
IN OUT UPDATE_CONFIG_DATA **  UpdateArray 
)

Parse Config data file to get the updated data array.

Parameters
[in]DataBufferConfig raw file buffer.
[in]BufferSizeSize of raw buffer.
[in,out]ConfigHeaderPointer to the config header.
[in,out]UpdateArrayPointer to the config of update data.
Return values
EFI_NOT_FOUNDNo config data is found.
EFI_OUT_OF_RESOURCESNo enough memory is allocated.
EFI_SUCCESSParse the config file successfully.

Definition at line 31 of file ParseConfigProfile.c.

◆ PerformUpdate()

EFI_STATUS PerformUpdate ( IN VOID *  SystemFirmwareImage,
IN UINTN  SystemFirmwareImageSize,
IN UPDATE_CONFIG_DATA ConfigData,
OUT UINT32 *  LastAttemptVersion,
OUT UINT32 *  LastAttemptStatus,
IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS  Progress,
IN UINTN  StartPercentage,
IN UINTN  EndPercentage 
)

Update System Firmware image component.

Parameters
[in]SystemFirmwareImagePoints to the System Firmware image.
[in]SystemFirmwareImageSizeThe length of the System Firmware image in bytes.
[in]ConfigDataPoints to the component configuration structure.
[out]LastAttemptVersionThe last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
[out]LastAttemptStatusThe last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
[in]ProgressA function used by the driver to report the progress of the firmware update.
[in]StartPercentageThe start completion percentage value that may be used to report progress during the flash write operation.
[in]EndPercentageThe end completion percentage value that may be used to report progress during the flash write operation.
Return values
EFI_SUCCESSThe System Firmware image is updated.
EFI_WRITE_PROTECTEDThe flash device is read only.

Definition at line 64 of file SystemFirmwareUpdateDxe.c.

◆ QueryVariableInfoHook()

EFI_STATUS EFIAPI QueryVariableInfoHook ( IN UINT32  Attributes,
OUT UINT64 *  MaximumVariableStorageSize,
OUT UINT64 *  RemainingVariableStorageSize,
OUT UINT64 *  MaximumVariableSize 
)

This code returns information about the EFI variables.

Parameters
[in]AttributesAttributes bitmask to specify the type of variables on which to return information.
[out]MaximumVariableStorageSizePointer to the maximum size of the storage space available for the EFI variables associated with the attributes specified.
[out]RemainingVariableStorageSizePointer to the remaining size of the storage space available for EFI variables associated with the attributes specified.
[out]MaximumVariableSizePointer to the maximum size of an individual EFI variables associated with the attributes specified.
Returns
EFI_SUCCESS Query successfully.

Definition at line 411 of file SystemFirmwareUpdateDxe.c.

◆ SetVariableHook()

EFI_STATUS EFIAPI SetVariableHook ( IN CHAR16 *  VariableName,
IN EFI_GUID VendorGuid,
IN UINT32  Attributes,
IN UINTN  DataSize,
IN VOID *  Data 
)

This code sets variable in storage blocks (Volatile or Non-Volatile).

Parameters
[in]VariableNameName of Variable to be found.
[in]VendorGuidVariable vendor GUID.
[in]AttributesAttribute value of the variable found
[in]DataSizeSize of Data found. If size is less than the data, this value contains the required size.
[in]DataData pointer.
Returns
EFI_INVALID_PARAMETER Invalid parameter.
EFI_SUCCESS Set successfully.
EFI_OUT_OF_RESOURCES Resource not enough to set variable.
EFI_NOT_FOUND Not found.
EFI_WRITE_PROTECTED Variable is read-only.

Definition at line 381 of file SystemFirmwareUpdateDxe.c.

◆ SystemFirmwareAuthenticatedUpdate()

EFI_STATUS SystemFirmwareAuthenticatedUpdate ( IN VOID *  Image,
IN UINTN  ImageSize,
OUT UINT32 *  LastAttemptVersion,
OUT UINT32 *  LastAttemptStatus,
IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS  Progress 
)

Authenticate and update System Firmware image.

Caution: This function may receive untrusted input.

Parameters
[in]ImageThe EDKII system FMP capsule image.
[in]ImageSizeThe size of the EDKII system FMP capsule image in bytes.
[out]LastAttemptVersionThe last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
[out]LastAttemptStatusThe last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
[in]ProgressA function used by the driver to report the progress of the firmware update.
Return values
EFI_SUCCESSEDKII system FMP capsule passes authentication and the System Firmware image is updated.
EFI_SECURITY_VIOLATIONEDKII system FMP capsule fails authentication and the System Firmware image is not updated.
EFI_WRITE_PROTECTEDThe flash device is read only.

Definition at line 260 of file SystemFirmwareUpdateDxe.c.

◆ SystemFirmwareUpdateMainDxe()

EFI_STATUS EFIAPI SystemFirmwareUpdateMainDxe ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

System FMP module entrypoint

Parameters
[in]ImageHandleThe firmware allocated handle for the EFI image.
[in]SystemTableA pointer to the EFI System Table.
Return values
EFI_SUCCESSSystem FMP module is initialized.
EFI_OUT_OF_RESOURCESThere are not enough resources avaulable to initialize this module.
OtherSystem FMP Protocols could not be uninstalled.
OtherSystem FMP Protocol could not be installed.
OtherFMP Protocol could not be installed.

Definition at line 811 of file SystemFirmwareUpdateDxe.c.

◆ UninstallMatchingSystemFmpProtocols()

EFI_STATUS UninstallMatchingSystemFmpProtocols ( VOID  )

Uninstall System FMP Protocol instances that may have been installed by SystemFirmwareUpdateDxe drivers dispatches by other capsules.

Return values
EFI_SUCCESSAll System FMP Protocols found were uninstalled.
Returns
Other One or more System FMP Protocols could not be uninstalled.

Definition at line 746 of file SystemFirmwareUpdateDxe.c.

◆ UpdateImage()

EFI_STATUS UpdateImage ( IN VOID *  SystemFirmwareImage,
IN UINTN  SystemFirmwareImageSize,
IN VOID *  ConfigImage,
IN UINTN  ConfigImageSize,
OUT UINT32 *  LastAttemptVersion,
OUT UINT32 *  LastAttemptStatus,
IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS  Progress 
)

Update System Firmware image.

Parameters
[in]SystemFirmwareImagePoints to the System Firmware image.
[in]SystemFirmwareImageSizeThe length of the System Firmware image in bytes.
[in]ConfigImagePoints to the config file image.
[in]ConfigImageSizeThe length of the config file image in bytes.
[out]LastAttemptVersionThe last attempt version, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
[out]LastAttemptStatusThe last attempt status, which will be recorded in ESRT and FMP EFI_FIRMWARE_IMAGE_DESCRIPTOR.
[in]ProgressA function used by the driver to report the progress of the firmware update.
Return values
EFI_SUCCESSThe System Firmware image is updated.
EFI_WRITE_PROTECTEDThe flash device is read only.

Definition at line 126 of file SystemFirmwareUpdateDxe.c.

Variable Documentation

◆ mCurrentImageTypeId

EFI_GUID mCurrentImageTypeId

Definition at line 23 of file SystemFirmwareUpdateDxe.c.

◆ mNvRamUpdated

BOOLEAN mNvRamUpdated = FALSE

Definition at line 25 of file SystemFirmwareUpdateDxe.c.

◆ mSystemFmpPrivate

SYSTEM_FMP_PRIVATE_DATA* mSystemFmpPrivate = NULL

Definition at line 21 of file SystemFirmwareUpdateDxe.c.