summaryrefslogtreecommitdiff
path: root/MdeModulePkg
diff options
context:
space:
mode:
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>2012-08-14 09:52:25 +0000
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>2012-08-14 09:52:25 +0000
commit33efdf51b0f123259dec0bfcff49af189b46c411 (patch)
treeca64b594e5609249f17a720ab2758342c68cbb89 /MdeModulePkg
parentd0bf562330e5309a92e55e44063a8ea37ead4d1d (diff)
downloadedk2-platforms-33efdf51b0f123259dec0bfcff49af189b46c411.tar.xz
Refine the logic to handle the device path info get from string token.
Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13632 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c48
-rw-r--r--MdeModulePkg/Universal/SetupBrowserDxe/Expression.c13
-rw-r--r--MdeModulePkg/Universal/SetupBrowserDxe/Ui.c87
-rw-r--r--MdeModulePkg/Universal/SetupBrowserDxe/Ui.h13
4 files changed, 121 insertions, 40 deletions
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
index a76c86791a..854a5a7291 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
+++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
@@ -1766,6 +1766,44 @@ DriverCallback (
return Status;
}
+
+/**
+ Transfer the binary device path to string.
+
+ @param DevicePath The device path info.
+
+ @retval Device path string info.
+
+**/
+CHAR16 *
+GenerateDevicePathString (
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ CHAR16 *String;
+ CHAR16 *TmpBuf;
+ UINTN Index;
+ UINT8 *Buffer;
+ UINTN DevicePathSize;
+
+ //
+ // Compute the size of the device path in bytes
+ //
+ DevicePathSize = GetDevicePathSize (DevicePath);
+
+ String = AllocateZeroPool ((DevicePathSize * 2 + 1) * sizeof (CHAR16));
+ if (String == NULL) {
+ return NULL;
+ }
+
+ TmpBuf = String;
+ for (Index = 0, Buffer = (UINT8 *)DevicePath; Index < DevicePathSize; Index++) {
+ TmpBuf += UnicodeValueToString (TmpBuf, PREFIX_ZERO | RADIX_HEX, *(Buffer++), 2);
+ }
+
+ return String;
+}
+
/**
Main entry for this driver.
@@ -1802,6 +1840,8 @@ DriverSampleInit (
// Initialize the local variables.
//
ConfigRequestHdr = NULL;
+ NewString = NULL;
+
//
// Initialize screen dimensions for SendForm().
// Remove 3 characters from top and bottom
@@ -1921,11 +1961,15 @@ DriverSampleInit (
//
// Update the device path string.
//
- if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), (EFI_STRING) &mHiiVendorDevicePath0, NULL) == 0) {
+ NewString = GenerateDevicePathString((EFI_DEVICE_PATH_PROTOCOL*)&mHiiVendorDevicePath0);
+ if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), NewString, NULL) == 0) {
DriverSampleUnload (ImageHandle);
return EFI_OUT_OF_RESOURCES;
}
-
+ if (NewString != NULL) {
+ FreePool (NewString);
+ }
+
//
// Very simple example of how one would update a string that is already
// in the HII database
diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Expression.c b/MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
index ff46fcbc5a..27be635e9c 100644
--- a/MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
+++ b/MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
@@ -2210,6 +2210,7 @@ EvaluateExpression (
UINT8 *TempBuffer;
EFI_TIME EfiTime;
EFI_HII_VALUE QuestionVal;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
//
// Save current stack offset.
@@ -2475,11 +2476,17 @@ EvaluateExpression (
break;
}
- if (!GetQuestionValueFromForm((EFI_DEVICE_PATH_PROTOCOL*)StrPtr, NULL, &OpCode->Guid, Value->Value.u16, &QuestionVal)){
+ DevicePath = ConvertDevicePathFromText(StrPtr);
+
+ if (!GetQuestionValueFromForm(DevicePath, NULL, &OpCode->Guid, Value->Value.u16, &QuestionVal)){
Value->Type = EFI_IFR_TYPE_UNDEFINED;
- break;
+ } else {
+ Value = &QuestionVal;
+ }
+
+ if (DevicePath != NULL) {
+ FreePool (DevicePath);
}
- Value = &QuestionVal;
} else if (CompareGuid (&OpCode->Guid, &gZeroGuid) != 0) {
if (!GetQuestionValueFromForm(NULL, FormSet->HiiHandle, &OpCode->Guid, Value->Value.u16, &QuestionVal)){
Value->Type = EFI_IFR_TYPE_UNDEFINED;
diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c b/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
index a2f336c2a4..e16b2e424a 100644
--- a/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
+++ b/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
@@ -1949,6 +1949,55 @@ FormSetGuidToHiiHandle (
}
/**
+ Transfer the device path string to binary format.
+
+ @param StringPtr The device path string info.
+
+ @retval Device path binary info.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+ConvertDevicePathFromText (
+ IN CHAR16 *StringPtr
+ )
+{
+ UINTN BufferSize;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ CHAR16 TemStr[2];
+ UINT8 *DevicePathBuffer;
+ UINTN Index;
+ UINT8 DigitUint8;
+
+ ASSERT (StringPtr != NULL);
+
+ BufferSize = StrLen (StringPtr) / 2;
+ DevicePath = AllocatePool (BufferSize);
+ ASSERT (DevicePath != NULL);
+
+ //
+ // Convert from Device Path String to DevicePath Buffer in the reverse order.
+ //
+ DevicePathBuffer = (UINT8 *) DevicePath;
+ for (Index = 0; StringPtr[Index] != L'\0'; Index ++) {
+ TemStr[0] = StringPtr[Index];
+ DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
+ if (DigitUint8 == 0 && TemStr[0] != L'0') {
+ //
+ // Invalid Hex Char as the tail.
+ //
+ break;
+ }
+ if ((Index & 1) == 0) {
+ DevicePathBuffer [Index/2] = DigitUint8;
+ } else {
+ DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);
+ }
+ }
+
+ return DevicePath;
+}
+
+/**
Process the goto op code, update the info in the selection structure.
@param Statement The statement belong to goto op code.
@@ -1968,13 +2017,7 @@ ProcessGotoOpCode (
)
{
CHAR16 *StringPtr;
- UINTN StringLen;
- UINTN BufferSize;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- CHAR16 TemStr[2];
- UINT8 *DevicePathBuffer;
- UINTN Index;
- UINT8 DigitUint8;
FORM_BROWSER_FORM *RefForm;
EFI_INPUT_KEY Key;
EFI_STATUS Status;
@@ -1984,22 +2027,18 @@ ProcessGotoOpCode (
Status = EFI_SUCCESS;
UpdateFormInfo = TRUE;
StringPtr = NULL;
- StringLen = 0;
//
// Prepare the device path check, get the device path info first.
//
if (Statement->HiiValue.Value.ref.DevicePath != 0) {
StringPtr = GetToken (Statement->HiiValue.Value.ref.DevicePath, Selection->FormSet->HiiHandle);
- if (StringPtr != NULL) {
- StringLen = StrLen (StringPtr);
- }
}
//
// Check whether the device path string is a valid string.
//
- if (Statement->HiiValue.Value.ref.DevicePath != 0 && StringPtr != NULL && StringLen != 0) {
+ if (Statement->HiiValue.Value.ref.DevicePath != 0 && StringPtr != NULL) {
if (Selection->Form->ModalForm) {
return Status;
}
@@ -2007,33 +2046,11 @@ ProcessGotoOpCode (
// Goto another Hii Package list
//
Selection->Action = UI_ACTION_REFRESH_FORMSET;
- BufferSize = StrLen (StringPtr) / 2;
- DevicePath = AllocatePool (BufferSize);
- ASSERT (DevicePath != NULL);
-
- //
- // Convert from Device Path String to DevicePath Buffer in the reverse order.
- //
- DevicePathBuffer = (UINT8 *) DevicePath;
- for (Index = 0; StringPtr[Index] != L'\0'; Index ++) {
- TemStr[0] = StringPtr[Index];
- DigitUint8 = (UINT8) StrHexToUint64 (TemStr);
- if (DigitUint8 == 0 && TemStr[0] != L'0') {
- //
- // Invalid Hex Char as the tail.
- //
- break;
- }
- if ((Index & 1) == 0) {
- DevicePathBuffer [Index/2] = DigitUint8;
- } else {
- DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);
- }
- }
- FreePool (StringPtr);
+ DevicePath = ConvertDevicePathFromText (StringPtr);
Selection->Handle = DevicePathToHiiHandle (DevicePath);
FreePool (DevicePath);
+ FreePool (StringPtr);
if (Selection->Handle == NULL) {
//
diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Ui.h b/MdeModulePkg/Universal/SetupBrowserDxe/Ui.h
index c9064f3144..fca33b71e5 100644
--- a/MdeModulePkg/Universal/SetupBrowserDxe/Ui.h
+++ b/MdeModulePkg/Universal/SetupBrowserDxe/Ui.h
@@ -1028,4 +1028,17 @@ EvaluateExpressionList (
IN FORM_BROWSER_FORM *Form OPTIONAL
);
+/**
+ Transfer the device path string to binary format.
+
+ @param StringPtr The device path string info.
+
+ @retval Device path binary info.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+ConvertDevicePathFromText (
+ IN CHAR16 *StringPtr
+ );
+
#endif // _UI_H