1 | /** @file
|
---|
2 | Dump Capsule image information.
|
---|
3 |
|
---|
4 | Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include "CapsuleApp.h"
|
---|
10 |
|
---|
11 | /**
|
---|
12 | Validate if it is valid capsule header
|
---|
13 |
|
---|
14 | This function assumes the caller provided correct CapsuleHeader pointer
|
---|
15 | and CapsuleSize.
|
---|
16 |
|
---|
17 | This function validates the fields in EFI_CAPSULE_HEADER.
|
---|
18 |
|
---|
19 | @param[in] CapsuleHeader Points to a capsule header.
|
---|
20 | @param[in] CapsuleSize Size of the whole capsule image.
|
---|
21 |
|
---|
22 | **/
|
---|
23 | BOOLEAN
|
---|
24 | IsValidCapsuleHeader (
|
---|
25 | IN EFI_CAPSULE_HEADER *CapsuleHeader,
|
---|
26 | IN UINT64 CapsuleSize
|
---|
27 | );
|
---|
28 |
|
---|
29 | /**
|
---|
30 | Dump UX capsule information.
|
---|
31 |
|
---|
32 | @param[in] CapsuleHeader The UX capsule header
|
---|
33 | **/
|
---|
34 | VOID
|
---|
35 | DumpUxCapsule (
|
---|
36 | IN EFI_CAPSULE_HEADER *CapsuleHeader
|
---|
37 | )
|
---|
38 | {
|
---|
39 | EFI_DISPLAY_CAPSULE *DisplayCapsule;
|
---|
40 |
|
---|
41 | DisplayCapsule = (EFI_DISPLAY_CAPSULE *)CapsuleHeader;
|
---|
42 | Print (L"[UxCapsule]\n");
|
---|
43 | Print (L"CapsuleHeader:\n");
|
---|
44 | Print (L" CapsuleGuid - %g\n", &DisplayCapsule->CapsuleHeader.CapsuleGuid);
|
---|
45 | Print (L" HeaderSize - 0x%x\n", DisplayCapsule->CapsuleHeader.HeaderSize);
|
---|
46 | Print (L" Flags - 0x%x\n", DisplayCapsule->CapsuleHeader.Flags);
|
---|
47 | Print (L" CapsuleImageSize - 0x%x\n", DisplayCapsule->CapsuleHeader.CapsuleImageSize);
|
---|
48 | Print (L"ImagePayload:\n");
|
---|
49 | Print (L" Version - 0x%x\n", DisplayCapsule->ImagePayload.Version);
|
---|
50 | Print (L" Checksum - 0x%x\n", DisplayCapsule->ImagePayload.Checksum);
|
---|
51 | Print (L" ImageType - 0x%x\n", DisplayCapsule->ImagePayload.ImageType);
|
---|
52 | Print (L" Mode - 0x%x\n", DisplayCapsule->ImagePayload.Mode);
|
---|
53 | Print (L" OffsetX - 0x%x\n", DisplayCapsule->ImagePayload.OffsetX);
|
---|
54 | Print (L" OffsetY - 0x%x\n", DisplayCapsule->ImagePayload.OffsetY);
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | Dump a non-nested FMP capsule.
|
---|
59 |
|
---|
60 | @param[in] CapsuleHeader A pointer to CapsuleHeader
|
---|
61 | **/
|
---|
62 | VOID
|
---|
63 | DumpFmpCapsule (
|
---|
64 | IN EFI_CAPSULE_HEADER *CapsuleHeader
|
---|
65 | )
|
---|
66 | {
|
---|
67 | EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *FmpCapsuleHeader;
|
---|
68 | UINT64 *ItemOffsetList;
|
---|
69 | UINTN Index;
|
---|
70 | UINTN Count;
|
---|
71 | EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *FmpImageHeader;
|
---|
72 |
|
---|
73 | Print (L"[FmpCapsule]\n");
|
---|
74 | Print (L"CapsuleHeader:\n");
|
---|
75 | Print (L" CapsuleGuid - %g\n", &CapsuleHeader->CapsuleGuid);
|
---|
76 | Print (L" HeaderSize - 0x%x\n", CapsuleHeader->HeaderSize);
|
---|
77 | Print (L" Flags - 0x%x\n", CapsuleHeader->Flags);
|
---|
78 | Print (L" CapsuleImageSize - 0x%x\n", CapsuleHeader->CapsuleImageSize);
|
---|
79 |
|
---|
80 | FmpCapsuleHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *)((UINT8 *)CapsuleHeader + CapsuleHeader->HeaderSize);
|
---|
81 | ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1);
|
---|
82 | Print (L"FmpHeader:\n");
|
---|
83 | Print (L" Version - 0x%x\n", FmpCapsuleHeader->Version);
|
---|
84 | Print (L" EmbeddedDriverCount - 0x%x\n", FmpCapsuleHeader->EmbeddedDriverCount);
|
---|
85 | Print (L" PayloadItemCount - 0x%x\n", FmpCapsuleHeader->PayloadItemCount);
|
---|
86 | Count = FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount;
|
---|
87 | for (Index = 0; Index < Count; Index++) {
|
---|
88 | Print (L" Offset[%d] - 0x%x\n", Index, ItemOffsetList[Index]);
|
---|
89 | }
|
---|
90 |
|
---|
91 | for (Index = FmpCapsuleHeader->EmbeddedDriverCount; Index < Count; Index++) {
|
---|
92 | Print (L"FmpPayload[%d] ImageHeader:\n", Index);
|
---|
93 | FmpImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[Index]);
|
---|
94 | Print (L" Version - 0x%x\n", FmpImageHeader->Version);
|
---|
95 | Print (L" UpdateImageTypeId - %g\n", &FmpImageHeader->UpdateImageTypeId);
|
---|
96 | Print (L" UpdateImageIndex - 0x%x\n", FmpImageHeader->UpdateImageIndex);
|
---|
97 | Print (L" UpdateImageSize - 0x%x\n", FmpImageHeader->UpdateImageSize);
|
---|
98 | Print (L" UpdateVendorCodeSize - 0x%x\n", FmpImageHeader->UpdateVendorCodeSize);
|
---|
99 | if (FmpImageHeader->Version >= 2) {
|
---|
100 | Print (L" UpdateHardwareInstance - 0x%lx\n", FmpImageHeader->UpdateHardwareInstance);
|
---|
101 | if (FmpImageHeader->Version >= EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) {
|
---|
102 | Print (L" ImageCapsuleSupport - 0x%lx\n", FmpImageHeader->ImageCapsuleSupport);
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | Return if there is a FMP header below capsule header.
|
---|
110 |
|
---|
111 | @param[in] CapsuleHeader A pointer to EFI_CAPSULE_HEADER
|
---|
112 |
|
---|
113 | @retval TRUE There is a FMP header below capsule header.
|
---|
114 | @retval FALSE There is not a FMP header below capsule header
|
---|
115 | **/
|
---|
116 | BOOLEAN
|
---|
117 | IsNestedFmpCapsule (
|
---|
118 | IN EFI_CAPSULE_HEADER *CapsuleHeader
|
---|
119 | )
|
---|
120 | {
|
---|
121 | EFI_STATUS Status;
|
---|
122 | EFI_SYSTEM_RESOURCE_TABLE *Esrt;
|
---|
123 | EFI_SYSTEM_RESOURCE_ENTRY *EsrtEntry;
|
---|
124 | UINTN Index;
|
---|
125 | BOOLEAN EsrtGuidFound;
|
---|
126 | EFI_CAPSULE_HEADER *NestedCapsuleHeader;
|
---|
127 | UINTN NestedCapsuleSize;
|
---|
128 |
|
---|
129 | //
|
---|
130 | // Check ESRT
|
---|
131 | //
|
---|
132 | EsrtGuidFound = FALSE;
|
---|
133 | Status = EfiGetSystemConfigurationTable (&gEfiSystemResourceTableGuid, (VOID **)&Esrt);
|
---|
134 | if (!EFI_ERROR (Status)) {
|
---|
135 | ASSERT (Esrt != NULL);
|
---|
136 | EsrtEntry = (VOID *)(Esrt + 1);
|
---|
137 | for (Index = 0; Index < Esrt->FwResourceCount; Index++, EsrtEntry++) {
|
---|
138 | if (CompareGuid (&EsrtEntry->FwClass, &CapsuleHeader->CapsuleGuid)) {
|
---|
139 | EsrtGuidFound = TRUE;
|
---|
140 | break;
|
---|
141 | }
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | if (!EsrtGuidFound) {
|
---|
146 | return FALSE;
|
---|
147 | }
|
---|
148 |
|
---|
149 | //
|
---|
150 | // Check nested capsule header
|
---|
151 | // FMP GUID after ESRT one
|
---|
152 | //
|
---|
153 | NestedCapsuleHeader = (EFI_CAPSULE_HEADER *)((UINT8 *)CapsuleHeader + CapsuleHeader->HeaderSize);
|
---|
154 | NestedCapsuleSize = (UINTN)CapsuleHeader + CapsuleHeader->CapsuleImageSize- (UINTN)NestedCapsuleHeader;
|
---|
155 | if (NestedCapsuleSize < sizeof (EFI_CAPSULE_HEADER)) {
|
---|
156 | return FALSE;
|
---|
157 | }
|
---|
158 |
|
---|
159 | if (!CompareGuid (&NestedCapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
|
---|
160 | return FALSE;
|
---|
161 | }
|
---|
162 |
|
---|
163 | return TRUE;
|
---|
164 | }
|
---|
165 |
|
---|
166 | /**
|
---|
167 | Dump capsule information
|
---|
168 |
|
---|
169 | @param[in] CapsuleName The name of the capsule image.
|
---|
170 |
|
---|
171 | @retval EFI_SUCCESS The capsule information is dumped.
|
---|
172 | @retval EFI_UNSUPPORTED Input parameter is not valid.
|
---|
173 | **/
|
---|
174 | EFI_STATUS
|
---|
175 | DumpCapsule (
|
---|
176 | IN CHAR16 *CapsuleName
|
---|
177 | )
|
---|
178 | {
|
---|
179 | VOID *Buffer;
|
---|
180 | UINTN FileSize;
|
---|
181 | EFI_CAPSULE_HEADER *CapsuleHeader;
|
---|
182 | EFI_STATUS Status;
|
---|
183 |
|
---|
184 | Buffer = NULL;
|
---|
185 | Status = ReadFileToBuffer (CapsuleName, &FileSize, &Buffer);
|
---|
186 | if (EFI_ERROR (Status)) {
|
---|
187 | Print (L"CapsuleApp: Capsule (%s) is not found.\n", CapsuleName);
|
---|
188 | goto Done;
|
---|
189 | }
|
---|
190 |
|
---|
191 | if (!IsValidCapsuleHeader (Buffer, FileSize)) {
|
---|
192 | Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);
|
---|
193 | Status = EFI_INVALID_PARAMETER;
|
---|
194 | goto Done;
|
---|
195 | }
|
---|
196 |
|
---|
197 | CapsuleHeader = Buffer;
|
---|
198 | if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid)) {
|
---|
199 | DumpUxCapsule (CapsuleHeader);
|
---|
200 | Status = EFI_SUCCESS;
|
---|
201 | goto Done;
|
---|
202 | }
|
---|
203 |
|
---|
204 | if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
|
---|
205 | DumpFmpCapsule (CapsuleHeader);
|
---|
206 | }
|
---|
207 |
|
---|
208 | if (IsNestedFmpCapsule (CapsuleHeader)) {
|
---|
209 | Print (L"[NestedCapsule]\n");
|
---|
210 | Print (L"CapsuleHeader:\n");
|
---|
211 | Print (L" CapsuleGuid - %g\n", &CapsuleHeader->CapsuleGuid);
|
---|
212 | Print (L" HeaderSize - 0x%x\n", CapsuleHeader->HeaderSize);
|
---|
213 | Print (L" Flags - 0x%x\n", CapsuleHeader->Flags);
|
---|
214 | Print (L" CapsuleImageSize - 0x%x\n", CapsuleHeader->CapsuleImageSize);
|
---|
215 | DumpFmpCapsule ((EFI_CAPSULE_HEADER *)((UINTN)CapsuleHeader + CapsuleHeader->HeaderSize));
|
---|
216 | }
|
---|
217 |
|
---|
218 | Done:
|
---|
219 | if (Buffer != NULL) {
|
---|
220 | FreePool (Buffer);
|
---|
221 | }
|
---|
222 |
|
---|
223 | return Status;
|
---|
224 | }
|
---|
225 |
|
---|
226 | /**
|
---|
227 | Dump capsule status variable.
|
---|
228 |
|
---|
229 | @retval EFI_SUCCESS The capsule status variable is dumped.
|
---|
230 | @retval EFI_UNSUPPORTED Input parameter is not valid.
|
---|
231 | **/
|
---|
232 | EFI_STATUS
|
---|
233 | DumpCapsuleStatusVariable (
|
---|
234 | VOID
|
---|
235 | )
|
---|
236 | {
|
---|
237 | EFI_STATUS Status;
|
---|
238 | UINT32 Index;
|
---|
239 | CHAR16 CapsuleVarName[20];
|
---|
240 | CHAR16 *TempVarName;
|
---|
241 | EFI_CAPSULE_RESULT_VARIABLE_HEADER *CapsuleResult;
|
---|
242 | EFI_CAPSULE_RESULT_VARIABLE_FMP *CapsuleResultFmp;
|
---|
243 | UINTN CapsuleFileNameSize;
|
---|
244 | CHAR16 CapsuleIndexData[12];
|
---|
245 | CHAR16 *CapsuleIndex;
|
---|
246 | CHAR16 *CapsuleFileName;
|
---|
247 | CHAR16 *CapsuleTarget;
|
---|
248 |
|
---|
249 | Status = GetVariable2 (
|
---|
250 | L"CapsuleMax",
|
---|
251 | &gEfiCapsuleReportGuid,
|
---|
252 | (VOID **)&CapsuleIndex,
|
---|
253 | NULL
|
---|
254 | );
|
---|
255 | if (!EFI_ERROR (Status)) {
|
---|
256 | ASSERT (CapsuleIndex != NULL);
|
---|
257 | CopyMem (CapsuleIndexData, CapsuleIndex, 11 * sizeof (CHAR16));
|
---|
258 | CapsuleIndexData[11] = 0;
|
---|
259 | Print (L"CapsuleMax - %s\n", CapsuleIndexData);
|
---|
260 | FreePool (CapsuleIndex);
|
---|
261 | }
|
---|
262 |
|
---|
263 | Status = GetVariable2 (
|
---|
264 | L"CapsuleLast",
|
---|
265 | &gEfiCapsuleReportGuid,
|
---|
266 | (VOID **)&CapsuleIndex,
|
---|
267 | NULL
|
---|
268 | );
|
---|
269 | if (!EFI_ERROR (Status)) {
|
---|
270 | ASSERT (CapsuleIndex != NULL);
|
---|
271 | CopyMem (CapsuleIndexData, CapsuleIndex, 11 * sizeof (CHAR16));
|
---|
272 | CapsuleIndexData[11] = 0;
|
---|
273 | Print (L"CapsuleLast - %s\n", CapsuleIndexData);
|
---|
274 | FreePool (CapsuleIndex);
|
---|
275 | }
|
---|
276 |
|
---|
277 | StrCpyS (CapsuleVarName, sizeof (CapsuleVarName)/sizeof (CapsuleVarName[0]), L"Capsule");
|
---|
278 | TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
|
---|
279 | Index = 0;
|
---|
280 |
|
---|
281 | while (TRUE) {
|
---|
282 | UnicodeSPrint (TempVarName, 5 * sizeof (CHAR16), L"%04x", Index);
|
---|
283 |
|
---|
284 | Status = GetVariable2 (
|
---|
285 | CapsuleVarName,
|
---|
286 | &gEfiCapsuleReportGuid,
|
---|
287 | (VOID **)&CapsuleResult,
|
---|
288 | NULL
|
---|
289 | );
|
---|
290 | if (Status == EFI_NOT_FOUND) {
|
---|
291 | break;
|
---|
292 | } else if (EFI_ERROR (Status)) {
|
---|
293 | continue;
|
---|
294 | }
|
---|
295 |
|
---|
296 | ASSERT (CapsuleResult != NULL);
|
---|
297 |
|
---|
298 | //
|
---|
299 | // display capsule process status
|
---|
300 | //
|
---|
301 | if (CapsuleResult->VariableTotalSize >= sizeof (EFI_CAPSULE_RESULT_VARIABLE_HEADER)) {
|
---|
302 | Print (L"CapsuleName: %s\n", CapsuleVarName);
|
---|
303 | Print (L" Capsule Guid: %g\n", &CapsuleResult->CapsuleGuid);
|
---|
304 | Print (L" Capsule ProcessedTime: %t\n", &CapsuleResult->CapsuleProcessed);
|
---|
305 | Print (L" Capsule Status: %r\n", CapsuleResult->CapsuleStatus);
|
---|
306 | }
|
---|
307 |
|
---|
308 | if (CompareGuid (&CapsuleResult->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
|
---|
309 | if (CapsuleResult->VariableTotalSize >= sizeof (EFI_CAPSULE_RESULT_VARIABLE_HEADER) + sizeof (EFI_CAPSULE_RESULT_VARIABLE_FMP) + sizeof (CHAR16) * 2) {
|
---|
310 | CapsuleResultFmp = (EFI_CAPSULE_RESULT_VARIABLE_FMP *)(CapsuleResult + 1);
|
---|
311 | Print (L" Capsule FMP Version: 0x%x\n", CapsuleResultFmp->Version);
|
---|
312 | Print (L" Capsule FMP PayloadIndex: 0x%x\n", CapsuleResultFmp->PayloadIndex);
|
---|
313 | Print (L" Capsule FMP UpdateImageIndex: 0x%x\n", CapsuleResultFmp->UpdateImageIndex);
|
---|
314 | Print (L" Capsule FMP UpdateImageTypeId: %g\n", &CapsuleResultFmp->UpdateImageTypeId);
|
---|
315 | CapsuleFileName = (CHAR16 *)(CapsuleResultFmp + 1);
|
---|
316 | Print (L" Capsule FMP CapsuleFileName: \"%s\"\n", CapsuleFileName);
|
---|
317 | CapsuleFileNameSize = StrSize (CapsuleFileName);
|
---|
318 | CapsuleTarget = (CHAR16 *)((UINTN)CapsuleFileName + CapsuleFileNameSize);
|
---|
319 | Print (L" Capsule FMP CapsuleTarget: \"%s\"\n", CapsuleTarget);
|
---|
320 | }
|
---|
321 | }
|
---|
322 |
|
---|
323 | FreePool (CapsuleResult);
|
---|
324 |
|
---|
325 | Index++;
|
---|
326 | if (Index > 0xFFFF) {
|
---|
327 | break;
|
---|
328 | }
|
---|
329 | }
|
---|
330 |
|
---|
331 | return EFI_SUCCESS;
|
---|
332 | }
|
---|
333 |
|
---|
334 | CHAR8 *mFwTypeString[] = {
|
---|
335 | "Unknown",
|
---|
336 | "SystemFirmware",
|
---|
337 | "DeviceFirmware",
|
---|
338 | "UefiDriver",
|
---|
339 | };
|
---|
340 |
|
---|
341 | CHAR8 *mLastAttemptStatusString[] = {
|
---|
342 | "Success",
|
---|
343 | "Error: Unsuccessful",
|
---|
344 | "Error: Insufficient Resources",
|
---|
345 | "Error: Incorrect Version",
|
---|
346 | "Error: Invalid Format",
|
---|
347 | "Error: Auth Error",
|
---|
348 | "Error: Power Event AC",
|
---|
349 | "Error: Power Event Battery",
|
---|
350 | "Error: Unsatisfied Dependencies",
|
---|
351 | };
|
---|
352 |
|
---|
353 | /**
|
---|
354 | Convert FwType to a string.
|
---|
355 |
|
---|
356 | @param[in] FwType FwType in ESRT
|
---|
357 |
|
---|
358 | @return a string for FwType.
|
---|
359 | **/
|
---|
360 | CHAR8 *
|
---|
361 | FwTypeToString (
|
---|
362 | IN UINT32 FwType
|
---|
363 | )
|
---|
364 | {
|
---|
365 | if (FwType < sizeof (mFwTypeString) / sizeof (mFwTypeString[0])) {
|
---|
366 | return mFwTypeString[FwType];
|
---|
367 | } else {
|
---|
368 | return "Invalid";
|
---|
369 | }
|
---|
370 | }
|
---|
371 |
|
---|
372 | /**
|
---|
373 | Convert LastAttemptStatus to a string.
|
---|
374 |
|
---|
375 | @param[in] LastAttemptStatus LastAttemptStatus in FMP or ESRT
|
---|
376 |
|
---|
377 | @return a string for LastAttemptStatus.
|
---|
378 | **/
|
---|
379 | CHAR8 *
|
---|
380 | LastAttemptStatusToString (
|
---|
381 | IN UINT32 LastAttemptStatus
|
---|
382 | )
|
---|
383 | {
|
---|
384 | if (LastAttemptStatus < sizeof (mLastAttemptStatusString) / sizeof (mLastAttemptStatusString[0])) {
|
---|
385 | return mLastAttemptStatusString[LastAttemptStatus];
|
---|
386 | } else {
|
---|
387 | return "Error: Unknown";
|
---|
388 | }
|
---|
389 | }
|
---|
390 |
|
---|
391 | /**
|
---|
392 | Dump ESRT entry.
|
---|
393 |
|
---|
394 | @param[in] EsrtEntry ESRT entry
|
---|
395 | **/
|
---|
396 | VOID
|
---|
397 | DumpEsrtEntry (
|
---|
398 | IN EFI_SYSTEM_RESOURCE_ENTRY *EsrtEntry
|
---|
399 | )
|
---|
400 | {
|
---|
401 | Print (L" FwClass - %g\n", &EsrtEntry->FwClass);
|
---|
402 | Print (L" FwType - 0x%x (%a)\n", EsrtEntry->FwType, FwTypeToString (EsrtEntry->FwType));
|
---|
403 | Print (L" FwVersion - 0x%x\n", EsrtEntry->FwVersion);
|
---|
404 | Print (L" LowestSupportedFwVersion - 0x%x\n", EsrtEntry->LowestSupportedFwVersion);
|
---|
405 | Print (L" CapsuleFlags - 0x%x\n", EsrtEntry->CapsuleFlags);
|
---|
406 | Print (L" LastAttemptVersion - 0x%x\n", EsrtEntry->LastAttemptVersion);
|
---|
407 | Print (L" LastAttemptStatus - 0x%x (%a)\n", EsrtEntry->LastAttemptStatus, LastAttemptStatusToString (EsrtEntry->LastAttemptStatus));
|
---|
408 | }
|
---|
409 |
|
---|
410 | /**
|
---|
411 | Dump ESRT table.
|
---|
412 |
|
---|
413 | @param[in] Esrt ESRT table
|
---|
414 | **/
|
---|
415 | VOID
|
---|
416 | DumpEsrt (
|
---|
417 | IN EFI_SYSTEM_RESOURCE_TABLE *Esrt
|
---|
418 | )
|
---|
419 | {
|
---|
420 | UINTN Index;
|
---|
421 | EFI_SYSTEM_RESOURCE_ENTRY *EsrtEntry;
|
---|
422 |
|
---|
423 | if (Esrt == NULL) {
|
---|
424 | return;
|
---|
425 | }
|
---|
426 |
|
---|
427 | Print (L"EFI_SYSTEM_RESOURCE_TABLE:\n");
|
---|
428 | Print (L"FwResourceCount - 0x%x\n", Esrt->FwResourceCount);
|
---|
429 | Print (L"FwResourceCountMax - 0x%x\n", Esrt->FwResourceCountMax);
|
---|
430 | Print (L"FwResourceVersion - 0x%lx\n", Esrt->FwResourceVersion);
|
---|
431 |
|
---|
432 | EsrtEntry = (VOID *)(Esrt + 1);
|
---|
433 | for (Index = 0; Index < Esrt->FwResourceCount; Index++) {
|
---|
434 | Print (L"EFI_SYSTEM_RESOURCE_ENTRY (%d):\n", Index);
|
---|
435 | DumpEsrtEntry (EsrtEntry);
|
---|
436 | EsrtEntry++;
|
---|
437 | }
|
---|
438 | }
|
---|
439 |
|
---|
440 | /**
|
---|
441 | Dump ESRT info.
|
---|
442 | **/
|
---|
443 | VOID
|
---|
444 | DumpEsrtData (
|
---|
445 | VOID
|
---|
446 | )
|
---|
447 | {
|
---|
448 | EFI_STATUS Status;
|
---|
449 | EFI_SYSTEM_RESOURCE_TABLE *Esrt;
|
---|
450 |
|
---|
451 | Print (L"##############\n");
|
---|
452 | Print (L"# ESRT TABLE #\n");
|
---|
453 | Print (L"##############\n");
|
---|
454 |
|
---|
455 | Status = EfiGetSystemConfigurationTable (&gEfiSystemResourceTableGuid, (VOID **)&Esrt);
|
---|
456 | if (EFI_ERROR (Status)) {
|
---|
457 | Print (L"ESRT - %r\n", Status);
|
---|
458 | return;
|
---|
459 | }
|
---|
460 |
|
---|
461 | DumpEsrt (Esrt);
|
---|
462 | Print (L"\n");
|
---|
463 | }
|
---|
464 |
|
---|
465 | /**
|
---|
466 | Dump capsule information from CapsuleHeader
|
---|
467 |
|
---|
468 | @param[in] CapsuleHeader The CapsuleHeader of the capsule image.
|
---|
469 |
|
---|
470 | @retval EFI_SUCCESS The capsule information is dumped.
|
---|
471 |
|
---|
472 | **/
|
---|
473 | EFI_STATUS
|
---|
474 | DumpCapsuleFromBuffer (
|
---|
475 | IN EFI_CAPSULE_HEADER *CapsuleHeader
|
---|
476 | )
|
---|
477 | {
|
---|
478 | if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid)) {
|
---|
479 | DumpUxCapsule (CapsuleHeader);
|
---|
480 | return EFI_SUCCESS;
|
---|
481 | }
|
---|
482 |
|
---|
483 | if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
|
---|
484 | DumpFmpCapsule (CapsuleHeader);
|
---|
485 | }
|
---|
486 |
|
---|
487 | if (IsNestedFmpCapsule (CapsuleHeader)) {
|
---|
488 | Print (L"[NestedCapusule]\n");
|
---|
489 | Print (L"CapsuleHeader:\n");
|
---|
490 | Print (L" CapsuleGuid - %g\n", &CapsuleHeader->CapsuleGuid);
|
---|
491 | Print (L" HeaderSize - 0x%x\n", CapsuleHeader->HeaderSize);
|
---|
492 | Print (L" Flags - 0x%x\n", CapsuleHeader->Flags);
|
---|
493 | Print (L" CapsuleImageSize - 0x%x\n", CapsuleHeader->CapsuleImageSize);
|
---|
494 | DumpFmpCapsule ((EFI_CAPSULE_HEADER *)((UINTN)CapsuleHeader + CapsuleHeader->HeaderSize));
|
---|
495 | }
|
---|
496 |
|
---|
497 | return EFI_SUCCESS;
|
---|
498 | }
|
---|
499 |
|
---|
500 | /**
|
---|
501 | This routine is called to upper case given unicode string.
|
---|
502 |
|
---|
503 | @param[in] Str String to upper case
|
---|
504 |
|
---|
505 | @retval upper cased string after process
|
---|
506 |
|
---|
507 | **/
|
---|
508 | STATIC
|
---|
509 | CHAR16 *
|
---|
510 | UpperCaseString (
|
---|
511 | IN CHAR16 *Str
|
---|
512 | )
|
---|
513 | {
|
---|
514 | CHAR16 *Cptr;
|
---|
515 |
|
---|
516 | for (Cptr = Str; *Cptr != L'\0'; Cptr++) {
|
---|
517 | if ((L'a' <= *Cptr) && (*Cptr <= L'z')) {
|
---|
518 | *Cptr = *Cptr - L'a' + L'A';
|
---|
519 | }
|
---|
520 | }
|
---|
521 |
|
---|
522 | return Str;
|
---|
523 | }
|
---|
524 |
|
---|
525 | /**
|
---|
526 | This routine is used to return substring before period '.' or '\0'
|
---|
527 | Caller should respsonsible of substr space allocation & free
|
---|
528 |
|
---|
529 | @param[in] Str String to check
|
---|
530 | @param[out] SubStr First part of string before period or '\0'
|
---|
531 | @param[out] SubStrLen Length of first part of string
|
---|
532 |
|
---|
533 | **/
|
---|
534 | STATIC
|
---|
535 | VOID
|
---|
536 | GetSubStringBeforePeriod (
|
---|
537 | IN CHAR16 *Str,
|
---|
538 | OUT CHAR16 *SubStr,
|
---|
539 | OUT UINTN *SubStrLen
|
---|
540 | )
|
---|
541 | {
|
---|
542 | UINTN Index;
|
---|
543 |
|
---|
544 | for (Index = 0; Str[Index] != L'.' && Str[Index] != L'\0'; Index++) {
|
---|
545 | SubStr[Index] = Str[Index];
|
---|
546 | }
|
---|
547 |
|
---|
548 | SubStr[Index] = L'\0';
|
---|
549 | *SubStrLen = Index;
|
---|
550 | }
|
---|
551 |
|
---|
552 | /**
|
---|
553 | This routine pad the string in tail with input character.
|
---|
554 |
|
---|
555 | @param[in] StrBuf Str buffer to be padded, should be enough room for
|
---|
556 | @param[in] PadLen Expected padding length
|
---|
557 | @param[in] Character Character used to pad
|
---|
558 |
|
---|
559 | **/
|
---|
560 | STATIC
|
---|
561 | VOID
|
---|
562 | PadStrInTail (
|
---|
563 | IN CHAR16 *StrBuf,
|
---|
564 | IN UINTN PadLen,
|
---|
565 | IN CHAR16 Character
|
---|
566 | )
|
---|
567 | {
|
---|
568 | UINTN Index;
|
---|
569 |
|
---|
570 | for (Index = 0; StrBuf[Index] != L'\0'; Index++) {
|
---|
571 | }
|
---|
572 |
|
---|
573 | while (PadLen != 0) {
|
---|
574 | StrBuf[Index] = Character;
|
---|
575 | Index++;
|
---|
576 | PadLen--;
|
---|
577 | }
|
---|
578 |
|
---|
579 | StrBuf[Index] = L'\0';
|
---|
580 | }
|
---|
581 |
|
---|
582 | /**
|
---|
583 | This routine find the offset of the last period '.' of string. if No period exists
|
---|
584 | function FileNameExtension is set to L'\0'
|
---|
585 |
|
---|
586 | @param[in] FileName File name to split between last period
|
---|
587 | @param[out] FileNameFirst First FileName before last period
|
---|
588 | @param[out] FileNameExtension FileName after last period
|
---|
589 |
|
---|
590 | **/
|
---|
591 | STATIC
|
---|
592 | VOID
|
---|
593 | SplitFileNameExtension (
|
---|
594 | IN CHAR16 *FileName,
|
---|
595 | OUT CHAR16 *FileNameFirst,
|
---|
596 | OUT CHAR16 *FileNameExtension
|
---|
597 | )
|
---|
598 | {
|
---|
599 | UINTN Index;
|
---|
600 | UINTN StringLen;
|
---|
601 |
|
---|
602 | StringLen = StrLen (FileName);
|
---|
603 | for (Index = StringLen; Index > 0 && FileName[Index] != L'.'; Index--) {
|
---|
604 | }
|
---|
605 |
|
---|
606 | //
|
---|
607 | // No period exists. No FileName Extension
|
---|
608 | //
|
---|
609 | if ((Index == 0) && (FileName[Index] != L'.')) {
|
---|
610 | FileNameExtension[0] = L'\0';
|
---|
611 | Index = StringLen;
|
---|
612 | } else {
|
---|
613 | StrCpyS (FileNameExtension, MAX_FILE_NAME_LEN, &FileName[Index+1]);
|
---|
614 | }
|
---|
615 |
|
---|
616 | //
|
---|
617 | // Copy First file name
|
---|
618 | //
|
---|
619 | StrnCpyS (FileNameFirst, MAX_FILE_NAME_LEN, FileName, Index);
|
---|
620 | FileNameFirst[Index] = L'\0';
|
---|
621 | }
|
---|
622 |
|
---|
623 | /**
|
---|
624 | The function is called by PerformQuickSort to sort file name in alphabet.
|
---|
625 |
|
---|
626 | @param[in] Left The pointer to first buffer.
|
---|
627 | @param[in] Right The pointer to second buffer.
|
---|
628 |
|
---|
629 | @retval 0 Buffer1 equal to Buffer2.
|
---|
630 | @return <0 Buffer1 is less than Buffer2.
|
---|
631 | @return >0 Buffer1 is greater than Buffer2.
|
---|
632 |
|
---|
633 | **/
|
---|
634 | INTN
|
---|
635 | EFIAPI
|
---|
636 | CompareFileNameInAlphabet (
|
---|
637 | IN VOID *Left,
|
---|
638 | IN VOID *Right
|
---|
639 | )
|
---|
640 | {
|
---|
641 | EFI_FILE_INFO *FileInfo1;
|
---|
642 | EFI_FILE_INFO *FileInfo2;
|
---|
643 | CHAR16 FileName1[MAX_FILE_NAME_SIZE];
|
---|
644 | CHAR16 FileExtension1[MAX_FILE_NAME_SIZE];
|
---|
645 | CHAR16 FileName2[MAX_FILE_NAME_SIZE];
|
---|
646 | CHAR16 FileExtension2[MAX_FILE_NAME_SIZE];
|
---|
647 | CHAR16 TempSubStr1[MAX_FILE_NAME_SIZE];
|
---|
648 | CHAR16 TempSubStr2[MAX_FILE_NAME_SIZE];
|
---|
649 | UINTN SubStrLen1;
|
---|
650 | UINTN SubStrLen2;
|
---|
651 | INTN SubStrCmpResult;
|
---|
652 |
|
---|
653 | FileInfo1 = (EFI_FILE_INFO *)(*(UINTN *)Left);
|
---|
654 | FileInfo2 = (EFI_FILE_INFO *)(*(UINTN *)Right);
|
---|
655 |
|
---|
656 | SplitFileNameExtension (FileInfo1->FileName, FileName1, FileExtension1);
|
---|
657 | SplitFileNameExtension (FileInfo2->FileName, FileName2, FileExtension2);
|
---|
658 |
|
---|
659 | UpperCaseString (FileName1);
|
---|
660 | UpperCaseString (FileName2);
|
---|
661 |
|
---|
662 | GetSubStringBeforePeriod (FileName1, TempSubStr1, &SubStrLen1);
|
---|
663 | GetSubStringBeforePeriod (FileName2, TempSubStr2, &SubStrLen2);
|
---|
664 |
|
---|
665 | if (SubStrLen1 > SubStrLen2) {
|
---|
666 | //
|
---|
667 | // Substr in NewFileName is longer. Pad tail with SPACE
|
---|
668 | //
|
---|
669 | PadStrInTail (TempSubStr2, SubStrLen1 - SubStrLen2, L' ');
|
---|
670 | } else if (SubStrLen1 < SubStrLen2) {
|
---|
671 | //
|
---|
672 | // Substr in ListedFileName is longer. Pad tail with SPACE
|
---|
673 | //
|
---|
674 | PadStrInTail (TempSubStr1, SubStrLen2 - SubStrLen1, L' ');
|
---|
675 | }
|
---|
676 |
|
---|
677 | SubStrCmpResult = StrnCmp (TempSubStr1, TempSubStr2, MAX_FILE_NAME_LEN);
|
---|
678 | if (SubStrCmpResult != 0) {
|
---|
679 | return SubStrCmpResult;
|
---|
680 | }
|
---|
681 |
|
---|
682 | UpperCaseString (FileExtension1);
|
---|
683 | UpperCaseString (FileExtension2);
|
---|
684 |
|
---|
685 | return StrnCmp (FileExtension1, FileExtension2, MAX_FILE_NAME_LEN);
|
---|
686 | }
|
---|
687 |
|
---|
688 | /**
|
---|
689 | Dump capsule information from disk.
|
---|
690 |
|
---|
691 | @param[in] Fs The device path of disk.
|
---|
692 | @param[in] DumpCapsuleInfo The flag to indicate whether to dump the capsule inforomation.
|
---|
693 |
|
---|
694 | @retval EFI_SUCCESS The capsule information is dumped.
|
---|
695 |
|
---|
696 | **/
|
---|
697 | EFI_STATUS
|
---|
698 | DumpCapsuleFromDisk (
|
---|
699 | IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs,
|
---|
700 | IN BOOLEAN DumpCapsuleInfo
|
---|
701 | )
|
---|
702 | {
|
---|
703 | EFI_STATUS Status;
|
---|
704 | EFI_FILE *Root;
|
---|
705 | EFI_FILE *DirHandle;
|
---|
706 | EFI_FILE *FileHandle;
|
---|
707 | UINTN Index;
|
---|
708 | UINTN FileSize;
|
---|
709 | VOID *FileBuffer;
|
---|
710 | EFI_FILE_INFO **FileInfoBuffer;
|
---|
711 | EFI_FILE_INFO *FileInfo;
|
---|
712 | UINTN FileCount;
|
---|
713 | BOOLEAN NoFile;
|
---|
714 |
|
---|
715 | DirHandle = NULL;
|
---|
716 | FileHandle = NULL;
|
---|
717 | Index = 0;
|
---|
718 | FileInfoBuffer = NULL;
|
---|
719 | FileInfo = NULL;
|
---|
720 | FileCount = 0;
|
---|
721 | NoFile = FALSE;
|
---|
722 |
|
---|
723 | Status = Fs->OpenVolume (Fs, &Root);
|
---|
724 | if (EFI_ERROR (Status)) {
|
---|
725 | Print (L"Cannot open volume. Status = %r\n", Status);
|
---|
726 | goto Done;
|
---|
727 | }
|
---|
728 |
|
---|
729 | Status = Root->Open (Root, &DirHandle, EFI_CAPSULE_FILE_DIRECTORY, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
|
---|
730 | if (EFI_ERROR (Status)) {
|
---|
731 | Print (L"Cannot open %s. Status = %r\n", EFI_CAPSULE_FILE_DIRECTORY, Status);
|
---|
732 | goto Done;
|
---|
733 | }
|
---|
734 |
|
---|
735 | //
|
---|
736 | // Get file count first
|
---|
737 | //
|
---|
738 | Status = FileHandleFindFirstFile (DirHandle, &FileInfo);
|
---|
739 | do {
|
---|
740 | if (EFI_ERROR (Status) || (FileInfo == NULL)) {
|
---|
741 | Print (L"Get File Info Fail. Status = %r\n", Status);
|
---|
742 | goto Done;
|
---|
743 | }
|
---|
744 |
|
---|
745 | if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
|
---|
746 | FileCount++;
|
---|
747 | }
|
---|
748 |
|
---|
749 | Status = FileHandleFindNextFile (DirHandle, FileInfo, &NoFile);
|
---|
750 | if (EFI_ERROR (Status)) {
|
---|
751 | Print (L"Get Next File Fail. Status = %r\n", Status);
|
---|
752 | goto Done;
|
---|
753 | }
|
---|
754 | } while (!NoFile);
|
---|
755 |
|
---|
756 | if (FileCount == 0) {
|
---|
757 | Print (L"Error: No capsule file found!\n");
|
---|
758 | Status = EFI_NOT_FOUND;
|
---|
759 | goto Done;
|
---|
760 | }
|
---|
761 |
|
---|
762 | FileInfoBuffer = AllocateZeroPool (sizeof (FileInfo) * FileCount);
|
---|
763 | if (FileInfoBuffer == NULL) {
|
---|
764 | Status = EFI_OUT_OF_RESOURCES;
|
---|
765 | goto Done;
|
---|
766 | }
|
---|
767 |
|
---|
768 | NoFile = FALSE;
|
---|
769 |
|
---|
770 | //
|
---|
771 | // Get all file info
|
---|
772 | //
|
---|
773 | Status = FileHandleFindFirstFile (DirHandle, &FileInfo);
|
---|
774 | do {
|
---|
775 | if (EFI_ERROR (Status) || (FileInfo == NULL)) {
|
---|
776 | Print (L"Get File Info Fail. Status = %r\n", Status);
|
---|
777 | goto Done;
|
---|
778 | }
|
---|
779 |
|
---|
780 | if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
|
---|
781 | FileInfoBuffer[Index++] = AllocateCopyPool ((UINTN)FileInfo->Size, FileInfo);
|
---|
782 | }
|
---|
783 |
|
---|
784 | Status = FileHandleFindNextFile (DirHandle, FileInfo, &NoFile);
|
---|
785 | if (EFI_ERROR (Status)) {
|
---|
786 | Print (L"Get Next File Fail. Status = %r\n", Status);
|
---|
787 | goto Done;
|
---|
788 | }
|
---|
789 | } while (!NoFile);
|
---|
790 |
|
---|
791 | //
|
---|
792 | // Sort FileInfoBuffer by alphabet order
|
---|
793 | //
|
---|
794 | PerformQuickSort (
|
---|
795 | FileInfoBuffer,
|
---|
796 | FileCount,
|
---|
797 | sizeof (FileInfo),
|
---|
798 | (SORT_COMPARE)CompareFileNameInAlphabet
|
---|
799 | );
|
---|
800 |
|
---|
801 | Print (L"The capsules will be performed by following order:\n");
|
---|
802 |
|
---|
803 | for (Index = 0; Index < FileCount; Index++) {
|
---|
804 | Print (L" %d.%s\n", Index + 1, FileInfoBuffer[Index]->FileName);
|
---|
805 | }
|
---|
806 |
|
---|
807 | if (!DumpCapsuleInfo) {
|
---|
808 | Status = EFI_SUCCESS;
|
---|
809 | goto Done;
|
---|
810 | }
|
---|
811 |
|
---|
812 | Print (L"The infomation of the capsules:\n");
|
---|
813 |
|
---|
814 | for (Index = 0; Index < FileCount; Index++) {
|
---|
815 | FileHandle = NULL;
|
---|
816 | Status = DirHandle->Open (DirHandle, &FileHandle, FileInfoBuffer[Index]->FileName, EFI_FILE_MODE_READ, 0);
|
---|
817 | if (EFI_ERROR (Status)) {
|
---|
818 | goto Done;
|
---|
819 | }
|
---|
820 |
|
---|
821 | Status = FileHandleGetSize (FileHandle, (UINT64 *)&FileSize);
|
---|
822 | if (EFI_ERROR (Status)) {
|
---|
823 | Print (L"Cannot read file %s. Status = %r\n", FileInfoBuffer[Index]->FileName, Status);
|
---|
824 | FileHandleClose (FileHandle);
|
---|
825 | goto Done;
|
---|
826 | }
|
---|
827 |
|
---|
828 | FileBuffer = AllocatePool (FileSize);
|
---|
829 | if (FileBuffer == NULL) {
|
---|
830 | Status = EFI_OUT_OF_RESOURCES;
|
---|
831 | goto Done;
|
---|
832 | }
|
---|
833 |
|
---|
834 | Status = FileHandleRead (FileHandle, &FileSize, FileBuffer);
|
---|
835 | if (EFI_ERROR (Status)) {
|
---|
836 | Print (L"Cannot read file %s. Status = %r\n", FileInfoBuffer[Index]->FileName, Status);
|
---|
837 | FileHandleClose (FileHandle);
|
---|
838 | FreePool (FileBuffer);
|
---|
839 | goto Done;
|
---|
840 | }
|
---|
841 |
|
---|
842 | Print (L"**************************\n");
|
---|
843 | Print (L" %d.%s:\n", Index + 1, FileInfoBuffer[Index]->FileName);
|
---|
844 | Print (L"**************************\n");
|
---|
845 | DumpCapsuleFromBuffer ((EFI_CAPSULE_HEADER *)FileBuffer);
|
---|
846 | FileHandleClose (FileHandle);
|
---|
847 | FreePool (FileBuffer);
|
---|
848 | }
|
---|
849 |
|
---|
850 | Done:
|
---|
851 | if (FileInfoBuffer != NULL) {
|
---|
852 | for (Index = 0; Index < FileCount; Index++) {
|
---|
853 | if (FileInfoBuffer[Index] != NULL) {
|
---|
854 | FreePool (FileInfoBuffer[Index]);
|
---|
855 | }
|
---|
856 | }
|
---|
857 |
|
---|
858 | FreePool (FileInfoBuffer);
|
---|
859 | }
|
---|
860 |
|
---|
861 | return Status;
|
---|
862 | }
|
---|
863 |
|
---|
864 | /**
|
---|
865 | Dump capsule inforomation form Gather list.
|
---|
866 |
|
---|
867 | @param[in] BlockDescriptors The block descriptors for the capsule images
|
---|
868 | @param[in] DumpCapsuleInfo The flag to indicate whether to dump the capsule inforomation.
|
---|
869 |
|
---|
870 | **/
|
---|
871 | VOID
|
---|
872 | DumpBlockDescriptors (
|
---|
873 | IN EFI_CAPSULE_BLOCK_DESCRIPTOR *BlockDescriptors,
|
---|
874 | IN BOOLEAN DumpCapsuleInfo
|
---|
875 | )
|
---|
876 | {
|
---|
877 | EFI_CAPSULE_BLOCK_DESCRIPTOR *TempBlockPtr;
|
---|
878 |
|
---|
879 | TempBlockPtr = BlockDescriptors;
|
---|
880 |
|
---|
881 | while (TRUE) {
|
---|
882 | if (TempBlockPtr->Length != 0) {
|
---|
883 | if (DumpCapsuleInfo) {
|
---|
884 | Print (L"******************************************************\n");
|
---|
885 | }
|
---|
886 |
|
---|
887 | Print (L"Capsule data starts at 0x%08x with size 0x%08x\n", TempBlockPtr->Union.DataBlock, TempBlockPtr->Length);
|
---|
888 | if (DumpCapsuleInfo) {
|
---|
889 | Print (L"******************************************************\n");
|
---|
890 | DumpCapsuleFromBuffer ((EFI_CAPSULE_HEADER *)(UINTN)TempBlockPtr->Union.DataBlock);
|
---|
891 | }
|
---|
892 |
|
---|
893 | TempBlockPtr += 1;
|
---|
894 | } else {
|
---|
895 | if (TempBlockPtr->Union.ContinuationPointer == (UINTN)NULL) {
|
---|
896 | break;
|
---|
897 | } else {
|
---|
898 | TempBlockPtr = (EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)TempBlockPtr->Union.ContinuationPointer;
|
---|
899 | }
|
---|
900 | }
|
---|
901 | }
|
---|
902 | }
|
---|
903 |
|
---|
904 | /**
|
---|
905 | Dump Provisioned Capsule.
|
---|
906 |
|
---|
907 | @param[in] DumpCapsuleInfo The flag to indicate whether to dump the capsule inforomation.
|
---|
908 |
|
---|
909 | **/
|
---|
910 | VOID
|
---|
911 | DumpProvisionedCapsule (
|
---|
912 | IN BOOLEAN DumpCapsuleInfo
|
---|
913 | )
|
---|
914 | {
|
---|
915 | EFI_STATUS Status;
|
---|
916 | CHAR16 CapsuleVarName[30];
|
---|
917 | CHAR16 *TempVarName;
|
---|
918 | UINTN Index;
|
---|
919 | EFI_PHYSICAL_ADDRESS *CapsuleDataPtr64;
|
---|
920 | UINT16 *BootNext;
|
---|
921 | CHAR16 BootOptionName[20];
|
---|
922 | EFI_BOOT_MANAGER_LOAD_OPTION BootNextOptionEntry;
|
---|
923 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
---|
924 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
|
---|
925 | EFI_SHELL_PROTOCOL *ShellProtocol;
|
---|
926 |
|
---|
927 | Index = 0;
|
---|
928 | CapsuleDataPtr64 = NULL;
|
---|
929 | BootNext = NULL;
|
---|
930 |
|
---|
931 | ShellProtocol = GetShellProtocol ();
|
---|
932 | if (ShellProtocol == NULL) {
|
---|
933 | Print (L"Get Shell Protocol Fail\n");
|
---|
934 | return;
|
---|
935 | }
|
---|
936 |
|
---|
937 | //
|
---|
938 | // Dump capsule provisioned on Memory
|
---|
939 | //
|
---|
940 | Print (L"#########################\n");
|
---|
941 | Print (L"### Capsule on Memory ###\n");
|
---|
942 | Print (L"#########################\n");
|
---|
943 | StrCpyS (CapsuleVarName, sizeof (CapsuleVarName)/sizeof (CHAR16), EFI_CAPSULE_VARIABLE_NAME);
|
---|
944 | TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
|
---|
945 | while (TRUE) {
|
---|
946 | if (Index > 0) {
|
---|
947 | UnicodeValueToStringS (
|
---|
948 | TempVarName,
|
---|
949 | sizeof (CapsuleVarName) - ((UINTN)TempVarName - (UINTN)CapsuleVarName),
|
---|
950 | 0,
|
---|
951 | Index,
|
---|
952 | 0
|
---|
953 | );
|
---|
954 | }
|
---|
955 |
|
---|
956 | Status = GetVariable2 (
|
---|
957 | CapsuleVarName,
|
---|
958 | &gEfiCapsuleVendorGuid,
|
---|
959 | (VOID **)&CapsuleDataPtr64,
|
---|
960 | NULL
|
---|
961 | );
|
---|
962 | if (EFI_ERROR (Status) || (CapsuleDataPtr64 == NULL)) {
|
---|
963 | if (Index == 0) {
|
---|
964 | Print (L"No data.\n");
|
---|
965 | }
|
---|
966 |
|
---|
967 | break;
|
---|
968 | }
|
---|
969 |
|
---|
970 | Index++;
|
---|
971 | Print (L"Capsule Description at 0x%08x\n", *CapsuleDataPtr64);
|
---|
972 | DumpBlockDescriptors ((EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)*CapsuleDataPtr64, DumpCapsuleInfo);
|
---|
973 | }
|
---|
974 |
|
---|
975 | //
|
---|
976 | // Dump capsule provisioned on Disk
|
---|
977 | //
|
---|
978 | Print (L"#########################\n");
|
---|
979 | Print (L"### Capsule on Disk #####\n");
|
---|
980 | Print (L"#########################\n");
|
---|
981 | Status = GetVariable2 (
|
---|
982 | L"BootNext",
|
---|
983 | &gEfiGlobalVariableGuid,
|
---|
984 | (VOID **)&BootNext,
|
---|
985 | NULL
|
---|
986 | );
|
---|
987 | if (EFI_ERROR (Status) || (BootNext == NULL)) {
|
---|
988 | Print (L"Get BootNext Variable Fail. Status = %r\n", Status);
|
---|
989 | } else {
|
---|
990 | UnicodeSPrint (BootOptionName, sizeof (BootOptionName), L"Boot%04x", *BootNext);
|
---|
991 | Status = EfiBootManagerVariableToLoadOption (BootOptionName, &BootNextOptionEntry);
|
---|
992 | if (!EFI_ERROR (Status)) {
|
---|
993 | //
|
---|
994 | // Display description and device path
|
---|
995 | //
|
---|
996 | GetEfiSysPartitionFromBootOptionFilePath (BootNextOptionEntry.FilePath, &DevicePath, &Fs);
|
---|
997 | if (!EFI_ERROR (Status)) {
|
---|
998 | Print (L"Capsules are provisioned on BootOption: %s\n", BootNextOptionEntry.Description);
|
---|
999 | Print (L" %s %s\n", ShellProtocol->GetMapFromDevicePath (&DevicePath), ConvertDevicePathToText (DevicePath, TRUE, TRUE));
|
---|
1000 | DumpCapsuleFromDisk (Fs, DumpCapsuleInfo);
|
---|
1001 | }
|
---|
1002 | }
|
---|
1003 | }
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | /**
|
---|
1007 | Dump FMP information.
|
---|
1008 |
|
---|
1009 | @param[in] ImageInfoSize The size of ImageInfo, in bytes.
|
---|
1010 | @param[in] ImageInfo A pointer to EFI_FIRMWARE_IMAGE_DESCRIPTOR.
|
---|
1011 | @param[in] DescriptorVersion The version of EFI_FIRMWARE_IMAGE_DESCRIPTOR.
|
---|
1012 | @param[in] DescriptorCount The count of EFI_FIRMWARE_IMAGE_DESCRIPTOR.
|
---|
1013 | @param[in] DescriptorSize The size of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR, in bytes.
|
---|
1014 | @param[in] PackageVersion The version of package.
|
---|
1015 | @param[in] PackageVersionName The version name of package.
|
---|
1016 | **/
|
---|
1017 | VOID
|
---|
1018 | DumpFmpImageInfo (
|
---|
1019 | IN UINTN ImageInfoSize,
|
---|
1020 | IN EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,
|
---|
1021 | IN UINT32 DescriptorVersion,
|
---|
1022 | IN UINT8 DescriptorCount,
|
---|
1023 | IN UINTN DescriptorSize,
|
---|
1024 | IN UINT32 PackageVersion,
|
---|
1025 | IN CHAR16 *PackageVersionName
|
---|
1026 | )
|
---|
1027 | {
|
---|
1028 | EFI_FIRMWARE_IMAGE_DESCRIPTOR *CurrentImageInfo;
|
---|
1029 | UINTN Index;
|
---|
1030 | UINTN Index2;
|
---|
1031 |
|
---|
1032 | Print (L" DescriptorVersion - 0x%x\n", DescriptorVersion);
|
---|
1033 | Print (L" DescriptorCount - 0x%x\n", DescriptorCount);
|
---|
1034 | Print (L" DescriptorSize - 0x%x\n", DescriptorSize);
|
---|
1035 | Print (L" PackageVersion - 0x%x\n", PackageVersion);
|
---|
1036 | Print (L" PackageVersionName - \"%s\"\n", PackageVersionName);
|
---|
1037 | CurrentImageInfo = ImageInfo;
|
---|
1038 | for (Index = 0; Index < DescriptorCount; Index++) {
|
---|
1039 | Print (L" ImageDescriptor (%d)\n", Index);
|
---|
1040 | Print (L" ImageIndex - 0x%x\n", CurrentImageInfo->ImageIndex);
|
---|
1041 | Print (L" ImageTypeId - %g\n", &CurrentImageInfo->ImageTypeId);
|
---|
1042 | Print (L" ImageId - 0x%lx\n", CurrentImageInfo->ImageId);
|
---|
1043 | Print (L" ImageIdName - \"%s\"\n", CurrentImageInfo->ImageIdName);
|
---|
1044 | Print (L" Version - 0x%x\n", CurrentImageInfo->Version);
|
---|
1045 | Print (L" VersionName - \"%s\"\n", CurrentImageInfo->VersionName);
|
---|
1046 | Print (L" Size - 0x%x\n", CurrentImageInfo->Size);
|
---|
1047 | Print (L" AttributesSupported - 0x%lx\n", CurrentImageInfo->AttributesSupported);
|
---|
1048 | Print (L" IMAGE_UPDATABLE - 0x%lx\n", CurrentImageInfo->AttributesSupported & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE);
|
---|
1049 | Print (L" RESET_REQUIRED - 0x%lx\n", CurrentImageInfo->AttributesSupported & IMAGE_ATTRIBUTE_RESET_REQUIRED);
|
---|
1050 | Print (L" AUTHENTICATION_REQUIRED - 0x%lx\n", CurrentImageInfo->AttributesSupported & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED);
|
---|
1051 | Print (L" IN_USE - 0x%lx\n", CurrentImageInfo->AttributesSupported & IMAGE_ATTRIBUTE_IN_USE);
|
---|
1052 | Print (L" UEFI_IMAGE - 0x%lx\n", CurrentImageInfo->AttributesSupported & IMAGE_ATTRIBUTE_UEFI_IMAGE);
|
---|
1053 | Print (L" AttributesSetting - 0x%lx\n", CurrentImageInfo->AttributesSetting);
|
---|
1054 | Print (L" IMAGE_UPDATABLE - 0x%lx\n", CurrentImageInfo->AttributesSetting & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE);
|
---|
1055 | Print (L" RESET_REQUIRED - 0x%lx\n", CurrentImageInfo->AttributesSetting & IMAGE_ATTRIBUTE_RESET_REQUIRED);
|
---|
1056 | Print (L" AUTHENTICATION_REQUIRED - 0x%lx\n", CurrentImageInfo->AttributesSetting & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED);
|
---|
1057 | Print (L" IN_USE - 0x%lx\n", CurrentImageInfo->AttributesSetting & IMAGE_ATTRIBUTE_IN_USE);
|
---|
1058 | Print (L" UEFI_IMAGE - 0x%lx\n", CurrentImageInfo->AttributesSetting & IMAGE_ATTRIBUTE_UEFI_IMAGE);
|
---|
1059 | Print (L" Compatibilities - 0x%lx\n", CurrentImageInfo->Compatibilities);
|
---|
1060 | Print (L" COMPATIB_CHECK_SUPPORTED - 0x%lx\n", CurrentImageInfo->Compatibilities & IMAGE_COMPATIBILITY_CHECK_SUPPORTED);
|
---|
1061 | if (DescriptorVersion > 1) {
|
---|
1062 | Print (L" LowestSupportedImageVersion - 0x%x\n", CurrentImageInfo->LowestSupportedImageVersion);
|
---|
1063 | if (DescriptorVersion > 2) {
|
---|
1064 | Print (L" LastAttemptVersion - 0x%x\n", CurrentImageInfo->LastAttemptVersion);
|
---|
1065 | Print (L" LastAttemptStatus - 0x%x (%a)\n", CurrentImageInfo->LastAttemptStatus, LastAttemptStatusToString (CurrentImageInfo->LastAttemptStatus));
|
---|
1066 | Print (L" HardwareInstance - 0x%lx\n", CurrentImageInfo->HardwareInstance);
|
---|
1067 | if (DescriptorVersion > 3) {
|
---|
1068 | Print (L" Dependencies - ");
|
---|
1069 | if (CurrentImageInfo->Dependencies == NULL) {
|
---|
1070 | Print (L"NULL\n");
|
---|
1071 | } else {
|
---|
1072 | Index2 = 0;
|
---|
1073 | do {
|
---|
1074 | Print (L"%02x ", CurrentImageInfo->Dependencies->Dependencies[Index2]);
|
---|
1075 | } while (CurrentImageInfo->Dependencies->Dependencies[Index2++] != EFI_FMP_DEP_END);
|
---|
1076 |
|
---|
1077 | Print (L"\n");
|
---|
1078 | }
|
---|
1079 | }
|
---|
1080 | }
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | //
|
---|
1084 | // Use DescriptorSize to move ImageInfo Pointer to stay compatible with different ImageInfo version
|
---|
1085 | //
|
---|
1086 | CurrentImageInfo = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)((UINT8 *)CurrentImageInfo + DescriptorSize);
|
---|
1087 | }
|
---|
1088 | }
|
---|
1089 |
|
---|
1090 | /**
|
---|
1091 | Dump FMP package information.
|
---|
1092 |
|
---|
1093 | @param[in] PackageVersion The version of package.
|
---|
1094 | @param[in] PackageVersionName The version name of package.
|
---|
1095 | @param[in] PackageVersionNameMaxLen The maximum length of PackageVersionName.
|
---|
1096 | @param[in] AttributesSupported Package attributes that are supported by this device.
|
---|
1097 | @param[in] AttributesSetting Package attributes.
|
---|
1098 | **/
|
---|
1099 | VOID
|
---|
1100 | DumpFmpPackageInfo (
|
---|
1101 | IN UINT32 PackageVersion,
|
---|
1102 | IN CHAR16 *PackageVersionName,
|
---|
1103 | IN UINT32 PackageVersionNameMaxLen,
|
---|
1104 | IN UINT64 AttributesSupported,
|
---|
1105 | IN UINT64 AttributesSetting
|
---|
1106 | )
|
---|
1107 | {
|
---|
1108 | Print (L" PackageVersion - 0x%x\n", PackageVersion);
|
---|
1109 | Print (L" PackageVersionName - \"%s\"\n", PackageVersionName);
|
---|
1110 | Print (L" PackageVersionNameMaxLen - 0x%x\n", PackageVersionNameMaxLen);
|
---|
1111 | Print (L" AttributesSupported - 0x%lx\n", AttributesSupported);
|
---|
1112 | Print (L" IMAGE_UPDATABLE - 0x%lx\n", AttributesSupported & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE);
|
---|
1113 | Print (L" RESET_REQUIRED - 0x%lx\n", AttributesSupported & IMAGE_ATTRIBUTE_RESET_REQUIRED);
|
---|
1114 | Print (L" AUTHENTICATION_REQUIRED - 0x%lx\n", AttributesSupported & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED);
|
---|
1115 | Print (L" AttributesSetting - 0x%lx\n", AttributesSetting);
|
---|
1116 | Print (L" IMAGE_UPDATABLE - 0x%lx\n", AttributesSetting & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE);
|
---|
1117 | Print (L" RESET_REQUIRED - 0x%lx\n", AttributesSetting & IMAGE_ATTRIBUTE_RESET_REQUIRED);
|
---|
1118 | Print (L" AUTHENTICATION_REQUIRED - 0x%lx\n", AttributesSetting & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED);
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | /**
|
---|
1122 | Dump FMP protocol info.
|
---|
1123 | **/
|
---|
1124 | VOID
|
---|
1125 | DumpFmpData (
|
---|
1126 | VOID
|
---|
1127 | )
|
---|
1128 | {
|
---|
1129 | EFI_STATUS Status;
|
---|
1130 | EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp;
|
---|
1131 | EFI_HANDLE *HandleBuffer;
|
---|
1132 | UINTN NumberOfHandles;
|
---|
1133 | UINTN Index;
|
---|
1134 | EFI_FIRMWARE_IMAGE_DESCRIPTOR *FmpImageInfoBuf;
|
---|
1135 | UINTN ImageInfoSize;
|
---|
1136 | UINT32 FmpImageInfoDescriptorVer;
|
---|
1137 | UINT8 FmpImageInfoCount;
|
---|
1138 | UINTN DescriptorSize;
|
---|
1139 | UINT32 PackageVersion;
|
---|
1140 | CHAR16 *PackageVersionName;
|
---|
1141 | UINT32 PackageVersionNameMaxLen;
|
---|
1142 | UINT64 AttributesSupported;
|
---|
1143 | UINT64 AttributesSetting;
|
---|
1144 |
|
---|
1145 | Print (L"############\n");
|
---|
1146 | Print (L"# FMP DATA #\n");
|
---|
1147 | Print (L"############\n");
|
---|
1148 | Status = gBS->LocateHandleBuffer (
|
---|
1149 | ByProtocol,
|
---|
1150 | &gEfiFirmwareManagementProtocolGuid,
|
---|
1151 | NULL,
|
---|
1152 | &NumberOfHandles,
|
---|
1153 | &HandleBuffer
|
---|
1154 | );
|
---|
1155 | if (EFI_ERROR (Status)) {
|
---|
1156 | Print (L"FMP protocol - %r\n", EFI_NOT_FOUND);
|
---|
1157 | return;
|
---|
1158 | }
|
---|
1159 |
|
---|
1160 | for (Index = 0; Index < NumberOfHandles; Index++) {
|
---|
1161 | Status = gBS->HandleProtocol (
|
---|
1162 | HandleBuffer[Index],
|
---|
1163 | &gEfiFirmwareManagementProtocolGuid,
|
---|
1164 | (VOID **)&Fmp
|
---|
1165 | );
|
---|
1166 | if (EFI_ERROR (Status)) {
|
---|
1167 | continue;
|
---|
1168 | }
|
---|
1169 |
|
---|
1170 | ImageInfoSize = 0;
|
---|
1171 | Status = Fmp->GetImageInfo (
|
---|
1172 | Fmp,
|
---|
1173 | &ImageInfoSize,
|
---|
1174 | NULL,
|
---|
1175 | NULL,
|
---|
1176 | NULL,
|
---|
1177 | NULL,
|
---|
1178 | NULL,
|
---|
1179 | NULL
|
---|
1180 | );
|
---|
1181 | if (Status != EFI_BUFFER_TOO_SMALL) {
|
---|
1182 | continue;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | FmpImageInfoBuf = NULL;
|
---|
1186 | FmpImageInfoBuf = AllocateZeroPool (ImageInfoSize);
|
---|
1187 | if (FmpImageInfoBuf == NULL) {
|
---|
1188 | Status = EFI_OUT_OF_RESOURCES;
|
---|
1189 | goto EXIT;
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | PackageVersionName = NULL;
|
---|
1193 | Status = Fmp->GetImageInfo (
|
---|
1194 | Fmp,
|
---|
1195 | &ImageInfoSize, // ImageInfoSize
|
---|
1196 | FmpImageInfoBuf, // ImageInfo
|
---|
1197 | &FmpImageInfoDescriptorVer, // DescriptorVersion
|
---|
1198 | &FmpImageInfoCount, // DescriptorCount
|
---|
1199 | &DescriptorSize, // DescriptorSize
|
---|
1200 | &PackageVersion, // PackageVersion
|
---|
1201 | &PackageVersionName // PackageVersionName
|
---|
1202 | );
|
---|
1203 |
|
---|
1204 | //
|
---|
1205 | // If FMP GetInformation interface failed, skip this resource
|
---|
1206 | //
|
---|
1207 | if (EFI_ERROR (Status)) {
|
---|
1208 | Print (L"FMP (%d) ImageInfo - %r\n", Index, Status);
|
---|
1209 | FreePool (FmpImageInfoBuf);
|
---|
1210 | continue;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | Print (L"FMP (%d) ImageInfo:\n", Index);
|
---|
1214 | DumpFmpImageInfo (
|
---|
1215 | ImageInfoSize, // ImageInfoSize
|
---|
1216 | FmpImageInfoBuf, // ImageInfo
|
---|
1217 | FmpImageInfoDescriptorVer, // DescriptorVersion
|
---|
1218 | FmpImageInfoCount, // DescriptorCount
|
---|
1219 | DescriptorSize, // DescriptorSize
|
---|
1220 | PackageVersion, // PackageVersion
|
---|
1221 | PackageVersionName // PackageVersionName
|
---|
1222 | );
|
---|
1223 |
|
---|
1224 | if (PackageVersionName != NULL) {
|
---|
1225 | FreePool (PackageVersionName);
|
---|
1226 | }
|
---|
1227 |
|
---|
1228 | FreePool (FmpImageInfoBuf);
|
---|
1229 |
|
---|
1230 | //
|
---|
1231 | // Get package info
|
---|
1232 | //
|
---|
1233 | PackageVersionName = NULL;
|
---|
1234 | Status = Fmp->GetPackageInfo (
|
---|
1235 | Fmp,
|
---|
1236 | &PackageVersion, // PackageVersion
|
---|
1237 | &PackageVersionName, // PackageVersionName
|
---|
1238 | &PackageVersionNameMaxLen, // PackageVersionNameMaxLen
|
---|
1239 | &AttributesSupported, // AttributesSupported
|
---|
1240 | &AttributesSetting // AttributesSetting
|
---|
1241 | );
|
---|
1242 | if (EFI_ERROR (Status)) {
|
---|
1243 | Print (L"FMP (%d) PackageInfo - %r\n", Index, Status);
|
---|
1244 | } else {
|
---|
1245 | Print (L"FMP (%d) ImageInfo:\n", Index);
|
---|
1246 | DumpFmpPackageInfo (
|
---|
1247 | PackageVersion, // PackageVersion
|
---|
1248 | PackageVersionName, // PackageVersionName
|
---|
1249 | PackageVersionNameMaxLen, // PackageVersionNameMaxLen
|
---|
1250 | AttributesSupported, // AttributesSupported
|
---|
1251 | AttributesSetting // AttributesSetting
|
---|
1252 | );
|
---|
1253 |
|
---|
1254 | if (PackageVersionName != NULL) {
|
---|
1255 | FreePool (PackageVersionName);
|
---|
1256 | }
|
---|
1257 | }
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | Print (L"\n");
|
---|
1261 |
|
---|
1262 | EXIT:
|
---|
1263 | FreePool (HandleBuffer);
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | /**
|
---|
1267 | Check if the ImageInfo includes the ImageTypeId.
|
---|
1268 |
|
---|
1269 | @param[in] ImageInfo A pointer to EFI_FIRMWARE_IMAGE_DESCRIPTOR.
|
---|
1270 | @param[in] DescriptorCount The count of EFI_FIRMWARE_IMAGE_DESCRIPTOR.
|
---|
1271 | @param[in] DescriptorSize The size of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR, in bytes.
|
---|
1272 | @param[in] ImageTypeId A unique GUID identifying the firmware image type.
|
---|
1273 |
|
---|
1274 | @return TRUE This ImageInfo includes the ImageTypeId
|
---|
1275 | @return FALSE This ImageInfo does not include the ImageTypeId
|
---|
1276 | **/
|
---|
1277 | BOOLEAN
|
---|
1278 | IsThisFmpImageInfo (
|
---|
1279 | IN EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,
|
---|
1280 | IN UINT8 DescriptorCount,
|
---|
1281 | IN UINTN DescriptorSize,
|
---|
1282 | IN EFI_GUID *ImageTypeId
|
---|
1283 | )
|
---|
1284 | {
|
---|
1285 | EFI_FIRMWARE_IMAGE_DESCRIPTOR *CurrentImageInfo;
|
---|
1286 | UINTN Index;
|
---|
1287 |
|
---|
1288 | CurrentImageInfo = ImageInfo;
|
---|
1289 | for (Index = 0; Index < DescriptorCount; Index++) {
|
---|
1290 | if (CompareGuid (&CurrentImageInfo->ImageTypeId, ImageTypeId)) {
|
---|
1291 | return TRUE;
|
---|
1292 | }
|
---|
1293 |
|
---|
1294 | CurrentImageInfo = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)((UINT8 *)CurrentImageInfo + DescriptorSize);
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | return FALSE;
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | /**
|
---|
1301 | return the FMP whoes ImageInfo includes the ImageTypeId.
|
---|
1302 |
|
---|
1303 | @param[in] ImageTypeId A unique GUID identifying the firmware image type.
|
---|
1304 |
|
---|
1305 | @return The FMP whoes ImageInfo includes the ImageTypeId
|
---|
1306 | **/
|
---|
1307 | EFI_FIRMWARE_MANAGEMENT_PROTOCOL *
|
---|
1308 | FindFmpFromImageTypeId (
|
---|
1309 | IN EFI_GUID *ImageTypeId
|
---|
1310 | )
|
---|
1311 | {
|
---|
1312 | EFI_STATUS Status;
|
---|
1313 | EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp;
|
---|
1314 | EFI_FIRMWARE_MANAGEMENT_PROTOCOL *TargetFmp;
|
---|
1315 | EFI_HANDLE *HandleBuffer;
|
---|
1316 | UINTN NumberOfHandles;
|
---|
1317 | UINTN Index;
|
---|
1318 | EFI_FIRMWARE_IMAGE_DESCRIPTOR *FmpImageInfoBuf;
|
---|
1319 | UINTN ImageInfoSize;
|
---|
1320 | UINT32 FmpImageInfoDescriptorVer;
|
---|
1321 | UINT8 FmpImageInfoCount;
|
---|
1322 | UINTN DescriptorSize;
|
---|
1323 | UINT32 PackageVersion;
|
---|
1324 | CHAR16 *PackageVersionName;
|
---|
1325 |
|
---|
1326 | Status = gBS->LocateHandleBuffer (
|
---|
1327 | ByProtocol,
|
---|
1328 | &gEfiFirmwareManagementProtocolGuid,
|
---|
1329 | NULL,
|
---|
1330 | &NumberOfHandles,
|
---|
1331 | &HandleBuffer
|
---|
1332 | );
|
---|
1333 | if (EFI_ERROR (Status)) {
|
---|
1334 | Print (L"FMP protocol - %r\n", EFI_NOT_FOUND);
|
---|
1335 | return NULL;
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 | TargetFmp = NULL;
|
---|
1339 | for (Index = 0; Index < NumberOfHandles; Index++) {
|
---|
1340 | Status = gBS->HandleProtocol (
|
---|
1341 | HandleBuffer[Index],
|
---|
1342 | &gEfiFirmwareManagementProtocolGuid,
|
---|
1343 | (VOID **)&Fmp
|
---|
1344 | );
|
---|
1345 | if (EFI_ERROR (Status)) {
|
---|
1346 | continue;
|
---|
1347 | }
|
---|
1348 |
|
---|
1349 | ImageInfoSize = 0;
|
---|
1350 | Status = Fmp->GetImageInfo (
|
---|
1351 | Fmp,
|
---|
1352 | &ImageInfoSize,
|
---|
1353 | NULL,
|
---|
1354 | NULL,
|
---|
1355 | NULL,
|
---|
1356 | NULL,
|
---|
1357 | NULL,
|
---|
1358 | NULL
|
---|
1359 | );
|
---|
1360 | if (Status != EFI_BUFFER_TOO_SMALL) {
|
---|
1361 | continue;
|
---|
1362 | }
|
---|
1363 |
|
---|
1364 | FmpImageInfoBuf = NULL;
|
---|
1365 | FmpImageInfoBuf = AllocateZeroPool (ImageInfoSize);
|
---|
1366 | if (FmpImageInfoBuf == NULL) {
|
---|
1367 | FreePool (HandleBuffer);
|
---|
1368 | Print (L"Out of resource\n");
|
---|
1369 | return NULL;
|
---|
1370 | }
|
---|
1371 |
|
---|
1372 | PackageVersionName = NULL;
|
---|
1373 | Status = Fmp->GetImageInfo (
|
---|
1374 | Fmp,
|
---|
1375 | &ImageInfoSize, // ImageInfoSize
|
---|
1376 | FmpImageInfoBuf, // ImageInfo
|
---|
1377 | &FmpImageInfoDescriptorVer, // DescriptorVersion
|
---|
1378 | &FmpImageInfoCount, // DescriptorCount
|
---|
1379 | &DescriptorSize, // DescriptorSize
|
---|
1380 | &PackageVersion, // PackageVersion
|
---|
1381 | &PackageVersionName // PackageVersionName
|
---|
1382 | );
|
---|
1383 |
|
---|
1384 | //
|
---|
1385 | // If FMP GetInformation interface failed, skip this resource
|
---|
1386 | //
|
---|
1387 | if (EFI_ERROR (Status)) {
|
---|
1388 | FreePool (FmpImageInfoBuf);
|
---|
1389 | continue;
|
---|
1390 | }
|
---|
1391 |
|
---|
1392 | if (PackageVersionName != NULL) {
|
---|
1393 | FreePool (PackageVersionName);
|
---|
1394 | }
|
---|
1395 |
|
---|
1396 | if (IsThisFmpImageInfo (FmpImageInfoBuf, FmpImageInfoCount, DescriptorSize, ImageTypeId)) {
|
---|
1397 | TargetFmp = Fmp;
|
---|
1398 | }
|
---|
1399 |
|
---|
1400 | FreePool (FmpImageInfoBuf);
|
---|
1401 | if (TargetFmp != NULL) {
|
---|
1402 | break;
|
---|
1403 | }
|
---|
1404 | }
|
---|
1405 |
|
---|
1406 | FreePool (HandleBuffer);
|
---|
1407 | return TargetFmp;
|
---|
1408 | }
|
---|
1409 |
|
---|
1410 | /**
|
---|
1411 | Dump FMP image data.
|
---|
1412 |
|
---|
1413 | @param[in] ImageTypeId The ImageTypeId of the FMP image.
|
---|
1414 | It is used to identify the FMP protocol.
|
---|
1415 | @param[in] ImageIndex The ImageIndex of the FMP image.
|
---|
1416 | It is the input parameter for FMP->GetImage().
|
---|
1417 | @param[in] ImageName The file name to hold the output FMP image.
|
---|
1418 | **/
|
---|
1419 | VOID
|
---|
1420 | DumpFmpImage (
|
---|
1421 | IN EFI_GUID *ImageTypeId,
|
---|
1422 | IN UINTN ImageIndex,
|
---|
1423 | IN CHAR16 *ImageName
|
---|
1424 | )
|
---|
1425 | {
|
---|
1426 | EFI_STATUS Status;
|
---|
1427 | EFI_FIRMWARE_MANAGEMENT_PROTOCOL *Fmp;
|
---|
1428 | VOID *Image;
|
---|
1429 | UINTN ImageSize;
|
---|
1430 |
|
---|
1431 | Fmp = FindFmpFromImageTypeId (ImageTypeId);
|
---|
1432 | if (Fmp == NULL) {
|
---|
1433 | Print (L"No FMP include ImageTypeId %g\n", ImageTypeId);
|
---|
1434 | return;
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | if (ImageIndex > 0xFF) {
|
---|
1438 | Print (L"ImageIndex 0x%x too big\n", ImageIndex);
|
---|
1439 | return;
|
---|
1440 | }
|
---|
1441 |
|
---|
1442 | Image = Fmp;
|
---|
1443 | ImageSize = 0;
|
---|
1444 | Status = Fmp->GetImage (Fmp, (UINT8)ImageIndex, Image, &ImageSize);
|
---|
1445 | if (Status != EFI_BUFFER_TOO_SMALL) {
|
---|
1446 | Print (L"Fmp->GetImage - %r\n", Status);
|
---|
1447 | return;
|
---|
1448 | }
|
---|
1449 |
|
---|
1450 | Image = AllocatePool (ImageSize);
|
---|
1451 | if (Image == NULL) {
|
---|
1452 | Print (L"Allocate FmpImage 0x%x - %r\n", ImageSize, EFI_OUT_OF_RESOURCES);
|
---|
1453 | return;
|
---|
1454 | }
|
---|
1455 |
|
---|
1456 | Status = Fmp->GetImage (Fmp, (UINT8)ImageIndex, Image, &ImageSize);
|
---|
1457 | if (EFI_ERROR (Status)) {
|
---|
1458 | Print (L"Fmp->GetImage - %r\n", Status);
|
---|
1459 | return;
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | Status = WriteFileFromBuffer (ImageName, ImageSize, Image);
|
---|
1463 | Print (L"CapsuleApp: Dump %g ImageIndex (0x%x) to %s %r\n", ImageTypeId, ImageIndex, ImageName, Status);
|
---|
1464 |
|
---|
1465 | FreePool (Image);
|
---|
1466 |
|
---|
1467 | return;
|
---|
1468 | }
|
---|