2 Variable Flash Information Library
4 Copyright (c) Microsoft Corporation<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Pi/PiMultiPhase.h>
12 #include <Guid/VariableFlashInfo.h>
13 #include <Library/DebugLib.h>
14 #include <Library/HobLib.h>
15 #include <Library/VariableFlashInfoLib.h>
18 Get the HOB that contains variable flash information.
20 @param[out] VariableFlashInfo Pointer to a pointer to set to the variable flash information structure.
22 @retval EFI_SUCCESS Variable flash information was found successfully.
23 @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is NULL.
24 @retval EFI_NOT_FOUND Variable flash information could not be found.
29 GetVariableFlashInfoFromHob (
30 OUT VARIABLE_FLASH_INFO
**VariableFlashInfo
33 EFI_HOB_GUID_TYPE
*GuidHob
;
35 if (VariableFlashInfo
== NULL
) {
36 return EFI_INVALID_PARAMETER
;
39 GuidHob
= GetFirstGuidHob (&gVariableFlashInfoHobGuid
);
40 if (GuidHob
== NULL
) {
44 *VariableFlashInfo
= GET_GUID_HOB_DATA (GuidHob
);
47 // Assert if more than one variable flash information HOB is present.
50 if ((GetNextGuidHob (&gVariableFlashInfoHobGuid
, GET_NEXT_HOB (GuidHob
)) != NULL
)) {
51 DEBUG ((DEBUG_ERROR
, "ERROR: Found two variable flash information HOBs\n"));
61 Get the base address and size for the NV storage area used for UEFI variable storage.
63 @param[out] BaseAddress The NV storage base address.
64 @param[out] Length The NV storage length in bytes.
66 @retval EFI_SUCCESS NV storage information was found successfully.
67 @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
72 GetVariableFlashNvStorageInfo (
73 OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
78 VARIABLE_FLASH_INFO
*VariableFlashInfo
;
80 if ((BaseAddress
== NULL
) || (Length
== NULL
)) {
81 return EFI_INVALID_PARAMETER
;
84 Status
= GetVariableFlashInfoFromHob (&VariableFlashInfo
);
85 if (!EFI_ERROR (Status
)) {
86 *BaseAddress
= VariableFlashInfo
->NvVariableBaseAddress
;
87 *Length
= VariableFlashInfo
->NvVariableLength
;
89 *BaseAddress
= (EFI_PHYSICAL_ADDRESS
)(PcdGet64 (PcdFlashNvStorageVariableBase64
) != 0 ?
90 PcdGet64 (PcdFlashNvStorageVariableBase64
) :
91 PcdGet32 (PcdFlashNvStorageVariableBase
)
93 *Length
= (UINT64
)PcdGet32 (PcdFlashNvStorageVariableSize
);
100 Get the base address and size for the fault tolerant write (FTW) spare
101 area used for UEFI variable storage.
103 @param[out] BaseAddress The FTW spare base address.
104 @param[out] Length The FTW spare length in bytes.
106 @retval EFI_SUCCESS FTW spare information was found successfully.
107 @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
108 @retval EFI_NOT_FOUND FTW spare information could not be found.
113 GetVariableFlashFtwSpareInfo (
114 OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
119 VARIABLE_FLASH_INFO
*VariableFlashInfo
;
121 if ((BaseAddress
== NULL
) || (Length
== NULL
)) {
122 return EFI_INVALID_PARAMETER
;
125 Status
= GetVariableFlashInfoFromHob (&VariableFlashInfo
);
126 if (!EFI_ERROR (Status
)) {
127 *BaseAddress
= VariableFlashInfo
->FtwSpareBaseAddress
;
128 *Length
= VariableFlashInfo
->FtwSpareLength
;
130 *BaseAddress
= (EFI_PHYSICAL_ADDRESS
)(PcdGet64 (PcdFlashNvStorageFtwSpareBase64
) != 0 ?
131 PcdGet64 (PcdFlashNvStorageFtwSpareBase64
) :
132 PcdGet32 (PcdFlashNvStorageFtwSpareBase
)
134 *Length
= (UINT64
)PcdGet32 (PcdFlashNvStorageFtwSpareSize
);
141 Get the base address and size for the fault tolerant write (FTW) working
142 area used for UEFI variable storage.
144 @param[out] BaseAddress The FTW working area base address.
145 @param[out] Length The FTW working area length in bytes.
147 @retval EFI_SUCCESS FTW working information was found successfully.
148 @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
149 @retval EFI_NOT_FOUND FTW working information could not be found.
154 GetVariableFlashFtwWorkingInfo (
155 OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
160 VARIABLE_FLASH_INFO
*VariableFlashInfo
;
162 if ((BaseAddress
== NULL
) || (Length
== NULL
)) {
163 return EFI_INVALID_PARAMETER
;
166 Status
= GetVariableFlashInfoFromHob (&VariableFlashInfo
);
167 if (!EFI_ERROR (Status
)) {
168 *BaseAddress
= VariableFlashInfo
->FtwWorkingBaseAddress
;
169 *Length
= VariableFlashInfo
->FtwWorkingLength
;
171 *BaseAddress
= (EFI_PHYSICAL_ADDRESS
)(PcdGet64 (PcdFlashNvStorageFtwWorkingBase64
) != 0 ?
172 PcdGet64 (PcdFlashNvStorageFtwWorkingBase64
) :
173 PcdGet32 (PcdFlashNvStorageFtwWorkingBase
)
175 *Length
= (UINT64
)PcdGet32 (PcdFlashNvStorageFtwWorkingSize
);