1 | /** @file
|
---|
2 | Main file for Dmem shell Debug1 function.
|
---|
3 |
|
---|
4 | Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
5 | (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
---|
6 | (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 |
|
---|
9 | **/
|
---|
10 |
|
---|
11 | #include "UefiShellDebug1CommandsLib.h"
|
---|
12 | #include <Protocol/PciRootBridgeIo.h>
|
---|
13 | #include <Protocol/HiiDatabase.h>
|
---|
14 | #include <Guid/Acpi.h>
|
---|
15 | #include <Guid/Mps.h>
|
---|
16 | #include <Guid/SmBios.h>
|
---|
17 | #include <Guid/MemoryAttributesTable.h>
|
---|
18 | #include <Guid/RtPropertiesTable.h>
|
---|
19 | #include <Guid/SystemResourceTable.h>
|
---|
20 | #include <Guid/DebugImageInfoTable.h>
|
---|
21 | #include <Guid/ImageAuthentication.h>
|
---|
22 |
|
---|
23 | /**
|
---|
24 | Make a printable character.
|
---|
25 |
|
---|
26 | If Char is printable then return it, otherwise return a question mark.
|
---|
27 |
|
---|
28 | @param[in] Char The character to make printable.
|
---|
29 |
|
---|
30 | @return A printable character representing Char.
|
---|
31 | **/
|
---|
32 | CHAR16
|
---|
33 | MakePrintable (
|
---|
34 | IN CONST CHAR16 Char
|
---|
35 | )
|
---|
36 | {
|
---|
37 | if (((Char < 0x20) && (Char > 0)) || (Char > 126)) {
|
---|
38 | return (L'?');
|
---|
39 | }
|
---|
40 |
|
---|
41 | return (Char);
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | Display some Memory-Mapped-IO memory.
|
---|
46 |
|
---|
47 | @param[in] Address The starting address to display.
|
---|
48 | @param[in] Size The length of memory to display.
|
---|
49 | **/
|
---|
50 | SHELL_STATUS
|
---|
51 | DisplayMmioMemory (
|
---|
52 | IN CONST VOID *Address,
|
---|
53 | IN CONST UINTN Size
|
---|
54 | )
|
---|
55 | {
|
---|
56 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRbIo;
|
---|
57 | EFI_STATUS Status;
|
---|
58 | VOID *Buffer;
|
---|
59 | SHELL_STATUS ShellStatus;
|
---|
60 |
|
---|
61 | ShellStatus = SHELL_SUCCESS;
|
---|
62 |
|
---|
63 | Status = gBS->LocateProtocol (&gEfiPciRootBridgeIoProtocolGuid, NULL, (VOID **)&PciRbIo);
|
---|
64 | if (EFI_ERROR (Status)) {
|
---|
65 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle, L"dmem");
|
---|
66 | return (SHELL_NOT_FOUND);
|
---|
67 | }
|
---|
68 |
|
---|
69 | Buffer = AllocateZeroPool (Size);
|
---|
70 | if (Buffer == NULL) {
|
---|
71 | return SHELL_OUT_OF_RESOURCES;
|
---|
72 | }
|
---|
73 |
|
---|
74 | Status = PciRbIo->Mem.Read (PciRbIo, EfiPciWidthUint8, (UINT64)(UINTN)Address, Size, Buffer);
|
---|
75 | if (EFI_ERROR (Status)) {
|
---|
76 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_ER), gShellDebug1HiiHandle, L"dmem");
|
---|
77 | ShellStatus = SHELL_NOT_FOUND;
|
---|
78 | } else {
|
---|
79 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size);
|
---|
80 | DumpHex (2, (UINTN)Address, Size, Buffer);
|
---|
81 | }
|
---|
82 |
|
---|
83 | FreePool (Buffer);
|
---|
84 | return (ShellStatus);
|
---|
85 | }
|
---|
86 |
|
---|
87 | STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
---|
88 | { L"-mmio", TypeFlag },
|
---|
89 | { NULL, TypeMax }
|
---|
90 | };
|
---|
91 |
|
---|
92 | /**
|
---|
93 | Function for 'dmem' command.
|
---|
94 |
|
---|
95 | @param[in] ImageHandle Handle to the Image (NULL if Internal).
|
---|
96 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
---|
97 | **/
|
---|
98 | SHELL_STATUS
|
---|
99 | EFIAPI
|
---|
100 | ShellCommandRunDmem (
|
---|
101 | IN EFI_HANDLE ImageHandle,
|
---|
102 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
103 | )
|
---|
104 | {
|
---|
105 | EFI_STATUS Status;
|
---|
106 | LIST_ENTRY *Package;
|
---|
107 | CHAR16 *ProblemParam;
|
---|
108 | SHELL_STATUS ShellStatus;
|
---|
109 | VOID *Address;
|
---|
110 | UINT64 Size;
|
---|
111 | CONST CHAR16 *Temp1;
|
---|
112 | UINT64 AcpiTableAddress;
|
---|
113 | UINT64 Acpi20TableAddress;
|
---|
114 | UINT64 SalTableAddress;
|
---|
115 | UINT64 SmbiosTableAddress;
|
---|
116 | UINT64 MpsTableAddress;
|
---|
117 | UINT64 DtbTableAddress;
|
---|
118 | UINT64 MemoryAttributesTableAddress;
|
---|
119 | UINT64 RtPropertiesTableAddress;
|
---|
120 | UINT64 SystemResourceTableAddress;
|
---|
121 | UINT64 DebugImageInfoTableAddress;
|
---|
122 | UINT64 ImageExecutionTableAddress;
|
---|
123 | UINT64 JsonConfigDataTableAddress;
|
---|
124 | UINT64 JsonCapsuleDataTableAddress;
|
---|
125 | UINT64 JsonCapsuleResultTableAddress;
|
---|
126 | UINT64 MemoryRangeCapsuleAddress;
|
---|
127 | UINT64 HiiDatabaseExportBufferAddress;
|
---|
128 | UINT64 ConformanceProfileTableAddress;
|
---|
129 | UINTN TableWalker;
|
---|
130 |
|
---|
131 | ShellStatus = SHELL_SUCCESS;
|
---|
132 | Status = EFI_SUCCESS;
|
---|
133 | Address = NULL;
|
---|
134 | Size = 0;
|
---|
135 |
|
---|
136 | //
|
---|
137 | // initialize the shell lib (we must be in non-auto-init...)
|
---|
138 | //
|
---|
139 | Status = ShellInitialize ();
|
---|
140 | ASSERT_EFI_ERROR (Status);
|
---|
141 |
|
---|
142 | Status = CommandInit ();
|
---|
143 | ASSERT_EFI_ERROR (Status);
|
---|
144 |
|
---|
145 | //
|
---|
146 | // parse the command line
|
---|
147 | //
|
---|
148 | Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
---|
149 | if (EFI_ERROR (Status)) {
|
---|
150 | if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
|
---|
151 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dmem", ProblemParam);
|
---|
152 | FreePool (ProblemParam);
|
---|
153 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
154 | } else {
|
---|
155 | ASSERT (FALSE);
|
---|
156 | }
|
---|
157 | } else {
|
---|
158 | if (ShellCommandLineGetCount (Package) > 3) {
|
---|
159 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmem");
|
---|
160 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
161 | } else {
|
---|
162 | Temp1 = ShellCommandLineGetRawValue (Package, 1);
|
---|
163 | if (Temp1 == NULL) {
|
---|
164 | Address = gST;
|
---|
165 | Size = sizeof (*gST);
|
---|
166 | } else {
|
---|
167 | if (!ShellIsHexOrDecimalNumber (Temp1, TRUE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, (UINT64 *)&Address, TRUE, FALSE))) {
|
---|
168 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1);
|
---|
169 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
170 | }
|
---|
171 |
|
---|
172 | Temp1 = ShellCommandLineGetRawValue (Package, 2);
|
---|
173 | if (Temp1 == NULL) {
|
---|
174 | Size = 512;
|
---|
175 | } else {
|
---|
176 | if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE) || EFI_ERROR (ShellConvertStringToUint64 (Temp1, &Size, TRUE, FALSE))) {
|
---|
177 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1);
|
---|
178 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
179 | }
|
---|
180 | }
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | if (ShellStatus == SHELL_SUCCESS) {
|
---|
185 | if (!ShellCommandLineGetFlag (Package, L"-mmio")) {
|
---|
186 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size);
|
---|
187 | DumpHex (2, (UINTN)Address, (UINTN)Size, Address);
|
---|
188 | if (Address == (VOID *)gST) {
|
---|
189 | Acpi20TableAddress = 0;
|
---|
190 | AcpiTableAddress = 0;
|
---|
191 | SalTableAddress = 0;
|
---|
192 | SmbiosTableAddress = 0;
|
---|
193 | MpsTableAddress = 0;
|
---|
194 | DtbTableAddress = 0;
|
---|
195 | MemoryAttributesTableAddress = 0;
|
---|
196 | RtPropertiesTableAddress = 0;
|
---|
197 | SystemResourceTableAddress = 0;
|
---|
198 | DebugImageInfoTableAddress = 0;
|
---|
199 | ImageExecutionTableAddress = 0;
|
---|
200 | JsonConfigDataTableAddress = 0;
|
---|
201 | JsonCapsuleDataTableAddress = 0;
|
---|
202 | JsonCapsuleResultTableAddress = 0;
|
---|
203 | MemoryRangeCapsuleAddress = 0;
|
---|
204 | HiiDatabaseExportBufferAddress = 0;
|
---|
205 | ConformanceProfileTableAddress = 0;
|
---|
206 | for (TableWalker = 0; TableWalker < gST->NumberOfTableEntries; TableWalker++) {
|
---|
207 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiAcpi20TableGuid)) {
|
---|
208 | Acpi20TableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
209 | continue;
|
---|
210 | }
|
---|
211 |
|
---|
212 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiAcpi10TableGuid)) {
|
---|
213 | AcpiTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
214 | continue;
|
---|
215 | }
|
---|
216 |
|
---|
217 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSmbiosTableGuid)) {
|
---|
218 | SmbiosTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
219 | continue;
|
---|
220 | }
|
---|
221 |
|
---|
222 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSmbios3TableGuid)) {
|
---|
223 | SmbiosTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
224 | continue;
|
---|
225 | }
|
---|
226 |
|
---|
227 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiMpsTableGuid)) {
|
---|
228 | MpsTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
229 | continue;
|
---|
230 | }
|
---|
231 |
|
---|
232 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiMemoryAttributesTableGuid)) {
|
---|
233 | MemoryAttributesTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
234 | continue;
|
---|
235 | }
|
---|
236 |
|
---|
237 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiRtPropertiesTableGuid)) {
|
---|
238 | RtPropertiesTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
239 | continue;
|
---|
240 | }
|
---|
241 |
|
---|
242 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSystemResourceTableGuid)) {
|
---|
243 | SystemResourceTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
244 | continue;
|
---|
245 | }
|
---|
246 |
|
---|
247 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiDebugImageInfoTableGuid)) {
|
---|
248 | DebugImageInfoTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
249 | continue;
|
---|
250 | }
|
---|
251 |
|
---|
252 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiImageSecurityDatabaseGuid)) {
|
---|
253 | ImageExecutionTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
254 | continue;
|
---|
255 | }
|
---|
256 |
|
---|
257 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiJsonConfigDataTableGuid)) {
|
---|
258 | JsonConfigDataTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
259 | continue;
|
---|
260 | }
|
---|
261 |
|
---|
262 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiJsonCapsuleDataTableGuid)) {
|
---|
263 | JsonCapsuleDataTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
264 | continue;
|
---|
265 | }
|
---|
266 |
|
---|
267 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiJsonCapsuleResultTableGuid)) {
|
---|
268 | JsonCapsuleResultTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
269 | continue;
|
---|
270 | }
|
---|
271 |
|
---|
272 | if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiHiiDatabaseProtocolGuid)) {
|
---|
273 | HiiDatabaseExportBufferAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable;
|
---|
274 | continue;
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | ShellPrintHiiEx (
|
---|
279 | -1,
|
---|
280 | -1,
|
---|
281 | NULL,
|
---|
282 | STRING_TOKEN (STR_DMEM_SYSTEM_TABLE),
|
---|
283 | gShellDebug1HiiHandle,
|
---|
284 | (UINT64)(UINTN)Address,
|
---|
285 | gST->Hdr.HeaderSize,
|
---|
286 | gST->Hdr.Revision,
|
---|
287 | (UINT64)(UINTN)gST->ConIn,
|
---|
288 | (UINT64)(UINTN)gST->ConOut,
|
---|
289 | (UINT64)(UINTN)gST->StdErr,
|
---|
290 | (UINT64)(UINTN)gST->RuntimeServices,
|
---|
291 | (UINT64)(UINTN)gST->BootServices,
|
---|
292 | SalTableAddress,
|
---|
293 | AcpiTableAddress,
|
---|
294 | Acpi20TableAddress,
|
---|
295 | MpsTableAddress,
|
---|
296 | SmbiosTableAddress,
|
---|
297 | DtbTableAddress,
|
---|
298 | MemoryAttributesTableAddress,
|
---|
299 | RtPropertiesTableAddress,
|
---|
300 | SystemResourceTableAddress,
|
---|
301 | DebugImageInfoTableAddress,
|
---|
302 | ImageExecutionTableAddress,
|
---|
303 | JsonConfigDataTableAddress,
|
---|
304 | JsonCapsuleDataTableAddress,
|
---|
305 | JsonCapsuleResultTableAddress,
|
---|
306 | MemoryRangeCapsuleAddress,
|
---|
307 | HiiDatabaseExportBufferAddress,
|
---|
308 | ConformanceProfileTableAddress
|
---|
309 | );
|
---|
310 | }
|
---|
311 | } else {
|
---|
312 | ShellStatus = DisplayMmioMemory (Address, (UINTN)Size);
|
---|
313 | }
|
---|
314 | }
|
---|
315 |
|
---|
316 | ShellCommandLineFreeVarList (Package);
|
---|
317 | }
|
---|
318 |
|
---|
319 | return (ShellStatus);
|
---|
320 | }
|
---|