If variable does not exist for a HII PCD, a new NV variable need to be created.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7705 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
klu2 2009-02-26 06:39:56 +00:00
parent 18efbdff45
commit 746be876f1
1 changed files with 32 additions and 5 deletions

View File

@ -978,6 +978,9 @@ SetHiiVariable (
Size = 0; Size = 0;
//
// Try to get original variable size information.
//
Status = gRT->GetVariable ( Status = gRT->GetVariable (
(UINT16 *)VariableName, (UINT16 *)VariableName,
VariableGuid, VariableGuid,
@ -987,6 +990,9 @@ SetHiiVariable (
); );
if (Status == EFI_BUFFER_TOO_SMALL) { if (Status == EFI_BUFFER_TOO_SMALL) {
//
// Patch new PCD's value to offset in given HII variable.
//
Buffer = AllocatePool (Size); Buffer = AllocatePool (Size);
@ -1015,12 +1021,33 @@ SetHiiVariable (
FreePool (Buffer); FreePool (Buffer);
return Status; return Status;
} else if (Status == EFI_NOT_FOUND) {
//
// If variable does not exist, a new variable need to be created.
//
Size = Offset + DataSize;
Buffer = AllocateZeroPool (Size);
ASSERT (Buffer != NULL);
CopyMem ((UINT8 *)Buffer + Offset, Data, DataSize);
Status = gRT->SetVariable (
VariableName,
VariableGuid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
Size,
Buffer
);
FreePool (Buffer);
return Status;
} }
// //
// If we drop to here, we don't have a Variable entry in // If we drop to here, the value is failed to be written in to variable area
// the variable service yet. So, we will save the data // So, we will save the data in the PCD Database's volatile area.
// in the PCD Database's volatile area.
// //
return Status; return Status;
} }