SignedCapsulePkg/PlatformFlashAccessLib: Add progress API
[mirror_edk2.git] / SignedCapsulePkg / Library / PlatformFlashAccessLibNull / PlatformFlashAccessLibNull.c
1 /** @file
2 Platform flash device access library NULL instance.
3
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiDxe.h>
16
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/PlatformFlashAccessLib.h>
19
20 UINT64 mInternalFdAddress;
21
22 /**
23 Perform flash write operation with progress indicator. The start and end
24 completion percentage values are passed into this function. If the requested
25 flash write operation is broken up, then completion percentage between the
26 start and end values may be passed to the provided Progress function. The
27 caller of this function is required to call the Progress function for the
28 start and end completion percentage values. This allows the Progress,
29 StartPercentage, and EndPercentage parameters to be ignored if the requested
30 flash write operation can not be broken up
31
32 @param[in] FirmwareType The type of firmware.
33 @param[in] FlashAddress The address of flash device to be accessed.
34 @param[in] FlashAddressType The type of flash device address.
35 @param[in] Buffer The pointer to the data buffer.
36 @param[in] Length The length of data buffer in bytes.
37 @param[in] Progress A function used report the progress of the
38 firmware update. This is an optional parameter
39 that may be NULL.
40 @param[in] StartPercentage The start completion percentage value that may
41 be used to report progress during the flash
42 write operation.
43 @param[in] EndPercentage The end completion percentage value that may
44 be used to report progress during the flash
45 write operation.
46
47 @retval EFI_SUCCESS The operation returns successfully.
48 @retval EFI_WRITE_PROTECTED The flash device is read only.
49 @retval EFI_UNSUPPORTED The flash device access is unsupported.
50 @retval EFI_INVALID_PARAMETER The input parameter is not valid.
51 **/
52 EFI_STATUS
53 EFIAPI
54 PerformFlashWriteWithProgress (
55 IN PLATFORM_FIRMWARE_TYPE FirmwareType,
56 IN EFI_PHYSICAL_ADDRESS FlashAddress,
57 IN FLASH_ADDRESS_TYPE FlashAddressType,
58 IN VOID *Buffer,
59 IN UINTN Length,
60 IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OPTIONAL
61 IN UINTN StartPercentage,
62 IN UINTN EndPercentage
63 )
64 {
65 if (FlashAddressType == FlashAddressTypeRelativeAddress) {
66 FlashAddress = FlashAddress + mInternalFdAddress;
67 }
68 CopyMem((VOID *)(UINTN)(FlashAddress), Buffer, Length);
69 return EFI_SUCCESS;
70 }
71
72 /**
73 Perform flash write operation.
74
75 @param[in] FirmwareType The type of firmware.
76 @param[in] FlashAddress The address of flash device to be accessed.
77 @param[in] FlashAddressType The type of flash device address.
78 @param[in] Buffer The pointer to the data buffer.
79 @param[in] Length The length of data buffer in bytes.
80
81 @retval EFI_SUCCESS The operation returns successfully.
82 @retval EFI_WRITE_PROTECTED The flash device is read only.
83 @retval EFI_UNSUPPORTED The flash device access is unsupported.
84 @retval EFI_INVALID_PARAMETER The input parameter is not valid.
85 **/
86 EFI_STATUS
87 EFIAPI
88 PerformFlashWrite (
89 IN PLATFORM_FIRMWARE_TYPE FirmwareType,
90 IN EFI_PHYSICAL_ADDRESS FlashAddress,
91 IN FLASH_ADDRESS_TYPE FlashAddressType,
92 IN VOID *Buffer,
93 IN UINTN Length
94 )
95 {
96 return PerformFlashWriteWithProgress (
97 FirmwareType,
98 FlashAddress,
99 FlashAddressType,
100 Buffer,
101 Length,
102 NULL,
103 0,
104 0
105 );
106 }
107