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