Sets NVRAM variable. Does nothing if variable with the same data and attributes already exists. */
| 175 | |
| 176 | /** Sets NVRAM variable. Does nothing if variable with the same data and attributes already exists. */ |
| 177 | EFI_STATUS |
| 178 | SetNvramVariable ( |
| 179 | IN CONST CHAR16 *VariableName, |
| 180 | IN EFI_GUID *VendorGuid, |
| 181 | IN UINT32 Attributes, |
| 182 | IN UINTN DataSize, |
| 183 | IN CONST VOID *Data |
| 184 | ) |
| 185 | { |
| 186 | //EFI_STATUS Status; |
| 187 | VOID *OldData; |
| 188 | UINTN OldDataSize = 0; |
| 189 | UINT32 OldAttributes = 0; |
| 190 | |
| 191 | //DBG("SetNvramVariable (%ls, guid, 0x%X, %d):", VariableName, Attributes, DataSize); |
| 192 | OldData = (__typeof__(OldData))GetNvramVariable(VariableName, VendorGuid, &OldAttributes, &OldDataSize); |
| 193 | if (OldData != NULL) { |
| 194 | // var already exists - check if it equal to new value |
| 195 | //DBG(" exists(0x%X, %d)", OldAttributes, OldDataSize); |
| 196 | if ((OldAttributes == Attributes) && |
| 197 | (OldDataSize == DataSize) && |
| 198 | (CompareMem (OldData, Data, DataSize) == 0)) { |
| 199 | // it's the same - do nothing |
| 200 | //DBG(", equal -> not writing again.\n"); |
| 201 | FreePool(OldData); |
| 202 | return EFI_SUCCESS; |
| 203 | } |
| 204 | //DBG(", not equal\n"); |
| 205 | |
| 206 | FreePool(OldData); |
| 207 | |
| 208 | // not the same - delete previous one if attributes are different |
| 209 | if (OldAttributes != Attributes) { |
| 210 | DeleteNvramVariable (VariableName, VendorGuid); |
| 211 | //DBG(", diff. attr: deleting old (%s)", efiStrError(Status)); |
| 212 | } |
| 213 | } |
| 214 | //DBG("\n"); // for debug without Status |
| 215 | //DBG(" -> writing new (%s)\n", efiStrError(Status)); |
| 216 | //return Status; |
| 217 | |
| 218 | return gRT->SetVariable(VariableName, VendorGuid, Attributes, DataSize, (VOID*)Data); // CONST missing in EFI_SET_VARIABLE->SetVariable |
| 219 | |
| 220 | } |
| 221 | EFI_STATUS |
| 222 | SetNvramXString8 ( |
| 223 | IN CONST CHAR16 *VariableName, |
no test coverage detected