]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/EblExternCmd/EntryPointGlue.c
Adding support for BeagleBoard.
[mirror_edk2.git] / EmbeddedPkg / EblExternCmd / EntryPointGlue.c
diff --git a/EmbeddedPkg/EblExternCmd/EntryPointGlue.c b/EmbeddedPkg/EblExternCmd/EntryPointGlue.c
new file mode 100644 (file)
index 0000000..1e26fb5
--- /dev/null
@@ -0,0 +1,152 @@
+/** @file\r
+  Glue code that contains the EFI entry point and converts it to an EBL \r
+  ASCII Argc, Argv sytle entry point\r
+\r
+\r
+  Copyright (c) 2007, Intel Corporation<BR>\r
+  Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
+\r
+  All rights reserved. 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
+\r
+#define CMD_SEPERATOR     ';'\r
+#define MAX_ARGS          32\r
+\r
+EFI_STATUS\r
+EblMain (\r
+  IN UINTN  Argc,\r
+  IN CHAR8  **Argv\r
+  );\r
+\r
+\r
+///\r
+/// EdkExternCmdEntry() & ParseArguments() convert the standard EFI entry point\r
+/// into Argc, Argv form that calls EblMain().\r
+///\r
+\r
+\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
+  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
+\r
+  @param  CmdLine     String to parse for a set of commands\r
+  @param  CmdLineSize Size of CmdLine in bytes\r
+  @param  Argc        Returns the number of arguments in the CmdLine current command\r
+  @param  Argv        Argc pointers to each string in CmdLine\r
+\r
+  @return Next Command in the command line or NULL if non exists\r
+**/\r
+VOID\r
+ParseArguments (\r
+  IN  CHAR8  *CmdLine,\r
+  IN  UINTN  CmdLineSize,\r
+  OUT UINTN  *Argc,\r
+  OUT CHAR8  **Argv\r
+  )\r
+{\r
+  UINTN   Arg;\r
+  CHAR8   *Char;\r
+  BOOLEAN LookingForArg;\r
+  BOOLEAN InQuote;\r
+  UINTN   Index;\r
+\r
+  *Argc = 0;\r
+  if ((CmdLineSize == 0) || (AsciiStrLen (CmdLine) == 0)) {\r
+    // basic error checking failed on the arguments\r
+    return;\r
+  }\r
+\r
+  // Walk a single command line. A CMD_SEPERATOR allows mult commands on a single line\r
+  InQuote       = FALSE;\r
+  LookingForArg = TRUE;\r
+  for (Char = CmdLine, Arg = 0, Index = 0; *Char != '\0' && *Char != CMD_SEPERATOR; Char++, Index++) {\r
+    // Perform any text coversion 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
+      if (*Char == '"') {\r
+        Argv[Arg++] = ++Char;\r
+        LookingForArg = FALSE;\r
+        InQuote = TRUE;\r
+      } else if (*Char != ' ') {\r
+        Argv[Arg++] = Char;\r
+        LookingForArg = FALSE;\r
+      } \r
+    } else {\r
+      // Looking for the terminator of an Argv[] entry\r
+      if ((InQuote && (*Char == '"')) || (!InQuote && (*Char == ' '))) {\r
+        *Char = '\0';\r
+        LookingForArg = TRUE;\r
+      }\r
+    }\r
+\r
+    if ((Arg >= MAX_ARGS) || (Index > CmdLineSize)) {\r
+      // Error check buffer and exit since it does not look valid\r
+      break;\r
+    }\r
+  }\r
+\r
+  *Argc = Arg;\r
+\r
+  if (*Char == CMD_SEPERATOR) {\r
+    // Replace the command delimeter with null\r
+    *Char = '\0';\r
+  }\r
+\r
+  return;\r
+}\r
\r
+\r
+\r
+\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
+  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
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EdkExternCmdEntry (\r
+  IN EFI_HANDLE                            ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                      *SystemTable\r
+  ) \r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_LOADED_IMAGE_PROTOCOL   *ImageInfo;\r
+  UINTN                       Argc;\r
+  CHAR8                       *Argv[MAX_ARGS];\r
+\r
+  Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&ImageInfo);\r
+  if (EFI_ERROR (Status)) {\r
+    Argc = 0;\r
+  } else {\r
+    // Looks like valid commands were passed in. \r
+    ParseArguments (ImageInfo->LoadOptions, ImageInfo->LoadOptionsSize, &Argc, Argv);\r
+  }\r
+      \r
+  return EblMain (Argc, Argv);\r
+}\r
+\r
+\r