]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/Shell.c
ShellPkg: Fixes and updates for the 'drivers' command
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.c
index fa7201642a1cf07c22ea724b7cf8a3358cb2fca2..2f1e3eb65c89ecdce0a16f4cddd9f17109f8ea78 100644 (file)
@@ -509,6 +509,7 @@ UefiMain (
           // Reset page break back to default.\r
           //\r
           ShellInfoObject.PageBreakEnabled        = PcdGetBool(PcdShellPageBreakDefault);\r
+          ASSERT (ShellInfoObject.ConsoleInfo != NULL);\r
           ShellInfoObject.ConsoleInfo->Enabled    = TRUE;\r
           ShellInfoObject.ConsoleInfo->RowCounter = 0;\r
 \r
@@ -835,9 +836,13 @@ ProcessCommandLine(
   ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit         = FALSE;\r
   ShellInfoObject.ShellInitSettings.Delay = 5;\r
 \r
-  // Start LoopVar at 1 to ignore Argv[0] which is the name of this binary\r
-  // (probably "Shell.efi")\r
-  for (LoopVar = 1 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r
+  //\r
+  // Start LoopVar at 0 to parse only optional arguments at Argv[0]\r
+  // and parse other parameters from Argv[1].  This is for use case that\r
+  // UEFI Shell boot option is created, and OptionalData is provided\r
+  // that starts with shell command-line options.\r
+  //\r
+  for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r
     CurrentArg = gEfiShellParametersProtocol->Argv[LoopVar];\r
     if (UnicodeCollation->StriColl (\r
                             UnicodeCollation,\r
@@ -925,6 +930,13 @@ ProcessCommandLine(
         );\r
       return EFI_INVALID_PARAMETER;\r
     } else {\r
+      //\r
+      // First argument should be Shell.efi image name\r
+      //\r
+      if (LoopVar == 0) {\r
+        continue;\r
+      }\r
+\r
       ShellInfoObject.ShellInitSettings.FileName = AllocateZeroPool(StrSize(CurrentArg));\r
       if (ShellInfoObject.ShellInitSettings.FileName == NULL) {\r
         return (EFI_OUT_OF_RESOURCES);\r
@@ -1367,14 +1379,14 @@ StripUnreplacedEnvironmentVariables(
     }\r
     ASSERT(FirstPercent < FirstQuote);\r
     if (SecondPercent < FirstQuote) {\r
-      //\r
-      // We need to remove from FirstPercent to SecondPercent\r
-      //\r
-      CopyMem(FirstPercent, SecondPercent + 1, StrSize(SecondPercent + 1));\r
+      FirstPercent[0] = L'\"';\r
+      SecondPercent[0] = L'\"';\r
 \r
       //\r
-      // dont need to update the locator.  both % characters are gone.\r
+      // We need to remove from FirstPercent to SecondPercent\r
       //\r
+      CopyMem(FirstPercent + 1, SecondPercent, StrSize(SecondPercent));\r
+      CurrentLocator = FirstPercent + 2;\r
       continue;\r
     }\r
     ASSERT(FirstQuote < SecondPercent);\r
@@ -2080,6 +2092,7 @@ ProcessCommandLineToFinal(
   if (EFI_ERROR(Status)) {\r
     return (Status);\r
   }\r
+  ASSERT (*CmdLine != NULL);\r
 \r
   TrimSpaces(CmdLine);\r
 \r
@@ -2220,6 +2233,7 @@ RunCommandOrFile(
 )\r
 {\r
   EFI_STATUS                Status;\r
+  EFI_STATUS                StartStatus;\r
   CHAR16                    *CommandWithPath;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
   SHELL_STATUS              CalleeExitStatus;\r
@@ -2297,6 +2311,7 @@ RunCommandOrFile(
             DevPath,\r
             CmdLine,\r
             NULL,\r
+            &StartStatus,\r
             NULL,\r
             NULL\r
            );\r
@@ -2306,7 +2321,7 @@ RunCommandOrFile(
           if(EFI_ERROR (Status)) {\r
             CalleeExitStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
           } else {\r
-            CalleeExitStatus = SHELL_SUCCESS;\r
+            CalleeExitStatus = (SHELL_STATUS) StartStatus;\r
           }\r
 \r
           //\r