return Status;\r
}\r
\r
+\r
+/**\r
+ Transfer the binary device path to string.\r
+\r
+ @param DevicePath The device path info.\r
+\r
+ @retval Device path string info.\r
+\r
+**/\r
+CHAR16 *\r
+GenerateDevicePathString (\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
+ )\r
+{\r
+ CHAR16 *String;\r
+ CHAR16 *TmpBuf;\r
+ UINTN Index;\r
+ UINT8 *Buffer;\r
+ UINTN DevicePathSize;\r
+\r
+ //\r
+ // Compute the size of the device path in bytes\r
+ //\r
+ DevicePathSize = GetDevicePathSize (DevicePath);\r
+ \r
+ String = AllocateZeroPool ((DevicePathSize * 2 + 1) * sizeof (CHAR16));\r
+ if (String == NULL) {\r
+ return NULL;\r
+ }\r
+\r
+ TmpBuf = String;\r
+ for (Index = 0, Buffer = (UINT8 *)DevicePath; Index < DevicePathSize; Index++) {\r
+ TmpBuf += UnicodeValueToString (TmpBuf, PREFIX_ZERO | RADIX_HEX, *(Buffer++), 2);\r
+ }\r
+\r
+ return String;\r
+}\r
+\r
/**\r
Main entry for this driver.\r
\r
// Initialize the local variables.\r
//\r
ConfigRequestHdr = NULL;\r
+ NewString = NULL;\r
+\r
//\r
// Initialize screen dimensions for SendForm().\r
// Remove 3 characters from top and bottom\r
//\r
// Update the device path string.\r
//\r
- if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), (EFI_STRING) &mHiiVendorDevicePath0, NULL) == 0) {\r
+ NewString = GenerateDevicePathString((EFI_DEVICE_PATH_PROTOCOL*)&mHiiVendorDevicePath0);\r
+ if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), NewString, NULL) == 0) {\r
DriverSampleUnload (ImageHandle);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
- \r
+ if (NewString != NULL) {\r
+ FreePool (NewString);\r
+ }\r
+\r
//\r
// Very simple example of how one would update a string that is already\r
// in the HII database\r
UINT8 *TempBuffer;\r
EFI_TIME EfiTime;\r
EFI_HII_VALUE QuestionVal;\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
\r
//\r
// Save current stack offset.\r
break;\r
}\r
\r
- if (!GetQuestionValueFromForm((EFI_DEVICE_PATH_PROTOCOL*)StrPtr, NULL, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
+ DevicePath = ConvertDevicePathFromText(StrPtr);\r
+\r
+ if (!GetQuestionValueFromForm(DevicePath, NULL, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
- break;\r
+ } else {\r
+ Value = &QuestionVal;\r
+ }\r
+\r
+ if (DevicePath != NULL) {\r
+ FreePool (DevicePath);\r
}\r
- Value = &QuestionVal;\r
} else if (CompareGuid (&OpCode->Guid, &gZeroGuid) != 0) {\r
if (!GetQuestionValueFromForm(NULL, FormSet->HiiHandle, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
return HiiHandle;\r
}\r
\r
+/**\r
+ Transfer the device path string to binary format.\r
+\r
+ @param StringPtr The device path string info.\r
+\r
+ @retval Device path binary info.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+ConvertDevicePathFromText (\r
+ IN CHAR16 *StringPtr\r
+ )\r
+{\r
+ UINTN BufferSize;\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
+ CHAR16 TemStr[2];\r
+ UINT8 *DevicePathBuffer;\r
+ UINTN Index;\r
+ UINT8 DigitUint8;\r
+\r
+ ASSERT (StringPtr != NULL);\r
+\r
+ BufferSize = StrLen (StringPtr) / 2;\r
+ DevicePath = AllocatePool (BufferSize);\r
+ ASSERT (DevicePath != NULL);\r
+ \r
+ //\r
+ // Convert from Device Path String to DevicePath Buffer in the reverse order.\r
+ //\r
+ DevicePathBuffer = (UINT8 *) DevicePath;\r
+ for (Index = 0; StringPtr[Index] != L'\0'; Index ++) {\r
+ TemStr[0] = StringPtr[Index];\r
+ DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
+ if (DigitUint8 == 0 && TemStr[0] != L'0') {\r
+ //\r
+ // Invalid Hex Char as the tail.\r
+ //\r
+ break;\r
+ }\r
+ if ((Index & 1) == 0) {\r
+ DevicePathBuffer [Index/2] = DigitUint8;\r
+ } else {\r
+ DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);\r
+ }\r
+ }\r
+\r
+ return DevicePath;\r
+}\r
+\r
/**\r
Process the goto op code, update the info in the selection structure.\r
\r
)\r
{\r
CHAR16 *StringPtr;\r
- UINTN StringLen;\r
- UINTN BufferSize;\r
EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
- CHAR16 TemStr[2];\r
- UINT8 *DevicePathBuffer;\r
- UINTN Index;\r
- UINT8 DigitUint8;\r
FORM_BROWSER_FORM *RefForm;\r
EFI_INPUT_KEY Key;\r
EFI_STATUS Status;\r
Status = EFI_SUCCESS;\r
UpdateFormInfo = TRUE;\r
StringPtr = NULL;\r
- StringLen = 0;\r
\r
//\r
// Prepare the device path check, get the device path info first.\r
//\r
if (Statement->HiiValue.Value.ref.DevicePath != 0) {\r
StringPtr = GetToken (Statement->HiiValue.Value.ref.DevicePath, Selection->FormSet->HiiHandle);\r
- if (StringPtr != NULL) {\r
- StringLen = StrLen (StringPtr);\r
- }\r
}\r
\r
//\r
// Check whether the device path string is a valid string.\r
//\r
- if (Statement->HiiValue.Value.ref.DevicePath != 0 && StringPtr != NULL && StringLen != 0) {\r
+ if (Statement->HiiValue.Value.ref.DevicePath != 0 && StringPtr != NULL) {\r
if (Selection->Form->ModalForm) {\r
return Status;\r
}\r
// Goto another Hii Package list\r
//\r
Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
- BufferSize = StrLen (StringPtr) / 2;\r
- DevicePath = AllocatePool (BufferSize);\r
- ASSERT (DevicePath != NULL);\r
-\r
- //\r
- // Convert from Device Path String to DevicePath Buffer in the reverse order.\r
- //\r
- DevicePathBuffer = (UINT8 *) DevicePath;\r
- for (Index = 0; StringPtr[Index] != L'\0'; Index ++) {\r
- TemStr[0] = StringPtr[Index];\r
- DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
- if (DigitUint8 == 0 && TemStr[0] != L'0') {\r
- //\r
- // Invalid Hex Char as the tail.\r
- //\r
- break;\r
- }\r
- if ((Index & 1) == 0) {\r
- DevicePathBuffer [Index/2] = DigitUint8;\r
- } else {\r
- DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);\r
- }\r
- }\r
- FreePool (StringPtr);\r
+ DevicePath = ConvertDevicePathFromText (StringPtr);\r
\r
Selection->Handle = DevicePathToHiiHandle (DevicePath);\r
FreePool (DevicePath);\r
+ FreePool (StringPtr);\r
\r
if (Selection->Handle == NULL) {\r
//\r