]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Refine the logic to handle the device path info get from string token.
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 14 Aug 2012 09:52:25 +0000 (09:52 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 14 Aug 2012 09:52:25 +0000 (09:52 +0000)
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

MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
MdeModulePkg/Universal/SetupBrowserDxe/Ui.h

index a76c86791a0fe3c98b9537cad47b5800c0691747..854a5a729156812e6f311c0546fa8a879009e1ea 100644 (file)
@@ -1766,6 +1766,44 @@ DriverCallback (
   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
@@ -1802,6 +1840,8 @@ DriverSampleInit (
   // 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
@@ -1921,11 +1961,15 @@ DriverSampleInit (
   //\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
index ff46fcbc5a7df49a30eb39692baa7ac780f58cf6..27be635e9c7c1b6e21b0c07e530c044564585a8b 100644 (file)
@@ -2210,6 +2210,7 @@ EvaluateExpression (
   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
@@ -2475,11 +2476,17 @@ EvaluateExpression (
           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
index a2f336c2a4bdd13d446bca0a1f2c8a1361cef9be..e16b2e424a7338106afd9dff304942294dc26d28 100644 (file)
@@ -1948,6 +1948,55 @@ FormSetGuidToHiiHandle (
   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
@@ -1968,13 +2017,7 @@ ProcessGotoOpCode (
   )\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
@@ -1984,22 +2027,18 @@ ProcessGotoOpCode (
   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
@@ -2007,33 +2046,11 @@ ProcessGotoOpCode (
     // 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
index c9064f31440f2ffde062432d7827ba6ea38b20e5..fca33b71e567ef13fe9df082286c823663f43159 100644 (file)
@@ -1028,4 +1028,17 @@ EvaluateExpressionList (
   IN FORM_BROWSER_FORM    *Form OPTIONAL\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
 #endif // _UI_H\r