]>
git.proxmox.com Git - mirror_edk2.git/blob - UefiPayloadPkg/Library/FlashDeviceLib/FlashDeviceLib.c
2 Flash Device Library based on SPI Flash library.
4 Copyright (c) 2018 - 2021, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseMemoryLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/SpiFlashLib.h>
15 Initialize spi flash device.
17 @retval EFI_SUCCESS The tested spi flash device is supported.
18 @retval EFI_UNSUPPORTED The tested spi flash device is not supported.
23 LibFvbFlashDeviceInit (
27 return SpiConstructor ();
32 Read NumBytes bytes of data from the address specified by
35 @param[in] PAddress The starting physical address of the read.
36 @param[in,out] NumBytes On input, the number of bytes to read. On output, the number
37 of bytes actually read.
38 @param[out] Buffer The destination data buffer for the read.
40 @retval EFI_SUCCESS. Opertion is successful.
41 @retval EFI_DEVICE_ERROR If there is any device errors.
46 LibFvbFlashDeviceRead (
48 IN OUT UINTN
*NumBytes
,
57 Status
= SpiGetRegionAddress (FlashRegionBios
, NULL
, &RgnSize
);
58 if (EFI_ERROR (Status
)) {
62 // BIOS region offset can be calculated by (PAddress - (0x100000000 - RgnSize))
63 // which equal (PAddress + RgnSize) here.
64 AddrOffset
= (UINT32
)((UINT32
)PAddress
+ RgnSize
);
65 ByteCount
= (UINT32
)*NumBytes
;
66 return SpiFlashRead (FlashRegionBios
, AddrOffset
, ByteCount
, Buffer
);
71 Write NumBytes bytes of data from Buffer to the address specified by
74 @param[in] PAddress The starting physical address of the write.
75 @param[in,out] NumBytes On input, the number of bytes to write. On output,
76 the actual number of bytes written.
77 @param[in] Buffer The source data buffer for the write.
79 @retval EFI_SUCCESS. Opertion is successful.
80 @retval EFI_DEVICE_ERROR If there is any device errors.
85 LibFvbFlashDeviceWrite (
87 IN OUT UINTN
*NumBytes
,
96 Status
= SpiGetRegionAddress (FlashRegionBios
, NULL
, &RgnSize
);
97 if (EFI_ERROR (Status
)) {
101 // BIOS region offset can be calculated by (PAddress - (0x100000000 - RgnSize))
102 // which equal (PAddress + RgnSize) here.
103 AddrOffset
= (UINT32
)((UINT32
)PAddress
+ RgnSize
);
104 ByteCount
= (UINT32
)*NumBytes
;
105 return SpiFlashWrite (FlashRegionBios
, AddrOffset
, ByteCount
, Buffer
);
110 Erase the block starting at PAddress.
112 @param[in] PAddress The starting physical address of the block to be erased.
113 This library assume that caller garantee that the PAddress
114 is at the starting address of this block.
115 @param[in] LbaLength The length of the logical block to be erased.
117 @retval EFI_SUCCESS. Opertion is successful.
118 @retval EFI_DEVICE_ERROR If there is any device errors.
123 LibFvbFlashDeviceBlockErase (
132 Status
= SpiGetRegionAddress (FlashRegionBios
, NULL
, &RgnSize
);
133 if (EFI_ERROR (Status
)) {
137 // BIOS region offset can be calculated by (PAddress - (0x100000000 - RgnSize))
138 // which equal (PAddress + RgnSize) here.
139 AddrOffset
= (UINT32
)((UINT32
)PAddress
+ RgnSize
);
140 return SpiFlashErase (FlashRegionBios
, AddrOffset
, (UINT32
)LbaLength
);
145 Lock or unlock the block starting at PAddress.
147 @param[in] PAddress The starting physical address of region to be (un)locked.
148 @param[in] LbaLength The length of the logical block to be erased.
149 @param[in] Lock TRUE to lock. FALSE to unlock.
151 @retval EFI_SUCCESS. Opertion is successful.
152 @retval EFI_DEVICE_ERROR If there is any device errors.
157 LibFvbFlashDeviceBlockLock (