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