Add example of Name/Value pair var store to DriverSample

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9975 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lgao4 2010-02-11 01:59:35 +00:00
parent a6d7123ebc
commit 38ebfecb62
5 changed files with 327 additions and 9 deletions

View File

@ -301,6 +301,38 @@ SetPassword (
return Status; return Status;
} }
/**
Update names of Name/Value storage to current language.
@param PrivateData Points to the driver private data.
@retval EFI_SUCCESS All names are successfully updated.
@retval EFI_NOT_FOUND Failed to get Name from HII database.
**/
EFI_STATUS
LoadNameValueNames (
IN DRIVER_SAMPLE_PRIVATE_DATA *PrivateData
)
{
UINTN Index;
//
// Get Name/Value name string of current language
//
for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
PrivateData->NameValueName[Index] = HiiGetString (
PrivateData->HiiHandle[0],
PrivateData->NameStringId[Index],
NULL
);
if (PrivateData->NameValueName[Index] == NULL) {
return EFI_NOT_FOUND;
}
}
return EFI_SUCCESS;
}
/** /**
This function allows a caller to extract the current configuration for one This function allows a caller to extract the current configuration for one
@ -344,6 +376,11 @@ ExtractConfig (
EFI_STRING ConfigRequest; EFI_STRING ConfigRequest;
EFI_STRING ConfigRequestHdr; EFI_STRING ConfigRequestHdr;
UINTN Size; UINTN Size;
EFI_STRING Value;
UINTN ValueStrLen;
CHAR16 BackupChar;
CHAR16 *StrPointer;
if (Progress == NULL || Results == NULL || Request == NULL) { if (Progress == NULL || Results == NULL || Request == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -394,10 +431,96 @@ ExtractConfig (
// Check routing data in <ConfigHdr>. // Check routing data in <ConfigHdr>.
// Note: if only one Storage is used, then this checking could be skipped. // Note: if only one Storage is used, then this checking could be skipped.
// //
if (!HiiIsConfigHdrMatch (Request, &mFormSetGuid, VariableName)) { if (!HiiIsConfigHdrMatch (Request, &mFormSetGuid, NULL)) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
ConfigRequest = Request; ConfigRequest = Request;
//
// Check if requesting Name/Value storage
//
if (StrStr (Request, L"OFFSET") == NULL) {
//
// Update Name/Value storage Names
//
Status = LoadNameValueNames (PrivateData);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Allocate memory for <ConfigResp>, e.g. Name0=0x11, Name1=0x1234, Name2="ABCD"
// <Request> ::=<ConfigHdr>&Name0&Name1&Name2
// <ConfigResp>::=<ConfigHdr>&Name0=11&Name1=1234&Name2=0041004200430044
//
BufferSize = (StrLen (Request) +
1 + sizeof (PrivateData->Configuration.NameValueVar0) * 2 +
1 + sizeof (PrivateData->Configuration.NameValueVar1) * 2 +
1 + sizeof (PrivateData->Configuration.NameValueVar2) * 2 + 1) * sizeof (CHAR16);
*Results = AllocateZeroPool (BufferSize);
ASSERT (*Results != NULL);
StrCpy (*Results, Request);
Value = *Results;
//
// Append value of NameValueVar0, type is UINT8
//
if ((Value = StrStr (*Results, PrivateData->NameValueName[0])) != NULL) {
Value += StrLen (PrivateData->NameValueName[0]);
ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar0) * 2) + 1);
CopyMem (Value + ValueStrLen, Value, StrSize (Value));
BackupChar = Value[ValueStrLen];
*Value++ = L'=';
Value += UnicodeValueToString (
Value,
PREFIX_ZERO | RADIX_HEX,
PrivateData->Configuration.NameValueVar0,
sizeof (PrivateData->Configuration.NameValueVar0) * 2
);
*Value = BackupChar;
}
//
// Append value of NameValueVar1, type is UINT16
//
if ((Value = StrStr (*Results, PrivateData->NameValueName[1])) != NULL) {
Value += StrLen (PrivateData->NameValueName[1]);
ValueStrLen = ((sizeof (PrivateData->Configuration.NameValueVar1) * 2) + 1);
CopyMem (Value + ValueStrLen, Value, StrSize (Value));
BackupChar = Value[ValueStrLen];
*Value++ = L'=';
Value += UnicodeValueToString (
Value,
PREFIX_ZERO | RADIX_HEX,
PrivateData->Configuration.NameValueVar1,
sizeof (PrivateData->Configuration.NameValueVar1) * 2
);
*Value = BackupChar;
}
//
// Append value of NameValueVar2, type is CHAR16 *
//
if ((Value = StrStr (*Results, PrivateData->NameValueName[2])) != NULL) {
Value += StrLen (PrivateData->NameValueName[2]);
ValueStrLen = StrLen (PrivateData->Configuration.NameValueVar2) * 4 + 1;
CopyMem (Value + ValueStrLen, Value, StrSize (Value));
*Value++ = L'=';
//
// Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"
//
StrPointer = (CHAR16 *) PrivateData->Configuration.NameValueVar2;
for (; *StrPointer != L'\0'; StrPointer++) {
Value += UnicodeValueToString (Value, PREFIX_ZERO | RADIX_HEX, *StrPointer, 4);
}
}
Progress = (EFI_STRING *) Request + StrLen (Request);
return EFI_SUCCESS;
}
} }
// //
@ -451,6 +574,13 @@ RouteConfig (
UINTN BufferSize; UINTN BufferSize;
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData; DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
CHAR16 *Value;
CHAR16 *StrPtr;
CHAR16 TemStr[5];
UINT8 *DataBuffer;
UINT8 DigitUint8;
UINTN Index;
CHAR16 *StrBuffer;
if (Configuration == NULL || Progress == NULL) { if (Configuration == NULL || Progress == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -464,7 +594,7 @@ RouteConfig (
// Check routing data in <ConfigHdr>. // Check routing data in <ConfigHdr>.
// Note: if only one Storage is used, then this checking could be skipped. // Note: if only one Storage is used, then this checking could be skipped.
// //
if (!HiiIsConfigHdrMatch (Configuration, &mFormSetGuid, VariableName)) { if (!HiiIsConfigHdrMatch (Configuration, &mFormSetGuid, NULL)) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -483,6 +613,125 @@ RouteConfig (
return Status; return Status;
} }
//
// Check if configuring Name/Value storage
//
if (StrStr (Configuration, L"OFFSET") == NULL) {
//
// Update Name/Value storage Names
//
Status = LoadNameValueNames (PrivateData);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Convert value for NameValueVar0
//
if ((Value = StrStr (Configuration, PrivateData->NameValueName[0])) != NULL) {
//
// Skip "Name="
//
Value += StrLen (PrivateData->NameValueName[0]);
Value++;
//
// Get Value String
//
StrPtr = StrStr (Value, L"&");
if (StrPtr == NULL) {
StrPtr = Value + StrLen (Value);
}
//
// Convert Value to Buffer data
//
DataBuffer = (UINT8 *) &PrivateData->Configuration.NameValueVar0;
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0, StrPtr --; StrPtr >= Value; StrPtr --, Index ++) {
TemStr[0] = *StrPtr;
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
if ((Index & 1) == 0) {
DataBuffer [Index/2] = DigitUint8;
} else {
DataBuffer [Index/2] = (UINT8) ((UINT8) (DigitUint8 << 4) + DataBuffer [Index/2]);
}
}
}
//
// Convert value for NameValueVar1
//
if ((Value = StrStr (Configuration, PrivateData->NameValueName[1])) != NULL) {
//
// Skip "Name="
//
Value += StrLen (PrivateData->NameValueName[1]);
Value++;
//
// Get Value String
//
StrPtr = StrStr (Value, L"&");
if (StrPtr == NULL) {
StrPtr = Value + StrLen (Value);
}
//
// Convert Value to Buffer data
//
DataBuffer = (UINT8 *) &PrivateData->Configuration.NameValueVar1;
ZeroMem (TemStr, sizeof (TemStr));
for (Index = 0, StrPtr --; StrPtr >= Value; StrPtr --, Index ++) {
TemStr[0] = *StrPtr;
DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
if ((Index & 1) == 0) {
DataBuffer [Index/2] = DigitUint8;
} else {
DataBuffer [Index/2] = (UINT8) ((UINT8) (DigitUint8 << 4) + DataBuffer [Index/2]);
}
}
}
//
// Convert value for NameValueVar2
//
if ((Value = StrStr (Configuration, PrivateData->NameValueName[2])) != NULL) {
//
// Skip "Name="
//
Value += StrLen (PrivateData->NameValueName[2]);
Value++;
//
// Get Value String
//
StrPtr = StrStr (Value, L"&");
if (StrPtr == NULL) {
StrPtr = Value + StrLen (Value);
}
//
// Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"
//
StrBuffer = (CHAR16 *) PrivateData->Configuration.NameValueVar2;
ZeroMem (TemStr, sizeof (TemStr));
while (Value < StrPtr) {
StrnCpy (TemStr, Value, 4);
*(StrBuffer++) = (CHAR16) StrHexToUint64 (TemStr);
Value += 4;
}
*StrBuffer = L'\0';
}
//
// Store Buffer Storage back to EFI variable
//
Status = gRT->SetVariable(
VariableName,
&mFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (DRIVER_SAMPLE_CONFIGURATION),
&PrivateData->Configuration
);
return Status;
}
// //
// Convert <ConfigResp> to buffer data by helper function ConfigToBlock() // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
// //
@ -1035,6 +1284,7 @@ DriverSampleInit (
NULL NULL
); );
if (HiiHandle[1] == NULL) { if (HiiHandle[1] == NULL) {
DriverSampleUnload (ImageHandle);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -1047,9 +1297,19 @@ DriverSampleInit (
NewString = L"700 Mhz"; NewString = L"700 Mhz";
if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString, NULL) == 0) { if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString, NULL) == 0) {
DriverSampleUnload (ImageHandle);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
HiiSetString (HiiHandle[0], 0, NewString, NULL);
//
// Initialize Name/Value name String ID
//
PrivateData->NameStringId[0] = STR_NAME_VALUE_VAR_NAME0;
PrivateData->NameStringId[1] = STR_NAME_VALUE_VAR_NAME1;
PrivateData->NameStringId[2] = STR_NAME_VALUE_VAR_NAME2;
// //
// Initialize configuration data // Initialize configuration data
// //
@ -1138,6 +1398,7 @@ DriverSampleUnload (
IN EFI_HANDLE ImageHandle IN EFI_HANDLE ImageHandle
) )
{ {
UINTN Index;
if (DriverHandle[0] != NULL) { if (DriverHandle[0] != NULL) {
gBS->UninstallMultipleProtocolInterfaces ( gBS->UninstallMultipleProtocolInterfaces (
DriverHandle[0], DriverHandle[0],
@ -1169,6 +1430,11 @@ DriverSampleUnload (
} }
if (PrivateData != NULL) { if (PrivateData != NULL) {
for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
if (PrivateData->NameValueName[Index] != NULL) {
FreePool (PrivateData->NameValueName[Index]);
}
}
FreePool (PrivateData); FreePool (PrivateData);
PrivateData = NULL; PrivateData = NULL;
} }

View File

@ -47,13 +47,6 @@ Revision History
#include "NVDataStruc.h" #include "NVDataStruc.h"
//
// This is the generated <AltResp> for defaults defined in VFR
//
extern UINT8 VfrMyIfrNVDataDefault0000[];
extern UINT8 VfrMyIfrNVDataDefault0001[];
extern UINT8 VfrMyIfrNVDataBlockName[];
// //
// This is the generated IFR binary data for each formset defined in VFR. // This is the generated IFR binary data for each formset defined in VFR.
// This data array is ready to be used as input of HiiAddPackages() to // This data array is ready to be used as input of HiiAddPackages() to
@ -72,6 +65,11 @@ extern UINT8 DriverSampleStrings[];
#define DYNAMIC_ONE_OF_VAR_OFFSET OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, DynamicOneof) #define DYNAMIC_ONE_OF_VAR_OFFSET OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, DynamicOneof)
#define DYNAMIC_ORDERED_LIST_VAR_OFFSET OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, DynamicOrderedList) #define DYNAMIC_ORDERED_LIST_VAR_OFFSET OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, DynamicOrderedList)
//
// Number of name in Name/Value storage
//
#define NAME_VALUE_NAME_NUMBER 3
#define DRIVER_SAMPLE_PRIVATE_SIGNATURE SIGNATURE_32 ('D', 'S', 'p', 's') #define DRIVER_SAMPLE_PRIVATE_SIGNATURE SIGNATURE_32 ('D', 'S', 'p', 's')
typedef struct { typedef struct {
@ -82,6 +80,12 @@ typedef struct {
DRIVER_SAMPLE_CONFIGURATION Configuration; DRIVER_SAMPLE_CONFIGURATION Configuration;
UINT8 PasswordState; UINT8 PasswordState;
//
// Name/Value storage Name list
//
EFI_STRING_ID NameStringId[NAME_VALUE_NAME_NUMBER];
EFI_STRING NameValueName[NAME_VALUE_NAME_NUMBER];
// //
// Consumed protocol // Consumed protocol
// //

View File

@ -62,6 +62,10 @@ typedef struct {
UINT8 DynamicRefresh; UINT8 DynamicRefresh;
UINT8 DynamicOneof; UINT8 DynamicOneof;
UINT8 DynamicOrderedList[5]; UINT8 DynamicOrderedList[5];
UINT8 Reserved;
UINT8 NameValueVar0;
UINT16 NameValueVar1;
UINT16 NameValueVar2[20];
} DRIVER_SAMPLE_CONFIGURATION; } DRIVER_SAMPLE_CONFIGURATION;
// //

View File

@ -89,6 +89,15 @@ formset
varsize = 1, // Size of the EFI variable varsize = 1, // Size of the EFI variable
guid = FORMSET_GUID; // EFI variable GUID guid = FORMSET_GUID; // EFI variable GUID
//
// Define a Name/Value Storage (EFI_IFR_VARSTORE_NAME_VALUE)
//
namevaluevarstore MyNameValueVar, // Define storage reference name in vfr
name = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME0), // Define Name list of this storage, refer it by MyNameValueVar[0]
name = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME1), // Define Name list of this storage, refer it by MyNameValueVar[1]
name = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME2), // Define Name list of this storage, refer it by MyNameValueVar[2]
guid = FORMSET_GUID; // GUID of this Name/Value storage
defaultstore MyStandardDefault, defaultstore MyStandardDefault,
prompt = STRING_TOKEN(STR_STANDARD_DEFAULT_PROMPT), prompt = STRING_TOKEN(STR_STANDARD_DEFAULT_PROMPT),
attribute = 0x0000; // Default ID: 0000 standard default attribute = 0x0000; // Default ID: 0000 standard default
@ -323,6 +332,41 @@ formset
endnumeric; endnumeric;
//
// Define numeric using Name/Value Storage
//
numeric varid = MyNameValueVar[0], // This numeric take NameValueVar0 as storage
prompt = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME0),
help = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME0_HELP),
//
// Size should be defined for numeric when use Name/Value storage
// Valid value for numerice size are: NUMERIC_SIZE_1, NUMERIC_SIZE_2, NUMERIC_SIZE_4 and NUMERIC_SIZE_8
//
flags = NUMERIC_SIZE_1, // Size of this numeric is 1 byte
minimum = 0,
maximum = 0xff,
step = 0,
endnumeric;
numeric varid = MyNameValueVar[1], // This numeric take NameValueVar1 as storage
prompt = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME1),
help = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME1_HELP),
flags = NUMERIC_SIZE_2, // Size of this numeric is 2 bytes
minimum = 0,
maximum = 0xffff,
step = 0,
endnumeric;
//
// Define string using Name/Value Storage
//
string varid = MyNameValueVar[2], // This string take NameValueVar2 as storage
prompt = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME2),
help = STRING_TOKEN(STR_NAME_VALUE_VAR_NAME2_HELP),
minsize = 2,
maxsize = 0x14,
endstring;
label LABEL_1_VALUE; label LABEL_1_VALUE;
label LABEL_2_VALUE; label LABEL_2_VALUE;