]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BdsHelper.c
AppPkg: Update email and URL.
[mirror_edk2.git] / ArmPlatformPkg / Bds / BdsHelper.c
index 8553577cf1b1272f63b297033c390a25546a56e4..732292cdb94a0011b701f09c6e6d8f227f05d7aa 100644 (file)
@@ -1,14 +1,14 @@
 /** @file\r
 *\r
 *  Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.\r
-*  \r
-*  This program and the accompanying materials                          \r
-*  are licensed and made available under the terms and conditions of the BSD License         \r
-*  which accompanies this distribution.  The full text of the license may be found at        \r
-*  http://opensource.org/licenses/bsd-license.php                                            \r
 *\r
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 *\r
 **/\r
 \r
@@ -36,7 +36,7 @@ EditHIInputStr (
   Print (CmdLine);\r
 \r
   // To prevent a buffer overflow, we only allow to enter (MaxCmdLine-1) characters\r
-  for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine; ) {
+  for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine; ) {\r
     Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);\r
     ASSERT_EFI_ERROR (Status);\r
 \r
@@ -63,7 +63,7 @@ EditHIInputStr (
       }\r
     } else if ((Key.ScanCode == SCAN_ESC) || (Char == 0x1B) || (Char == 0x0)) {\r
       return EFI_INVALID_PARAMETER;\r
-    } else if (CmdLineIndex < (MaxCmdLine-1)) {
+    } else if (CmdLineIndex < (MaxCmdLine-1)) {\r
       CmdLine[CmdLineIndex++] = Key.UnicodeChar;\r
       Print (L"%c", Key.UnicodeChar);\r
     }\r
@@ -144,16 +144,16 @@ GetHIInputInteger (
   The function asks the user for an IPv4 address. If the input\r
   string defines a valid IPv4 address, the four bytes of the\r
   corresponding IPv4 address are extracted from the string and returned by\r
-  the function.\r
+  the function. As long as the user does not define a valid IP\r
+  address, he is asked for one. He can always escape by\r
+  pressing ESC.\r
 \r
   @param[out]  EFI_IP_ADDRESS  OutIpAddr  Returned IPv4 address. Valid if\r
                                           and only if the returned value\r
                                           is equal to EFI_SUCCESS\r
-
+\r
   @retval  EFI_SUCCESS            Input completed\r
   @retval  EFI_ABORTED            Editing aborted by the user\r
-  @retval  EFI_INVALID_PARAMETER  The string returned by the user is\r
-                                  mal-formated\r
   @retval  EFI_OUT_OF_RESOURCES   Fail to perform the operation due to\r
                                   lack of resource\r
 **/\r
@@ -165,15 +165,20 @@ GetHIInputIP (
   EFI_STATUS  Status;\r
   CHAR16      CmdLine[48];\r
 \r
-  CmdLine[0] = '\0';\r
-  Status = EditHIInputStr (CmdLine, 48);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_ABORTED;\r
-  }\r
-\r
-  Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4);\r
+  while (TRUE) {\r
+    CmdLine[0] = '\0';\r
+    Status = EditHIInputStr (CmdLine, 48);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_ABORTED;\r
+    }\r
 \r
-  return Status;\r
+    Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4);\r
+    if (Status == EFI_INVALID_PARAMETER) {\r
+      Print (L"Invalid address\n");\r
+    } else {\r
+      return Status;\r
+    }\r
+  }\r
 }\r
 \r
 /**\r
@@ -183,13 +188,15 @@ GetHIInputIP (
   IPv4 address that is passed in and asks the user to modify it. If the\r
   resulting string defines a valid IPv4 address, the four bytes of the\r
   corresponding IPv4 address are extracted from the string and returned by\r
-  the function.\r
+  the function. As long as the user does not define a valid IP\r
+  address, he is asked for one. He can always escape by\r
+  pressing ESC.\r
 \r
   @param[in ]  EFI_IP_ADDRESS  InIpAddr   Input IPv4 address\r
   @param[out]  EFI_IP_ADDRESS  OutIpAddr  Returned IPv4 address. Valid if\r
                                           and only if the returned value\r
                                           is equal to EFI_SUCCESS\r
-
+\r
   @retval  EFI_SUCCESS            Update completed\r
   @retval  EFI_ABORTED            Editing aborted by the user\r
   @retval  EFI_INVALID_PARAMETER  The string returned by the user is\r
@@ -206,20 +213,24 @@ EditHIInputIP (
   EFI_STATUS  Status;\r
   CHAR16      CmdLine[48];\r
 \r
-  UnicodeSPrint (
-    CmdLine, 48, L"%d.%d.%d.%d",\r
-    InIpAddr->v4.Addr[0], InIpAddr->v4.Addr[1],\r
-    InIpAddr->v4.Addr[2], InIpAddr->v4.Addr[3]\r
-    );\r
+  while (TRUE) {\r
+    UnicodeSPrint (\r
+      CmdLine, 48, L"%d.%d.%d.%d",\r
+      InIpAddr->v4.Addr[0], InIpAddr->v4.Addr[1],\r
+      InIpAddr->v4.Addr[2], InIpAddr->v4.Addr[3]\r
+      );\r
 \r
-  Status = EditHIInputStr (CmdLine, 48);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_ABORTED;\r
+    Status = EditHIInputStr (CmdLine, 48);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_ABORTED;\r
+    }\r
+    Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4);\r
+    if (Status == EFI_INVALID_PARAMETER) {\r
+      Print (L"Invalid address\n");\r
+    } else {\r
+      return Status;\r
+    }\r
   }\r
-\r
-  Status = NetLibStrToIp4 (CmdLine, &OutIpAddr->v4);\r
-\r
-  return Status;\r
 }\r
 \r
 EFI_STATUS\r
@@ -232,7 +243,7 @@ GetHIInputBoolean (
 \r
   while(1) {\r
     Print (L"[y/n] ");\r
-    Status = GetHIInputStr (CmdBoolean, 2);
+    Status = GetHIInputStr (CmdBoolean, 2);\r
     if (EFI_ERROR(Status)) {\r
       return Status;\r
     } else if ((CmdBoolean[0] == L'y') || (CmdBoolean[0] == L'Y')) {\r
@@ -245,15 +256,6 @@ GetHIInputBoolean (
   }\r
 }\r
 \r
-BOOLEAN\r
-HasFilePathEfiExtension (\r
-  IN CHAR16* FilePath\r
-  )\r
-{\r
-  return (StrCmp (FilePath + (StrSize (FilePath) / sizeof (CHAR16)) - 5, L".EFI") == 0) ||\r
-         (StrCmp (FilePath + (StrSize (FilePath) / sizeof (CHAR16)) - 5, L".efi") == 0);\r
-}\r
-\r
 // Return the last non end-type Device Path Node from a Device Path\r
 EFI_DEVICE_PATH*\r
 GetLastDevicePathNode (\r
@@ -393,7 +395,9 @@ IsUnicodeString (
  * Some limitations:\r
  *   - it only supports unicode string that use ASCII character (< 0x100)\r
  *   - single character ASCII strings are interpreted as Unicode string\r
- *   - string cannot be longer than 2 x BOOT_DEVICE_OPTION_MAX (600 bytes)\r
+ *   - string cannot be longer than BOOT_DEVICE_OPTION_MAX characters and\r
+ *     thus (BOOT_DEVICE_OPTION_MAX*2) bytes for an Unicode string and\r
+ *     BOOT_DEVICE_OPTION_MAX bytes for an ASCII string.\r
  *\r
  * @param String    Buffer that might contain a Unicode or Ascii string\r
  * @param IsUnicode If not NULL this boolean value returns if the string is an\r
@@ -435,7 +439,7 @@ IsPrintableString (
   }\r
 \r
   IsPrintable = FALSE;\r
-  for (Index = 0; Index < BOOT_DEVICE_OPTION_MAX * 2; Index++) {\r
+  for (Index = 0; Index < BOOT_DEVICE_OPTION_MAX; Index++) {\r
     if (UnicodeDetected) {\r
       Character = ((CHAR16*)String)[Index];\r
     } else {\r