diff options
Diffstat (limited to 'MdeModulePkg')
-rw-r--r-- | MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c | 270 | ||||
-rw-r--r-- | MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h | 18 | ||||
-rw-r--r-- | MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h | 4 | ||||
-rw-r--r-- | MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr | 44 | ||||
-rw-r--r-- | MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni | bin | 38442 -> 40902 bytes |
5 files changed, 327 insertions, 9 deletions
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c index 3912946958..52d9b837bd 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c @@ -301,6 +301,38 @@ SetPassword ( 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
@@ -344,6 +376,11 @@ ExtractConfig ( EFI_STRING ConfigRequest;
EFI_STRING ConfigRequestHdr;
UINTN Size;
+ EFI_STRING Value;
+ UINTN ValueStrLen;
+ CHAR16 BackupChar;
+ CHAR16 *StrPointer;
+
if (Progress == NULL || Results == NULL || Request == NULL) {
return EFI_INVALID_PARAMETER;
@@ -394,10 +431,96 @@ ExtractConfig ( // Check routing data in <ConfigHdr>.
// 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;
}
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;
DRIVER_SAMPLE_PRIVATE_DATA *PrivateData;
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) {
return EFI_INVALID_PARAMETER;
@@ -464,7 +594,7 @@ RouteConfig ( // Check routing data in <ConfigHdr>.
// 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;
}
@@ -484,6 +614,125 @@ RouteConfig ( }
//
+ // 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()
//
BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);
@@ -1035,6 +1284,7 @@ DriverSampleInit ( NULL
);
if (HiiHandle[1] == NULL) {
+ DriverSampleUnload (ImageHandle);
return EFI_OUT_OF_RESOURCES;
}
@@ -1047,9 +1297,19 @@ DriverSampleInit ( NewString = L"700 Mhz";
if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString, NULL) == 0) {
+ DriverSampleUnload (ImageHandle);
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
//
@@ -1138,6 +1398,7 @@ DriverSampleUnload ( IN EFI_HANDLE ImageHandle
)
{
+ UINTN Index;
if (DriverHandle[0] != NULL) {
gBS->UninstallMultipleProtocolInterfaces (
DriverHandle[0],
@@ -1169,6 +1430,11 @@ DriverSampleUnload ( }
if (PrivateData != NULL) {
+ for (Index = 0; Index < NAME_VALUE_NAME_NUMBER; Index++) {
+ if (PrivateData->NameValueName[Index] != NULL) {
+ FreePool (PrivateData->NameValueName[Index]);
+ }
+ }
FreePool (PrivateData);
PrivateData = NULL;
}
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h index ebe40a2948..86f41a107b 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h @@ -48,13 +48,6 @@ Revision History #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 data array is ready to be used as input of HiiAddPackages() to
// create a packagelist (which contains Form packages, String packages, etc).
@@ -72,6 +65,11 @@ extern UINT8 DriverSampleStrings[]; #define DYNAMIC_ONE_OF_VAR_OFFSET OFFSET_OF (DRIVER_SAMPLE_CONFIGURATION, DynamicOneof)
#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')
typedef struct {
@@ -83,6 +81,12 @@ typedef struct { UINT8 PasswordState;
//
+ // Name/Value storage Name list
+ //
+ EFI_STRING_ID NameStringId[NAME_VALUE_NAME_NUMBER];
+ EFI_STRING NameValueName[NAME_VALUE_NAME_NUMBER];
+
+ //
// Consumed protocol
//
EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h b/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h index bdc4a46147..648b6dba91 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h +++ b/MdeModulePkg/Universal/DriverSampleDxe/NVDataStruc.h @@ -62,6 +62,10 @@ typedef struct { UINT8 DynamicRefresh;
UINT8 DynamicOneof;
UINT8 DynamicOrderedList[5];
+ UINT8 Reserved;
+ UINT8 NameValueVar0;
+ UINT16 NameValueVar1;
+ UINT16 NameValueVar2[20];
} DRIVER_SAMPLE_CONFIGURATION;
//
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr index 8a0a863e3f..bc821a61b5 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr +++ b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr @@ -89,6 +89,15 @@ formset varsize = 1, // Size of the EFI variable
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,
prompt = STRING_TOKEN(STR_STANDARD_DEFAULT_PROMPT),
attribute = 0x0000; // Default ID: 0000 standard default
@@ -323,6 +332,41 @@ formset 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_2_VALUE;
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni Binary files differindex c687bf7d84..355538a9a5 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni +++ b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni |