]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Ebl/Main.c
EmbeddedPkg: Fix mispellings
[mirror_edk2.git] / EmbeddedPkg / Ebl / Main.c
index d3dcc58a929f0744bea195dbdad6175e2028b5d3..e4879bcf977aa541c244eb58b1a31d14647623e5 100644 (file)
@@ -1,10 +1,10 @@
 /** @file\r
   Basic command line parser for EBL (Embedded Boot Loader)\r
 \r
-  Copyright (c) 2007, Intel Corporation<BR>\r
-  Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
+  Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+  Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 \r
-  All rights reserved. This program and the accompanying materials\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
@@ -151,7 +151,7 @@ Exit:
 \r
 /**\r
   Parse the CmdLine and break it up into Argc (arg count) and Argv (array of\r
-  pointers to each argument). The Cmd buffer is altered and seperators are \r
+  pointers to each argument). The Cmd buffer is altered and separators are\r
   converted to string terminators. This allows Argv to point into CmdLine.\r
   A CmdLine can support multiple commands. The next command in the command line\r
   is returned if it exists.\r
@@ -179,22 +179,22 @@ ParseArguments (
     return NULL;\r
   }\r
 \r
-  // Walk a single command line. A CMD_SEPERATOR allows mult commands on a single line\r
+  // Walk a single command line. A CMD_SEPARATOR allows multiple commands on a single line\r
   InQuote       = FALSE;\r
   LookingForArg = TRUE;\r
   for (Char = CmdLine, Arg = 0; *Char != '\0'; Char++) {\r
-    if (!InQuote && *Char == CMD_SEPERATOR) {\r
+    if (!InQuote && *Char == CMD_SEPARATOR) {\r
       break;\r
     }\r
 \r
-    // Perform any text coversion here\r
+    // Perform any text conversion here\r
     if (*Char == '\t') {\r
       // TAB to space\r
       *Char = ' ';\r
     }\r
 \r
     if (LookingForArg) {\r
-      // Look for the beging of an Argv[] entry\r
+      // Look for the beginning of an Argv[] entry\r
       if (*Char == '"') {\r
         Argv[Arg++] = ++Char;\r
         LookingForArg = FALSE;\r
@@ -205,17 +205,22 @@ ParseArguments (
       } \r
     } else {\r
       // Looking for the terminator of an Argv[] entry\r
-      if ((InQuote && (*Char == '"')) || (!InQuote && (*Char == ' '))) {\r
+      if (!InQuote && (*Char == ' ')) {\r
         *Char = '\0';\r
         LookingForArg = TRUE;\r
+      } else if (!InQuote && (*Char == '"') && (*(Char-1) != '\\')) {\r
+        InQuote = TRUE;\r
+      } else if (InQuote && (*Char == '"') && (*(Char-1) != '\\')) {\r
+        *Char = '\0';\r
+        InQuote = FALSE;\r
       }\r
     }    \r
   }\r
 \r
   *Argc = Arg;\r
 \r
-  if (*Char == CMD_SEPERATOR) {\r
-    // Replace the command delimeter with null and return pointer to next command line\r
+  if (*Char == CMD_SEPARATOR) {\r
+    // Replace the command delimiter with null and return pointer to next command line\r
     *Char = '\0';\r
     return ++Char;\r
   }\r
@@ -226,7 +231,7 @@ ParseArguments (
 \r
 /**\r
   Return a keypress or optionally timeout if a timeout value was passed in.\r
-  An optional callback funciton is called evey second when waiting for a\r
+  An optional callback function is called every second when waiting for a\r
   timeout.\r
 \r
   @param  Key           EFI Key information returned\r
@@ -365,10 +370,10 @@ EblSetTextColor (
 \r
 \r
 /**\r
-  Collect the keyboard input for a cmd line. Carage Return, New Line, or ESC\r
+  Collect the keyboard input for a cmd line. Carriage Return, New Line, or ESC\r
   terminates the command line. You can edit the command line via left arrow,\r
   delete and backspace and they all back up and erase the command line. \r
-  No edit of commnad line is possible without deletion at this time!\r
+  No edit of command line is possible without deletion at this time!\r
   The up arrow and down arrow fill Cmd with information from the history \r
   buffer.\r
 \r
@@ -455,6 +460,45 @@ EblPrintStartupBanner (
 }\r
 \r
 \r
+/**\r
+  Send null requests to all removable media block IO devices so the a media add/remove/change\r
+  can be detected in real before we execute a command. \r
+\r
+  This is mainly due to the fact that the FAT driver does not do this today so you can get stale \r
+  dir commands after an SD Card has been removed.\r
+**/\r
+VOID\r
+EblProbeRemovableMedia (\r
+  VOID\r
+  )\r
+{\r
+  UINTN         Index;\r
+  UINTN         Max;\r
+  EFI_OPEN_FILE *File;\r
+\r
+  //\r
+  // Probe for media insertion/removal in removable media devices\r
+  //\r
+  Max = EfiGetDeviceCounts (EfiOpenBlockIo);\r
+  if (Max != 0) {\r
+    for (Index = 0; Index < Max; Index++) {\r
+      File = EfiDeviceOpenByType (EfiOpenBlockIo, Index);\r
+      if (File != NULL) {\r
+        if (File->FsBlockIoMedia->RemovableMedia) {\r
+          // Probe to see if media is present (or not) or media changed\r
+          //  this causes the ReinstallProtocolInterface() to fire in the\r
+          //  block io driver to update the system about media change events\r
+          File->FsBlockIo->ReadBlocks (File->FsBlockIo, File->FsBlockIo->Media->MediaId, (EFI_LBA)0, 0, NULL);\r
+        }\r
+        EfiClose (File);\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+\r
+\r
+\r
 /**\r
   Print the prompt for the EBL.\r
 **/\r
@@ -464,7 +508,7 @@ EblPrompt (
   )\r
 {\r
   EblSetTextColor (EFI_YELLOW);\r
-  AsciiPrint ((CHAR8 *)PcdGetPtr (PcdEmbeddedPrompt));\r
+  AsciiPrint ("%a %a",(CHAR8 *)PcdGetPtr (PcdEmbeddedPrompt), EfiGetCwd ());\r
   EblSetTextColor (0);\r
   AsciiPrint ("%a", ">");\r
 }\r
@@ -472,7 +516,7 @@ EblPrompt (
 \r
 \r
 /**\r
-  Parse a command line and execute the commands. The ; seperator allows \r
+  Parse a command line and execute the commands. The ; separator allows\r
   multiple commands for each command line. Stop processing if one of the\r
   commands returns an error.\r
 \r
@@ -494,7 +538,7 @@ ProcessCmdLine (
   UINTN               Argc;\r
   CHAR8               *Argv[MAX_ARGS];\r
 \r
-  // Parse the command line. The loop processes commands seperated by ;\r
+  // Parse the command line. The loop processes commands separated by ;\r
   for (Ptr = CmdLine, Status = EFI_SUCCESS; Ptr != NULL;) {\r
     Ptr = ParseArguments (Ptr, &Argc, Argv);\r
     if (Argc != 0) {\r
@@ -506,7 +550,7 @@ ProcessCmdLine (
           // exit command so lets exit\r
           break;\r
         } else if (Status == EFI_TIMEOUT) {\r
-          // pause command got imput so don't process any more cmd on this cmd line\r
+          // pause command got input so don't process any more cmd on this cmd line\r
           break;\r
         } else if (EFI_ERROR (Status)) {\r
           AsciiPrint ("%a returned %r error\n", Cmd->Name, Status);\r
@@ -524,14 +568,14 @@ ProcessCmdLine (
 \r
 /**\r
   Embedded Boot Loader (EBL) - A simple EFI command line application for embedded \r
-  devices. PcdEmbeddedAutomaticBootCommand is a complied in commnad line that\r
-  gets executed automatically. The ; seperator allows multiple commands \r
+  devices. PcdEmbeddedAutomaticBootCommand is a complied in command line that\r
+  gets executed automatically. The ; separator allows multiple commands\r
   for each command line.\r
 \r
   @param  ImageHandle   EFI ImageHandle for this application.\r
   @param  SystemTable   EFI system table\r
 \r
-  @return EFI status of the applicaiton\r
+  @return EFI status of the application\r
 \r
 **/\r
 EFI_STATUS\r
@@ -548,7 +592,7 @@ EdkBootLoaderEntry (
   UINTN       CommandLineVariableSize = 0;\r
   EFI_GUID    VendorGuid;\r
 \r
-  // Initialize tables of commnads\r
+  // Initialize tables of commands\r
   EblInitializeCmdTable ();\r
   EblInitializeDeviceCmd ();\r
   EblInitializemdHwDebugCmds ();\r
@@ -558,7 +602,16 @@ EdkBootLoaderEntry (
   EblInitializeScriptCmd ();\r
   EblInitializeExternalCmd ();\r
   EblInitializeNetworkCmd();\r
+  EblInitializeVariableCmds ();\r
   \r
+  if (gST->ConOut == NULL) {\r
+    DEBUG((EFI_D_ERROR,"Error: No Console Output\n"));\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  // Disable the 5 minute EFI watchdog time so we don't get automatically reset\r
+  gBS->SetWatchdogTimer (0, 0, 0, NULL);\r
+\r
   if (FeaturePcdGet (PcdEmbeddedMacBoot)) {\r
     // A MAC will boot in graphics mode, so turn it back to text here\r
     // This protocol was removed from edk2. It is only an edk thing. We need to make our own copy.\r
@@ -567,8 +620,6 @@ EdkBootLoaderEntry (
     // Enable the biggest output screen size possible\r
     gST->ConOut->SetMode (gST->ConOut, (UINTN)gST->ConOut->Mode->MaxMode - 1);\r
 \r
-    // Disable the 5 minute EFI watchdog time so we don't get automatically reset\r
-    gBS->SetWatchdogTimer (0, 0, 0, NULL);\r
   }\r
 \r
   // Save current screen mode\r
@@ -576,7 +627,7 @@ EdkBootLoaderEntry (
 \r
   EblPrintStartupBanner ();\r
  \r
-  // Parse command line and handle commands seperated by ;\r
+  // Parse command line and handle commands separated by ;\r
   // The loop prints the prompt gets user input and saves history\r
   \r
   // Look for a variable with a default command line, otherwise use the Pcd\r
@@ -610,6 +661,11 @@ EdkBootLoaderEntry (
     EblPrompt ();\r
     GetCmd (CmdLine, MAX_CMD_LINE);\r
     SetCmdHistory (CmdLine);\r
+\r
+    if (FeaturePcdGet (PcdEmbeddedProbeRemovable)) {\r
+      // Probe removable media devices to see if media has been inserted or removed.\r
+      EblProbeRemovableMedia ();\r
+    }\r
   }\r
 }\r
 \r