1 | /** @file
|
---|
2 | Main file for SerMode shell Debug1 function.
|
---|
3 |
|
---|
4 | (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
---|
5 | Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include "UefiShellDebug1CommandsLib.h"
|
---|
11 | #include <Library/ShellLib.h>
|
---|
12 | #include <Protocol/SerialIo.h>
|
---|
13 |
|
---|
14 | /**
|
---|
15 | Display information about a serial device by it's handle.
|
---|
16 |
|
---|
17 | If HandleValid is FALSE, do all devices.
|
---|
18 |
|
---|
19 | @param[in] HandleIdx The handle index for the device.
|
---|
20 | @param[in] HandleValid TRUE if HandleIdx is valid.
|
---|
21 |
|
---|
22 | @retval SHELL_INVALID_PARAMETER A parameter was invalid.
|
---|
23 | @retval SHELL_SUCCESS The operation was successful.
|
---|
24 | **/
|
---|
25 | SHELL_STATUS
|
---|
26 | DisplaySettings (
|
---|
27 | IN UINTN HandleIdx,
|
---|
28 | IN BOOLEAN HandleValid
|
---|
29 | )
|
---|
30 | {
|
---|
31 | EFI_SERIAL_IO_PROTOCOL *SerialIo;
|
---|
32 | UINTN NoHandles;
|
---|
33 | EFI_HANDLE *Handles;
|
---|
34 | EFI_STATUS Status;
|
---|
35 | UINTN Index;
|
---|
36 | CHAR16 *StopBits;
|
---|
37 | CHAR16 Parity;
|
---|
38 | SHELL_STATUS ShellStatus;
|
---|
39 |
|
---|
40 | Handles = NULL;
|
---|
41 | StopBits = NULL;
|
---|
42 |
|
---|
43 | ShellStatus = SHELL_SUCCESS;
|
---|
44 |
|
---|
45 | Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Handles);
|
---|
46 | if (EFI_ERROR (Status)) {
|
---|
47 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode");
|
---|
48 | return SHELL_INVALID_PARAMETER;
|
---|
49 | }
|
---|
50 |
|
---|
51 | for (Index = 0; Index < NoHandles; Index++) {
|
---|
52 | if (HandleValid) {
|
---|
53 | if (ConvertHandleIndexToHandle (HandleIdx) != Handles[Index]) {
|
---|
54 | continue;
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | Status = gBS->HandleProtocol (Handles[Index], &gEfiSerialIoProtocolGuid, (VOID **)&SerialIo);
|
---|
59 | if (!EFI_ERROR (Status)) {
|
---|
60 | switch (SerialIo->Mode->Parity) {
|
---|
61 | case DefaultParity:
|
---|
62 |
|
---|
63 | Parity = 'D';
|
---|
64 | break;
|
---|
65 |
|
---|
66 | case NoParity:
|
---|
67 |
|
---|
68 | Parity = 'N';
|
---|
69 | break;
|
---|
70 |
|
---|
71 | case EvenParity:
|
---|
72 |
|
---|
73 | Parity = 'E';
|
---|
74 | break;
|
---|
75 |
|
---|
76 | case OddParity:
|
---|
77 |
|
---|
78 | Parity = 'O';
|
---|
79 | break;
|
---|
80 |
|
---|
81 | case MarkParity:
|
---|
82 |
|
---|
83 | Parity = 'M';
|
---|
84 | break;
|
---|
85 |
|
---|
86 | case SpaceParity:
|
---|
87 |
|
---|
88 | Parity = 'S';
|
---|
89 | break;
|
---|
90 |
|
---|
91 | default:
|
---|
92 |
|
---|
93 | Parity = 'U';
|
---|
94 | }
|
---|
95 |
|
---|
96 | switch (SerialIo->Mode->StopBits) {
|
---|
97 | case DefaultStopBits:
|
---|
98 |
|
---|
99 | StopBits = L"Default";
|
---|
100 | break;
|
---|
101 |
|
---|
102 | case OneStopBit:
|
---|
103 |
|
---|
104 | StopBits = L"1";
|
---|
105 | break;
|
---|
106 |
|
---|
107 | case TwoStopBits:
|
---|
108 |
|
---|
109 | StopBits = L"2";
|
---|
110 | break;
|
---|
111 |
|
---|
112 | case OneFiveStopBits:
|
---|
113 |
|
---|
114 | StopBits = L"1.5";
|
---|
115 | break;
|
---|
116 |
|
---|
117 | default:
|
---|
118 |
|
---|
119 | StopBits = L"Unknown";
|
---|
120 | }
|
---|
121 |
|
---|
122 | ShellPrintHiiEx (
|
---|
123 | -1,
|
---|
124 | -1,
|
---|
125 | NULL,
|
---|
126 | STRING_TOKEN (STR_SERMODE_DISPLAY),
|
---|
127 | gShellDebug1HiiHandle,
|
---|
128 | ConvertHandleToHandleIndex (Handles[Index]),
|
---|
129 | Handles[Index],
|
---|
130 | SerialIo->Mode->BaudRate,
|
---|
131 | Parity,
|
---|
132 | SerialIo->Mode->DataBits,
|
---|
133 | StopBits
|
---|
134 | );
|
---|
135 | } else {
|
---|
136 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode");
|
---|
137 | ShellStatus = SHELL_NOT_FOUND;
|
---|
138 | break;
|
---|
139 | }
|
---|
140 |
|
---|
141 | if (HandleValid) {
|
---|
142 | break;
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | if (Index == NoHandles) {
|
---|
147 | if (((NoHandles != 0) && HandleValid) || (0 == NoHandles)) {
|
---|
148 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SERMODE_NOT_FOUND), gShellDebug1HiiHandle, L"sermode");
|
---|
149 | ShellStatus = SHELL_NOT_FOUND;
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | return ShellStatus;
|
---|
154 | }
|
---|
155 |
|
---|
156 | /**
|
---|
157 | Function for 'sermode' command.
|
---|
158 |
|
---|
159 | @param[in] ImageHandle Handle to the Image (NULL if Internal).
|
---|
160 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
---|
161 | **/
|
---|
162 | SHELL_STATUS
|
---|
163 | EFIAPI
|
---|
164 | ShellCommandRunSerMode (
|
---|
165 | IN EFI_HANDLE ImageHandle,
|
---|
166 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
167 | )
|
---|
168 | {
|
---|
169 | EFI_STATUS Status;
|
---|
170 | SHELL_STATUS ShellStatus;
|
---|
171 | UINTN Index;
|
---|
172 | UINTN NoHandles;
|
---|
173 | EFI_HANDLE *Handles;
|
---|
174 | EFI_PARITY_TYPE Parity;
|
---|
175 | EFI_STOP_BITS_TYPE StopBits;
|
---|
176 | UINTN HandleIdx;
|
---|
177 | UINTN BaudRate;
|
---|
178 | UINTN DataBits;
|
---|
179 | UINTN Value;
|
---|
180 | EFI_SERIAL_IO_PROTOCOL *SerialIo;
|
---|
181 | LIST_ENTRY *Package;
|
---|
182 | CHAR16 *ProblemParam;
|
---|
183 | CONST CHAR16 *Temp;
|
---|
184 | UINT64 Intermediate;
|
---|
185 |
|
---|
186 | ShellStatus = SHELL_SUCCESS;
|
---|
187 | HandleIdx = 0;
|
---|
188 | Parity = DefaultParity;
|
---|
189 | Handles = NULL;
|
---|
190 | NoHandles = 0;
|
---|
191 | Index = 0;
|
---|
192 | Package = NULL;
|
---|
193 |
|
---|
194 | Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
|
---|
195 | if (EFI_ERROR (Status)) {
|
---|
196 | if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
---|
197 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"sermode", ProblemParam);
|
---|
198 | FreePool (ProblemParam);
|
---|
199 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
200 | } else {
|
---|
201 | ASSERT (FALSE);
|
---|
202 | }
|
---|
203 | } else {
|
---|
204 | if ((ShellCommandLineGetCount (Package) < 6) && (ShellCommandLineGetCount (Package) > 2)) {
|
---|
205 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"sermode");
|
---|
206 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
207 | } else if (ShellCommandLineGetCount (Package) > 6) {
|
---|
208 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"sermode");
|
---|
209 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
210 | } else {
|
---|
211 | Temp = ShellCommandLineGetRawValue (Package, 1);
|
---|
212 | if (Temp != NULL) {
|
---|
213 | Status = ShellConvertStringToUint64 (Temp, &Intermediate, TRUE, FALSE);
|
---|
214 | HandleIdx = (UINTN)Intermediate;
|
---|
215 | Temp = ShellCommandLineGetRawValue (Package, 2);
|
---|
216 | if (Temp == NULL) {
|
---|
217 | ShellStatus = DisplaySettings (HandleIdx, TRUE);
|
---|
218 | goto Done;
|
---|
219 | }
|
---|
220 | } else {
|
---|
221 | ShellStatus = DisplaySettings (0, FALSE);
|
---|
222 | goto Done;
|
---|
223 | }
|
---|
224 |
|
---|
225 | Temp = ShellCommandLineGetRawValue (Package, 2);
|
---|
226 | if (Temp != NULL) {
|
---|
227 | BaudRate = ShellStrToUintn (Temp);
|
---|
228 | } else {
|
---|
229 | ASSERT (FALSE);
|
---|
230 | BaudRate = 0;
|
---|
231 | }
|
---|
232 |
|
---|
233 | Temp = ShellCommandLineGetRawValue (Package, 3);
|
---|
234 | if ((Temp == NULL) || (StrLen (Temp) > 1)) {
|
---|
235 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp);
|
---|
236 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
237 | } else {
|
---|
238 | switch (Temp[0]) {
|
---|
239 | case 'd':
|
---|
240 | case 'D':
|
---|
241 | Parity = DefaultParity;
|
---|
242 | break;
|
---|
243 | case 'n':
|
---|
244 | case 'N':
|
---|
245 | Parity = NoParity;
|
---|
246 | break;
|
---|
247 | case 'e':
|
---|
248 | case 'E':
|
---|
249 | Parity = EvenParity;
|
---|
250 | break;
|
---|
251 | case 'o':
|
---|
252 | case 'O':
|
---|
253 | Parity = OddParity;
|
---|
254 | break;
|
---|
255 | case 'm':
|
---|
256 | case 'M':
|
---|
257 | Parity = MarkParity;
|
---|
258 | break;
|
---|
259 | case 's':
|
---|
260 | case 'S':
|
---|
261 | Parity = SpaceParity;
|
---|
262 | break;
|
---|
263 | default:
|
---|
264 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp);
|
---|
265 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
266 | goto Done;
|
---|
267 | }
|
---|
268 | }
|
---|
269 |
|
---|
270 | Temp = ShellCommandLineGetRawValue (Package, 4);
|
---|
271 | if (Temp != NULL) {
|
---|
272 | DataBits = ShellStrToUintn (Temp);
|
---|
273 | } else {
|
---|
274 | //
|
---|
275 | // make sure this is some number not in the list below.
|
---|
276 | //
|
---|
277 | DataBits = 0;
|
---|
278 | }
|
---|
279 |
|
---|
280 | switch (DataBits) {
|
---|
281 | case 4:
|
---|
282 | case 7:
|
---|
283 | case 8:
|
---|
284 | break;
|
---|
285 | default:
|
---|
286 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp);
|
---|
287 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
288 | goto Done;
|
---|
289 | }
|
---|
290 |
|
---|
291 | Temp = ShellCommandLineGetRawValue (Package, 5);
|
---|
292 | Value = ShellStrToUintn (Temp);
|
---|
293 | switch (Value) {
|
---|
294 | case 0:
|
---|
295 | StopBits = DefaultStopBits;
|
---|
296 | break;
|
---|
297 |
|
---|
298 | case 1:
|
---|
299 | StopBits = OneStopBit;
|
---|
300 | break;
|
---|
301 |
|
---|
302 | case 2:
|
---|
303 | StopBits = TwoStopBits;
|
---|
304 | break;
|
---|
305 |
|
---|
306 | case 15:
|
---|
307 | StopBits = OneFiveStopBits;
|
---|
308 | break;
|
---|
309 |
|
---|
310 | default:
|
---|
311 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp);
|
---|
312 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
313 | goto Done;
|
---|
314 | }
|
---|
315 |
|
---|
316 | Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Handles);
|
---|
317 | if (EFI_ERROR (Status)) {
|
---|
318 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode");
|
---|
319 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
320 | goto Done;
|
---|
321 | }
|
---|
322 |
|
---|
323 | for (Index = 0; Index < NoHandles; Index++) {
|
---|
324 | if (ConvertHandleIndexToHandle (HandleIdx) != Handles[Index]) {
|
---|
325 | continue;
|
---|
326 | }
|
---|
327 |
|
---|
328 | Status = gBS->HandleProtocol (Handles[Index], &gEfiSerialIoProtocolGuid, (VOID **)&SerialIo);
|
---|
329 | if (!EFI_ERROR (Status)) {
|
---|
330 | Status = SerialIo->SetAttributes (
|
---|
331 | SerialIo,
|
---|
332 | (UINT64)BaudRate,
|
---|
333 | SerialIo->Mode->ReceiveFifoDepth,
|
---|
334 | SerialIo->Mode->Timeout,
|
---|
335 | Parity,
|
---|
336 | (UINT8)DataBits,
|
---|
337 | StopBits
|
---|
338 | );
|
---|
339 | if (EFI_ERROR (Status)) {
|
---|
340 | if (Status == EFI_INVALID_PARAMETER) {
|
---|
341 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SERMODE_SET_UNSUPPORTED), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index]));
|
---|
342 | ShellStatus = SHELL_UNSUPPORTED;
|
---|
343 | } else if (Status == EFI_DEVICE_ERROR) {
|
---|
344 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SERMODE_SET_DEV_ERROR), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index]));
|
---|
345 | ShellStatus = SHELL_ACCESS_DENIED;
|
---|
346 | } else {
|
---|
347 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SERMODE_SET_FAIL), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex (Handles[Index]));
|
---|
348 | ShellStatus = SHELL_ACCESS_DENIED;
|
---|
349 | }
|
---|
350 | } else {
|
---|
351 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SERMODE_SET_HANDLE), gShellDebug1HiiHandle, ConvertHandleToHandleIndex (Handles[Index]));
|
---|
352 | }
|
---|
353 |
|
---|
354 | break;
|
---|
355 | }
|
---|
356 | }
|
---|
357 | }
|
---|
358 | }
|
---|
359 |
|
---|
360 | if ((ShellStatus == SHELL_SUCCESS) && (Index == NoHandles)) {
|
---|
361 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SERMODE_BAD_HANDLE), gShellDebug1HiiHandle, L"sermode", HandleIdx);
|
---|
362 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
363 | }
|
---|
364 |
|
---|
365 | Done:
|
---|
366 | if (Package != NULL) {
|
---|
367 | ShellCommandLineFreeVarList (Package);
|
---|
368 | }
|
---|
369 |
|
---|
370 | if (Handles != NULL) {
|
---|
371 | FreePool (Handles);
|
---|
372 | }
|
---|
373 |
|
---|
374 | return ShellStatus;
|
---|
375 | }
|
---|