From: klu2 Date: Thu, 26 Feb 2009 06:39:56 +0000 (+0000) Subject: If variable does not exist for a HII PCD, a new NV variable need to be created. X-Git-Tag: edk2-stable201903~18545 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=746be876f107eeb5782b417d1699337b2b1e96ca 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 --- diff --git a/MdeModulePkg/Universal/PCD/Dxe/Service.c b/MdeModulePkg/Universal/PCD/Dxe/Service.c index 9c497e9606..bfc17e734c 100644 --- a/MdeModulePkg/Universal/PCD/Dxe/Service.c +++ b/MdeModulePkg/Universal/PCD/Dxe/Service.c @@ -978,6 +978,9 @@ SetHiiVariable ( Size = 0; + // + // Try to get original variable size information. + // Status = gRT->GetVariable ( (UINT16 *)VariableName, VariableGuid, @@ -987,7 +990,10 @@ SetHiiVariable ( ); if (Status == EFI_BUFFER_TOO_SMALL) { - + // + // Patch new PCD's value to offset in given HII variable. + // + Buffer = AllocatePool (Size); ASSERT (Buffer != NULL); @@ -1015,12 +1021,33 @@ SetHiiVariable ( FreePool (Buffer); 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 - // the variable service yet. So, we will save the data - // in the PCD Database's volatile area. + // If we drop to here, the value is failed to be written in to variable area + // So, we will save the data in the PCD Database's volatile area. // return Status; }