]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Library/EblAddExternalCommandLib/EblAddExternalCommandLib.c
Remove Template stuff and teach people with BeagleBoard
[mirror_edk2.git] / EmbeddedPkg / Library / EblAddExternalCommandLib / EblAddExternalCommandLib.c
CommitLineData
2ef2b01e
A
1/** @file\r
2 Add external EblCmd Lib\r
3\r
4 Copyright (c) 2007, Intel Corporation<BR>\r
5 Portions copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
6\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15\r
16**/\r
17\r
18#include <PiDxe.h>\r
19#include <Library/BaseLib.h>\r
20#include <Library/EblAddExternalCommandLib.h>\r
21#include <Library/UefiBootServicesTableLib.h>\r
22#include <Library/UefiLib.h>\r
23\r
24\r
25STATIC BOOLEAN gInstalledCommand = FALSE;\r
26STATIC EFI_EVENT mEblCommandRegistration = NULL;\r
27\r
28STATIC const EBL_COMMAND_TABLE *mAddExternalCmdLibTemplate = NULL;\r
29STATIC UINTN mAddExternalCmdLibTemplateSize = 0;\r
30EBL_ADD_COMMAND_PROTOCOL *gEblExternalCommand = NULL;\r
31\r
32\r
33/**\r
34 Return a keypress or optionally timeout if a timeout value was passed in.\r
35 An optional callback funciton is called evey second when waiting for a\r
36 timeout.\r
37\r
38 @param Key EFI Key information returned\r
39 @param TimeoutInSec Number of seconds to wait to timeout\r
40 @param CallBack Callback called every second during the timeout wait \r
41\r
42 @return EFI_SUCCESS Key was returned\r
43 @return EFI_TIMEOUT If the TimoutInSec expired\r
44\r
45**/\r
46EFI_STATUS\r
47EFIAPI\r
48EblGetCharKey (\r
49 IN OUT EFI_INPUT_KEY *Key,\r
50 IN UINTN TimeoutInSec,\r
51 IN EBL_GET_CHAR_CALL_BACK CallBack OPTIONAL\r
52 )\r
53{\r
54 if (gEblExternalCommand != NULL) {\r
55 return gEblExternalCommand->EblGetCharKey (Key, TimeoutInSec, CallBack);\r
56 }\r
57 return EFI_TIMEOUT;\r
58}\r
59\r
60\r
61/**\r
62 This routine is used prevent command output data from scrolling off the end\r
63 of the screen. The global gPageBreak is used to turn on or off this feature.\r
64 If the CurrentRow is near the end of the screen pause and print out a prompt\r
65 If the use hits Q to quit return TRUE else for any other key return FALSE.\r
66 PrefixNewline is used to figure out if a newline is needed before the prompt\r
67 string. This depends on the last print done before calling this function.\r
68 CurrentRow is updated by one on a call or set back to zero if a prompt is \r
69 needed.\r
70\r
71 @param CurrentRow Used to figure out if its the end of the page and updated\r
72 @param PrefixNewline Did previous print issue a newline\r
73\r
74 @return TRUE if Q was hit to quit, FALSE in all other cases.\r
75\r
76**/\r
77BOOLEAN\r
78EFIAPI\r
79EblAnyKeyToContinueQtoQuit (\r
80 IN UINTN *CurrentRow,\r
81 IN BOOLEAN PrefixNewline\r
82 )\r
83{\r
84 if (gEblExternalCommand != NULL) {\r
85 return gEblExternalCommand->EblAnyKeyToContinueQtoQuit (CurrentRow, PrefixNewline);\r
86 }\r
87 return FALSE;\r
88}\r
89\r
90\r
91\r
92/**\r
93 Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is\r
94 reinstalled.\r
95\r
96 @param Event The Event that is being processed\r
97 @param Context Event Context\r
98\r
99**/\r
100VOID\r
101EFIAPI\r
102EblAddCommandNotificationEvent (\r
103 IN EFI_EVENT Event,\r
104 IN VOID *Context\r
105 )\r
106{\r
107 EFI_STATUS Status;\r
108\r
109 if (!gInstalledCommand) {\r
110 Status = gBS->LocateProtocol (&gEfiEblAddCommandProtocolGuid, NULL, (VOID **)&gEblExternalCommand);\r
111 if (!EFI_ERROR (Status)) {\r
112 gEblExternalCommand->AddCommands (mAddExternalCmdLibTemplate, mAddExternalCmdLibTemplateSize);\r
113 gInstalledCommand = TRUE;\r
114 }\r
115 }\r
116}\r
117\r
118\r
119\r
120/**\r
121 The user Entry Point for the driver. The user code starts with this function\r
122 as the real entry point for the image goes into a library that calls this \r
123 function.\r
124\r
125 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
126 @param[in] SystemTable A pointer to the EFI System Table.\r
127 \r
128 @retval EFI_SUCCESS The entry point is executed successfully.\r
129 @retval other Some error occurs when executing this entry point.\r
130\r
131**/\r
132EFI_STATUS\r
133EFIAPI\r
134EblAddExternalCommands (\r
135 IN const EBL_COMMAND_TABLE *EntryArray,\r
136 IN UINTN ArrayCount\r
137 )\r
138{\r
139 if (mAddExternalCmdLibTemplate != NULL) {\r
140 return EFI_ALREADY_STARTED;\r
141 }\r
142\r
143 mAddExternalCmdLibTemplate = EntryArray;\r
144 mAddExternalCmdLibTemplateSize = ArrayCount;\r
145 \r
146 EfiCreateProtocolNotifyEvent (\r
147 &gEfiEblAddCommandProtocolGuid,\r
148 TPL_CALLBACK,\r
149 EblAddCommandNotificationEvent,\r
150 NULL,\r
151 &mEblCommandRegistration\r
152 );\r
153 \r
154 return EFI_SUCCESS;\r
155}\r
156\r