]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.c
Adding support for BeagleBoard.
[mirror_edk2.git] / EmbeddedPkg / Library / EblAddExternalCommandLib / EblAddExternalCommandLib.c
diff --git a/EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.c b/EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.c
new file mode 100644 (file)
index 0000000..fcb533c
--- /dev/null
@@ -0,0 +1,156 @@
+/** @file\r
+  Add external EblCmd Lib\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
+#include <PiDxe.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/EblAddExternalCommandLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+\r
+STATIC BOOLEAN   gInstalledCommand = FALSE;\r
+STATIC EFI_EVENT mEblCommandRegistration = NULL;\r
+\r
+STATIC const EBL_COMMAND_TABLE *mAddExternalCmdLibTemplate = NULL;\r
+STATIC UINTN                   mAddExternalCmdLibTemplateSize = 0;\r
+EBL_ADD_COMMAND_PROTOCOL      *gEblExternalCommand = NULL;\r
+\r
+\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
+  timeout.\r
+\r
+  @param  Key           EFI Key information returned\r
+  @param  TimeoutInSec  Number of seconds to wait to timeout\r
+  @param  CallBack      Callback called every second during the timeout wait \r
+\r
+  @return EFI_SUCCESS  Key was returned\r
+  @return EFI_TIMEOUT  If the TimoutInSec expired\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EblGetCharKey (\r
+  IN OUT EFI_INPUT_KEY            *Key,\r
+  IN     UINTN                    TimeoutInSec,\r
+  IN     EBL_GET_CHAR_CALL_BACK   CallBack   OPTIONAL\r
+  )\r
+{\r
+  if (gEblExternalCommand != NULL) {\r
+    return gEblExternalCommand->EblGetCharKey (Key, TimeoutInSec, CallBack);\r
+  }\r
+  return EFI_TIMEOUT;\r
+}\r
+\r
+\r
+/**\r
+  This routine is used prevent command output data from scrolling off the end\r
+  of the screen. The global gPageBreak is used to turn on or off this feature.\r
+  If the CurrentRow is near the end of the screen pause and print out a prompt\r
+  If the use hits Q to quit return TRUE else for any other key return FALSE.\r
+  PrefixNewline is used to figure out if a newline is needed before the prompt\r
+  string. This depends on the last print done before calling this function.\r
+  CurrentRow is updated by one on a call or set back to zero if a prompt is \r
+  needed.\r
+\r
+  @param  CurrentRow  Used to figure out if its the end of the page and updated\r
+  @param  PrefixNewline  Did previous print issue a newline\r
+\r
+  @return TRUE if Q was hit to quit, FALSE in all other cases.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+EblAnyKeyToContinueQtoQuit (\r
+  IN  UINTN   *CurrentRow,\r
+  IN  BOOLEAN PrefixNewline\r
+  )\r
+{\r
+  if (gEblExternalCommand != NULL) {\r
+    return gEblExternalCommand->EblAnyKeyToContinueQtoQuit (CurrentRow, PrefixNewline);\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is\r
+  reinstalled.\r
+\r
+  @param Event      The Event that is being processed\r
+  @param Context    Event Context\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EblAddCommandNotificationEvent (\r
+  IN  EFI_EVENT       Event,\r
+  IN  VOID            *Context\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+\r
+  if (!gInstalledCommand) {\r
+    Status = gBS->LocateProtocol (&gEfiEblAddCommandProtocolGuid, NULL, (VOID **)&gEblExternalCommand);\r
+    if (!EFI_ERROR (Status)) {\r
+      gEblExternalCommand->AddCommands (mAddExternalCmdLibTemplate, mAddExternalCmdLibTemplateSize);\r
+      gInstalledCommand = TRUE;\r
+    }\r
+  }\r
+}\r
+\r
+\r
+\r
+/**\r
+  The user Entry Point for the driver. The user code starts with this function\r
+  as the real entry point for the image goes into a library that calls this \r
+  function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EblAddExternalCommands (\r
+  IN const EBL_COMMAND_TABLE   *EntryArray,\r
+  IN UINTN                     ArrayCount\r
+  )\r
+{\r
+  if (mAddExternalCmdLibTemplate != NULL) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  mAddExternalCmdLibTemplate     = EntryArray;\r
+  mAddExternalCmdLibTemplateSize = ArrayCount;\r
+  \r
+  EfiCreateProtocolNotifyEvent (\r
+    &gEfiEblAddCommandProtocolGuid,\r
+    TPL_CALLBACK,\r
+    EblAddCommandNotificationEvent,\r
+    NULL,\r
+    &mEblCommandRegistration\r
+    );\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r