Changeset 99404 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
- Timestamp:
- Apr 14, 2023 3:17:44 PM (22 months ago)
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-145445 /vendor/edk2/current 103735-103757,103769-103776,129194-156846
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c
r85718 r99404 28 28 ) 29 29 { 30 CHAR16 31 VOID 32 UINTN 33 CHAR16 34 UINT8 35 UINTN 36 EFI_DISPLAY_CAPSULE 37 EFI_STATUS 38 EFI_GRAPHICS_OUTPUT_PROTOCOL 39 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION 40 EFI_GRAPHICS_OUTPUT_BLT_PIXEL 41 UINTN 42 UINTN 43 UINTN 44 45 Status = gBS->LocateProtocol (&gEfiGraphicsOutputProtocolGuid, NULL, (VOID **)&Gop);46 if (EFI_ERROR (Status)) {47 Print (L"CapsuleApp: NO GOP is found.\n");30 CHAR16 *OutputCapsuleName; 31 VOID *BmpBuffer; 32 UINTN FileSize; 33 CHAR16 *BmpName; 34 UINT8 *FullCapsuleBuffer; 35 UINTN FullCapsuleBufferSize; 36 EFI_DISPLAY_CAPSULE *DisplayCapsule; 37 EFI_STATUS Status; 38 EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; 39 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; 40 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *GopBlt; 41 UINTN GopBltSize; 42 UINTN Height; 43 UINTN Width; 44 45 Status = gBS->LocateProtocol (&gEfiGraphicsOutputProtocolGuid, NULL, (VOID **)&Gop); 46 if (EFI_ERROR (Status)) { 47 Print (L"CapsuleApp: NO GOP is found.\n"); 48 48 return EFI_UNSUPPORTED; 49 49 } 50 50 51 Info = Gop->Mode->Info; 51 Print (L"Current GOP: Mode - %d, ", Gop->Mode->Mode);52 Print (L"HorizontalResolution - %d, ", Info->HorizontalResolution);53 Print (L"VerticalResolution - %d\n", Info->VerticalResolution);52 Print (L"Current GOP: Mode - %d, ", Gop->Mode->Mode); 53 Print (L"HorizontalResolution - %d, ", Info->HorizontalResolution); 54 Print (L"VerticalResolution - %d\n", Info->VerticalResolution); 54 55 // HorizontalResolution >= BMP_IMAGE_HEADER.PixelWidth 55 56 // VerticalResolution >= BMP_IMAGE_HEADER.PixelHeight 56 57 57 58 if (Argc != 5) { 58 Print (L"CapsuleApp: Incorrect parameter count.\n");59 Print (L"CapsuleApp: Incorrect parameter count.\n"); 59 60 return EFI_UNSUPPORTED; 60 61 } 61 62 62 if (StrCmp (Argv[3], L"-O") != 0) {63 Print (L"CapsuleApp: NO output capsule name.\n");63 if (StrCmp (Argv[3], L"-O") != 0) { 64 Print (L"CapsuleApp: NO output capsule name.\n"); 64 65 return EFI_UNSUPPORTED; 65 66 } 67 66 68 OutputCapsuleName = Argv[4]; 67 69 68 BmpBuffer = NULL;69 FileSize = 0;70 BmpBuffer = NULL; 71 FileSize = 0; 70 72 FullCapsuleBuffer = NULL; 71 73 72 74 BmpName = Argv[2]; 73 Status = ReadFileToBuffer(BmpName, &FileSize, &BmpBuffer);74 if (EFI_ERROR (Status)) {75 Print (L"CapsuleApp: BMP image (%s) is not found.\n", BmpName);75 Status = ReadFileToBuffer (BmpName, &FileSize, &BmpBuffer); 76 if (EFI_ERROR (Status)) { 77 Print (L"CapsuleApp: BMP image (%s) is not found.\n", BmpName); 76 78 goto Done; 77 79 } … … 86 88 &Width 87 89 ); 88 if (EFI_ERROR(Status)) { 89 Print(L"CapsuleApp: BMP image (%s) is not valid.\n", BmpName); 90 goto Done; 91 } 90 if (EFI_ERROR (Status)) { 91 Print (L"CapsuleApp: BMP image (%s) is not valid.\n", BmpName); 92 goto Done; 93 } 94 92 95 if (GopBlt != NULL) { 93 96 FreePool (GopBlt); 94 97 } 95 Print(L"BMP image (%s), Width - %d, Height - %d\n", BmpName, Width, Height); 98 99 Print (L"BMP image (%s), Width - %d, Height - %d\n", BmpName, Width, Height); 96 100 97 101 if (Height > Info->VerticalResolution) { 98 102 Status = EFI_INVALID_PARAMETER; 99 Print(L"CapsuleApp: BMP image (%s) height is larger than current resolution.\n", BmpName); 100 goto Done; 101 } 103 Print (L"CapsuleApp: BMP image (%s) height is larger than current resolution.\n", BmpName); 104 goto Done; 105 } 106 102 107 if (Width > Info->HorizontalResolution) { 103 108 Status = EFI_INVALID_PARAMETER; 104 Print (L"CapsuleApp: BMP image (%s) width is larger than current resolution.\n", BmpName);105 goto Done; 106 } 107 108 FullCapsuleBufferSize = sizeof (EFI_DISPLAY_CAPSULE) + FileSize;109 FullCapsuleBuffer = AllocatePool(FullCapsuleBufferSize);109 Print (L"CapsuleApp: BMP image (%s) width is larger than current resolution.\n", BmpName); 110 goto Done; 111 } 112 113 FullCapsuleBufferSize = sizeof (EFI_DISPLAY_CAPSULE) + FileSize; 114 FullCapsuleBuffer = AllocatePool (FullCapsuleBufferSize); 110 115 if (FullCapsuleBuffer == NULL) { 111 Print (L"CapsuleApp: Capsule Buffer size (0x%x) too big.\n", FullCapsuleBufferSize);116 Print (L"CapsuleApp: Capsule Buffer size (0x%x) too big.\n", FullCapsuleBufferSize); 112 117 Status = EFI_OUT_OF_RESOURCES; 113 118 goto Done; … … 115 120 116 121 DisplayCapsule = (EFI_DISPLAY_CAPSULE *)FullCapsuleBuffer; 117 CopyGuid (&DisplayCapsule->CapsuleHeader.CapsuleGuid, &gWindowsUxCapsuleGuid);118 DisplayCapsule->CapsuleHeader.HeaderSize = sizeof(DisplayCapsule->CapsuleHeader);119 DisplayCapsule->CapsuleHeader.Flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET;122 CopyGuid (&DisplayCapsule->CapsuleHeader.CapsuleGuid, &gWindowsUxCapsuleGuid); 123 DisplayCapsule->CapsuleHeader.HeaderSize = sizeof (DisplayCapsule->CapsuleHeader); 124 DisplayCapsule->CapsuleHeader.Flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET; 120 125 DisplayCapsule->CapsuleHeader.CapsuleImageSize = (UINT32)FullCapsuleBufferSize; 121 126 122 DisplayCapsule->ImagePayload.Version = 1;123 DisplayCapsule->ImagePayload.Checksum = 0;127 DisplayCapsule->ImagePayload.Version = 1; 128 DisplayCapsule->ImagePayload.Checksum = 0; 124 129 DisplayCapsule->ImagePayload.ImageType = 0; // BMP 125 DisplayCapsule->ImagePayload.Reserved = 0;126 DisplayCapsule->ImagePayload.Mode = Gop->Mode->Mode;130 DisplayCapsule->ImagePayload.Reserved = 0; 131 DisplayCapsule->ImagePayload.Mode = Gop->Mode->Mode; 127 132 128 133 // … … 141 146 ); 142 147 143 Print(L"BMP image (%s), OffsetX - %d, OffsetY - %d\n", 148 Print ( 149 L"BMP image (%s), OffsetX - %d, OffsetY - %d\n", 144 150 BmpName, 145 151 DisplayCapsule->ImagePayload.OffsetX, … … 147 153 ); 148 154 149 CopyMem ((DisplayCapsule + 1), BmpBuffer, FileSize);150 151 DisplayCapsule->ImagePayload.Checksum = CalculateCheckSum8 (FullCapsuleBuffer, FullCapsuleBufferSize);152 153 Status = WriteFileFromBuffer (OutputCapsuleName, FullCapsuleBufferSize, FullCapsuleBuffer);154 Print (L"CapsuleApp: Write %s %r\n", OutputCapsuleName, Status);155 CopyMem ((DisplayCapsule + 1), BmpBuffer, FileSize); 156 157 DisplayCapsule->ImagePayload.Checksum = CalculateCheckSum8 (FullCapsuleBuffer, FullCapsuleBufferSize); 158 159 Status = WriteFileFromBuffer (OutputCapsuleName, FullCapsuleBufferSize, FullCapsuleBuffer); 160 Print (L"CapsuleApp: Write %s %r\n", OutputCapsuleName, Status); 155 161 156 162 Done: 157 163 if (BmpBuffer != NULL) { 158 FreePool (BmpBuffer);164 FreePool (BmpBuffer); 159 165 } 160 166 161 167 if (FullCapsuleBuffer != NULL) { 162 FreePool (FullCapsuleBuffer);168 FreePool (FullCapsuleBuffer); 163 169 } 164 170 … … 175 181 EFI_GUID * 176 182 GetCapsuleImageTypeId ( 177 IN EFI_CAPSULE_HEADER 183 IN EFI_CAPSULE_HEADER *CapsuleHeader 178 184 ) 179 185 { 180 EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *FmpCapsuleHeader;181 UINT64 *ItemOffsetList;182 EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *ImageHeader;186 EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *FmpCapsuleHeader; 187 UINT64 *ItemOffsetList; 188 EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *ImageHeader; 183 189 184 190 FmpCapsuleHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *)((UINT8 *)CapsuleHeader + CapsuleHeader->HeaderSize); 185 ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1);191 ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1); 186 192 if (FmpCapsuleHeader->PayloadItemCount == 0) { 187 193 return NULL; 188 194 } 195 189 196 ImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[FmpCapsuleHeader->EmbeddedDriverCount]); 190 197 return &ImageHeader->UpdateImageTypeId; … … 200 207 UINT32 201 208 GetEsrtFwType ( 202 IN EFI_GUID 209 IN EFI_GUID *ImageTypeId 203 210 ) 204 211 { … … 211 218 // Check ESRT 212 219 // 213 Status = EfiGetSystemConfigurationTable (&gEfiSystemResourceTableGuid, (VOID **)&Esrt);214 if (!EFI_ERROR (Status)) {215 ASSERT (Esrt != NULL);220 Status = EfiGetSystemConfigurationTable (&gEfiSystemResourceTableGuid, (VOID **)&Esrt); 221 if (!EFI_ERROR (Status)) { 222 ASSERT (Esrt != NULL); 216 223 EsrtEntry = (VOID *)(Esrt + 1); 217 224 for (Index = 0; Index < Esrt->FwResourceCount; Index++, EsrtEntry++) { 218 if (CompareGuid (&EsrtEntry->FwClass, ImageTypeId)) {225 if (CompareGuid (&EsrtEntry->FwClass, ImageTypeId)) { 219 226 return EsrtEntry->FwType; 220 227 } … … 239 246 BOOLEAN 240 247 IsValidCapsuleHeader ( 241 IN EFI_CAPSULE_HEADER 242 IN UINT64 248 IN EFI_CAPSULE_HEADER *CapsuleHeader, 249 IN UINT64 CapsuleSize 243 250 ) 244 251 { … … 246 253 return FALSE; 247 254 } 255 248 256 if (CapsuleHeader->CapsuleImageSize != CapsuleSize) { 249 257 return FALSE; 250 258 } 259 251 260 if (CapsuleHeader->HeaderSize > CapsuleHeader->CapsuleImageSize) { 252 261 return FALSE; 253 262 } 263 254 264 if (CapsuleHeader->HeaderSize < sizeof (EFI_CAPSULE_HEADER)) { 255 265 return FALSE; … … 272 282 ) 273 283 { 274 if (CompareGuid (&gEfiFmpCapsuleGuid, CapsuleGuid)) {284 if (CompareGuid (&gEfiFmpCapsuleGuid, CapsuleGuid)) { 275 285 return TRUE; 276 286 } … … 292 302 ) 293 303 { 294 CHAR16 295 VOID 296 UINTN 297 CHAR16 298 UINT8 299 UINTN 300 EFI_CAPSULE_HEADER 301 EFI_GUID 302 UINT32 303 EFI_STATUS 304 CHAR16 *OutputCapsuleName; 305 VOID *CapsuleBuffer; 306 UINTN FileSize; 307 CHAR16 *CapsuleName; 308 UINT8 *FullCapsuleBuffer; 309 UINTN FullCapsuleBufferSize; 310 EFI_CAPSULE_HEADER *NestedCapsuleHeader; 311 EFI_GUID *ImageTypeId; 312 UINT32 FwType; 313 EFI_STATUS Status; 304 314 305 315 if (Argc != 5) { 306 Print (L"CapsuleApp: Incorrect parameter count.\n");316 Print (L"CapsuleApp: Incorrect parameter count.\n"); 307 317 return EFI_UNSUPPORTED; 308 318 } 309 319 310 if (StrCmp (Argv[3], L"-O") != 0) {311 Print (L"CapsuleApp: NO output capsule name.\n");320 if (StrCmp (Argv[3], L"-O") != 0) { 321 Print (L"CapsuleApp: NO output capsule name.\n"); 312 322 return EFI_UNSUPPORTED; 313 323 } 324 314 325 OutputCapsuleName = Argv[4]; 315 326 316 CapsuleBuffer = NULL;317 FileSize = 0;327 CapsuleBuffer = NULL; 328 FileSize = 0; 318 329 FullCapsuleBuffer = NULL; 319 330 320 331 CapsuleName = Argv[2]; 321 Status = ReadFileToBuffer(CapsuleName, &FileSize, &CapsuleBuffer); 322 if (EFI_ERROR(Status)) { 323 Print(L"CapsuleApp: Capsule image (%s) is not found.\n", CapsuleName); 324 goto Done; 325 } 332 Status = ReadFileToBuffer (CapsuleName, &FileSize, &CapsuleBuffer); 333 if (EFI_ERROR (Status)) { 334 Print (L"CapsuleApp: Capsule image (%s) is not found.\n", CapsuleName); 335 goto Done; 336 } 337 326 338 if (!IsValidCapsuleHeader (CapsuleBuffer, FileSize)) { 327 Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);339 Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName); 328 340 Status = EFI_INVALID_PARAMETER; 329 341 goto Done; 330 342 } 331 343 332 if (!IsFmpCapsuleGuid (&((EFI_CAPSULE_HEADER *) 333 Print (L"CapsuleApp: Capsule image (%s) is not a FMP capsule.\n", CapsuleName);344 if (!IsFmpCapsuleGuid (&((EFI_CAPSULE_HEADER *)CapsuleBuffer)->CapsuleGuid)) { 345 Print (L"CapsuleApp: Capsule image (%s) is not a FMP capsule.\n", CapsuleName); 334 346 Status = EFI_INVALID_PARAMETER; 335 347 goto Done; 336 348 } 337 349 338 ImageTypeId = GetCapsuleImageTypeId (CapsuleBuffer);350 ImageTypeId = GetCapsuleImageTypeId (CapsuleBuffer); 339 351 if (ImageTypeId == NULL) { 340 Print (L"CapsuleApp: Capsule ImageTypeId is not found.\n");352 Print (L"CapsuleApp: Capsule ImageTypeId is not found.\n"); 341 353 Status = EFI_INVALID_PARAMETER; 342 354 goto Done; 343 355 } 344 FwType = GetEsrtFwType(ImageTypeId); 356 357 FwType = GetEsrtFwType (ImageTypeId); 345 358 if ((FwType != ESRT_FW_TYPE_SYSTEMFIRMWARE) && (FwType != ESRT_FW_TYPE_DEVICEFIRMWARE)) { 346 Print (L"CapsuleApp: Capsule FwType is invalid.\n");359 Print (L"CapsuleApp: Capsule FwType is invalid.\n"); 347 360 Status = EFI_INVALID_PARAMETER; 348 361 goto Done; … … 350 363 351 364 FullCapsuleBufferSize = NESTED_CAPSULE_HEADER_SIZE + FileSize; 352 FullCapsuleBuffer = AllocatePool(FullCapsuleBufferSize);365 FullCapsuleBuffer = AllocatePool (FullCapsuleBufferSize); 353 366 if (FullCapsuleBuffer == NULL) { 354 Print (L"CapsuleApp: Capsule Buffer size (0x%x) too big.\n", FullCapsuleBufferSize);367 Print (L"CapsuleApp: Capsule Buffer size (0x%x) too big.\n", FullCapsuleBufferSize); 355 368 Status = EFI_OUT_OF_RESOURCES; 356 369 goto Done; … … 358 371 359 372 NestedCapsuleHeader = (EFI_CAPSULE_HEADER *)FullCapsuleBuffer; 360 ZeroMem (NestedCapsuleHeader, NESTED_CAPSULE_HEADER_SIZE);361 CopyGuid (&NestedCapsuleHeader->CapsuleGuid, ImageTypeId);362 NestedCapsuleHeader->HeaderSize = NESTED_CAPSULE_HEADER_SIZE;363 NestedCapsuleHeader->Flags = (FwType == ESRT_FW_TYPE_SYSTEMFIRMWARE) ? SYSTEM_FIRMWARE_FLAG : DEVICE_FIRMWARE_FLAG;373 ZeroMem (NestedCapsuleHeader, NESTED_CAPSULE_HEADER_SIZE); 374 CopyGuid (&NestedCapsuleHeader->CapsuleGuid, ImageTypeId); 375 NestedCapsuleHeader->HeaderSize = NESTED_CAPSULE_HEADER_SIZE; 376 NestedCapsuleHeader->Flags = (FwType == ESRT_FW_TYPE_SYSTEMFIRMWARE) ? SYSTEM_FIRMWARE_FLAG : DEVICE_FIRMWARE_FLAG; 364 377 NestedCapsuleHeader->CapsuleImageSize = (UINT32)FullCapsuleBufferSize; 365 378 366 CopyMem ((UINT8 *)NestedCapsuleHeader + NestedCapsuleHeader->HeaderSize, CapsuleBuffer, FileSize);367 368 Status = WriteFileFromBuffer (OutputCapsuleName, FullCapsuleBufferSize, FullCapsuleBuffer);369 Print (L"CapsuleApp: Write %s %r\n", OutputCapsuleName, Status);379 CopyMem ((UINT8 *)NestedCapsuleHeader + NestedCapsuleHeader->HeaderSize, CapsuleBuffer, FileSize); 380 381 Status = WriteFileFromBuffer (OutputCapsuleName, FullCapsuleBufferSize, FullCapsuleBuffer); 382 Print (L"CapsuleApp: Write %s %r\n", OutputCapsuleName, Status); 370 383 371 384 Done: 372 385 if (CapsuleBuffer != NULL) { 373 FreePool (CapsuleBuffer);386 FreePool (CapsuleBuffer); 374 387 } 375 388 376 389 if (FullCapsuleBuffer != NULL) { 377 FreePool (FullCapsuleBuffer);390 FreePool (FullCapsuleBuffer); 378 391 } 379 392 380 393 return Status; 381 394 } 382 383 395 384 396 /** … … 392 404 ) 393 405 { 394 EFI_STATUS 395 UINT32 396 CHAR16 397 CHAR16 398 BOOLEAN 399 400 StrCpyS (CapsuleVarName, sizeof (CapsuleVarName)/sizeof(CapsuleVarName[0]), L"Capsule");406 EFI_STATUS Status; 407 UINT32 Index; 408 CHAR16 CapsuleVarName[20]; 409 CHAR16 *TempVarName; 410 BOOLEAN Found; 411 412 StrCpyS (CapsuleVarName, sizeof (CapsuleVarName)/sizeof (CapsuleVarName[0]), L"Capsule"); 401 413 TempVarName = CapsuleVarName + StrLen (CapsuleVarName); 402 Index = 0;414 Index = 0; 403 415 404 416 Found = FALSE; 405 417 while (TRUE) { 406 UnicodeSPrint (TempVarName, 5 * sizeof (CHAR16), L"%04x", Index);418 UnicodeSPrint (TempVarName, 5 * sizeof (CHAR16), L"%04x", Index); 407 419 408 420 Status = gRT->SetVariable ( … … 419 431 break; 420 432 } 433 421 434 Found = TRUE; 422 435 … … 448 461 EFI_STATUS 449 462 BuildGatherList ( 450 IN VOID **CapsuleBuffer,451 IN UINTN *FileSize,452 IN UINTN CapsuleNum,453 OUT EFI_CAPSULE_BLOCK_DESCRIPTOR **BlockDescriptors463 IN VOID **CapsuleBuffer, 464 IN UINTN *FileSize, 465 IN UINTN CapsuleNum, 466 OUT EFI_CAPSULE_BLOCK_DESCRIPTOR **BlockDescriptors 454 467 ) 455 468 { … … 483 496 } 484 497 485 Size 486 BlockDescriptors1 498 Size = Count * sizeof (EFI_CAPSULE_BLOCK_DESCRIPTOR); 499 BlockDescriptors1 = AllocateRuntimeZeroPool (Size); 487 500 if (BlockDescriptors1 == NULL) { 488 501 Print (L"CapsuleApp: failed to allocate memory for descriptors\n"); … … 490 503 goto ERREXIT; 491 504 } else { 492 Print (L"CapsuleApp: creating capsule descriptors at 0x%X\n", (UINTN) 493 Print (L"CapsuleApp: capsule data starts at 0x%X with size 0x%X\n", (UINTN) 505 Print (L"CapsuleApp: creating capsule descriptors at 0x%X\n", (UINTN)BlockDescriptors1); 506 Print (L"CapsuleApp: capsule data starts at 0x%X with size 0x%X\n", (UINTN)CapsuleBuffer[Index], FileSize[Index]); 494 507 } 495 508 … … 502 515 503 516 if (BlockDescriptorPre != NULL) { 504 BlockDescriptorPre->Union.ContinuationPointer = (UINTN) 505 BlockDescriptorPre->Length = 0;517 BlockDescriptorPre->Union.ContinuationPointer = (UINTN)BlockDescriptors1; 518 BlockDescriptorPre->Length = 0; 506 519 } 507 520 … … 509 522 // Fill them in 510 523 // 511 TempBlockPtr 512 TempDataPtr 513 SizeLeft 524 TempBlockPtr = BlockDescriptors1; 525 TempDataPtr = CapsuleBuffer[Index]; 526 SizeLeft = FileSize[Index]; 514 527 for (Number = 0; (Number < Count - 1) && (SizeLeft != 0); Number++) { 515 528 // … … 525 538 Size = SizeLeft; 526 539 } 527 TempBlockPtr->Union.DataBlock = (UINTN)TempDataPtr; 528 TempBlockPtr->Length = Size; 529 Print (L"CapsuleApp: capsule block/size 0x%X/0x%X\n", (UINTN) TempDataPtr, Size); 530 SizeLeft -= Size; 540 541 TempBlockPtr->Union.DataBlock = (UINTN)TempDataPtr; 542 TempBlockPtr->Length = Size; 543 Print (L"CapsuleApp: capsule block/size 0x%X/0x%X\n", (UINTN)TempDataPtr, Size); 544 SizeLeft -= Size; 531 545 TempDataPtr += Size; 532 546 TempBlockPtr++; … … 556 570 // Point the first list's last element to point to this second list. 557 571 // 558 TempBlockPtr->Union.ContinuationPointer = (UINTN)BlockDescriptors2;559 560 TempBlockPtr->Length 561 TempBlockPtr = BlockDescriptors2;572 TempBlockPtr->Union.ContinuationPointer = (UINTN)BlockDescriptors2; 573 574 TempBlockPtr->Length = 0; 575 TempBlockPtr = BlockDescriptors2; 562 576 for (Number = 0; Number < Count - 1; Number++) { 563 577 // … … 577 591 } 578 592 579 TempBlockPtr->Union.DataBlock 580 TempBlockPtr->Length = Size;581 Print (L"CapsuleApp: capsule block/size 0x%X/0x%X\n", (UINTN) 582 SizeLeft -= Size;593 TempBlockPtr->Union.DataBlock = (UINTN)TempDataPtr; 594 TempBlockPtr->Length = Size; 595 Print (L"CapsuleApp: capsule block/size 0x%X/0x%X\n", (UINTN)TempDataPtr, Size); 596 SizeLeft -= Size; 583 597 TempDataPtr += Size; 584 598 TempBlockPtr++; … … 597 611 // 598 612 if (TempBlockPtr != NULL) { 599 TempBlockPtr->Union.ContinuationPointer 600 TempBlockPtr->Length = 0;601 *BlockDescriptors = BlockDescriptorsHeader;613 TempBlockPtr->Union.ContinuationPointer = (UINTN)NULL; 614 TempBlockPtr->Length = 0; 615 *BlockDescriptors = BlockDescriptorsHeader; 602 616 } 603 617 … … 606 620 ERREXIT: 607 621 if (BlockDescriptors1 != NULL) { 608 FreePool (BlockDescriptors1);622 FreePool (BlockDescriptors1); 609 623 } 610 624 611 625 if (BlockDescriptors2 != NULL) { 612 FreePool (BlockDescriptors2);626 FreePool (BlockDescriptors2); 613 627 } 614 628 … … 624 638 VOID 625 639 CleanGatherList ( 626 IN EFI_CAPSULE_BLOCK_DESCRIPTOR 627 IN UINTN 640 IN EFI_CAPSULE_BLOCK_DESCRIPTOR *BlockDescriptors, 641 IN UINTN CapsuleNum 628 642 ) 629 643 { 630 EFI_CAPSULE_BLOCK_DESCRIPTOR 631 EFI_CAPSULE_BLOCK_DESCRIPTOR 632 EFI_CAPSULE_BLOCK_DESCRIPTOR 633 UINTN 644 EFI_CAPSULE_BLOCK_DESCRIPTOR *TempBlockPtr; 645 EFI_CAPSULE_BLOCK_DESCRIPTOR *TempBlockPtr1; 646 EFI_CAPSULE_BLOCK_DESCRIPTOR *TempBlockPtr2; 647 UINTN Index; 634 648 635 649 if (BlockDescriptors != NULL) { 636 650 TempBlockPtr1 = BlockDescriptors; 637 while (1) {651 while (1) { 638 652 TempBlockPtr = TempBlockPtr1; 639 653 for (Index = 0; Index < CapsuleNum; Index++) { … … 647 661 } 648 662 649 TempBlockPtr2 = (VOID *) ((UINTN)TempBlockPtr[Index].Union.ContinuationPointer);650 FreePool (TempBlockPtr1);663 TempBlockPtr2 = (VOID *)((UINTN)TempBlockPtr[Index].Union.ContinuationPointer); 664 FreePool (TempBlockPtr1); 651 665 TempBlockPtr1 = TempBlockPtr2; 652 666 } … … 662 676 ) 663 677 { 664 Print (L"CapsuleApp: usage\n");665 Print (L" CapsuleApp <Capsule...> [-NR] [-OD [FSx]]\n");666 Print (L" CapsuleApp -S\n");667 Print (L" CapsuleApp -C\n");668 Print (L" CapsuleApp -P\n");669 Print (L" CapsuleApp -E\n");670 Print (L" CapsuleApp -L\n");671 Print (L" CapsuleApp -L INFO\n");672 Print (L" CapsuleApp -F\n");673 Print (L" CapsuleApp -G <BMP> -O <Capsule>\n");674 Print (L" CapsuleApp -N <Capsule> -O <NestedCapsule>\n");675 Print (L" CapsuleApp -D <Capsule>\n");676 Print (L" CapsuleApp -P GET <ImageTypeId> <Index> -O <FileName>\n");677 Print (L"Parameter:\n");678 Print (L" -NR: No reset will be triggered for the capsule\n");679 Print (L" with CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without CAPSULE_FLAGS_INITIATE_RESET.\n");680 Print (L" -OD: Delivery of Capsules via file on Mass Storage device.\n");681 Print (L" -S: Dump capsule report variable (EFI_CAPSULE_REPORT_GUID),\n");682 Print (L" which is defined in UEFI specification.\n");683 Print (L" -C: Clear capsule report variable (EFI_CAPSULE_REPORT_GUID),\n");684 Print (L" which is defined in UEFI specification.\n");685 Print (L" -P: Dump UEFI FMP protocol info, or get image with specified\n");686 Print (L" ImageTypeId and Index (decimal format) to a file if 'GET'\n");687 Print (L" option is used.\n");688 Print (L" -E: Dump UEFI ESRT table info.\n");689 Print (L" -L: Dump provisioned capsule image information.\n");690 Print (L" -F: Dump all EFI System Partition.\n");691 Print (L" -G: Convert a BMP file to be an UX capsule,\n");692 Print (L" according to Windows Firmware Update document\n");693 Print (L" -N: Append a Capsule Header to an existing FMP capsule image\n");694 Print (L" with its ImageTypeId supported by the system,\n");695 Print (L" according to Windows Firmware Update document\n");696 Print (L" -O: Output new Capsule file name\n");697 Print (L" -D: Dump Capsule image header information, image payload\n");698 Print (L" information if it is an UX capsule and FMP header\n");699 Print (L" information if it is a FMP capsule.\n");678 Print (L"CapsuleApp: usage\n"); 679 Print (L" CapsuleApp <Capsule...> [-NR] [-OD [FSx]]\n"); 680 Print (L" CapsuleApp -S\n"); 681 Print (L" CapsuleApp -C\n"); 682 Print (L" CapsuleApp -P\n"); 683 Print (L" CapsuleApp -E\n"); 684 Print (L" CapsuleApp -L\n"); 685 Print (L" CapsuleApp -L INFO\n"); 686 Print (L" CapsuleApp -F\n"); 687 Print (L" CapsuleApp -G <BMP> -O <Capsule>\n"); 688 Print (L" CapsuleApp -N <Capsule> -O <NestedCapsule>\n"); 689 Print (L" CapsuleApp -D <Capsule>\n"); 690 Print (L" CapsuleApp -P GET <ImageTypeId> <Index> -O <FileName>\n"); 691 Print (L"Parameter:\n"); 692 Print (L" -NR: No reset will be triggered for the capsule\n"); 693 Print (L" with CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without CAPSULE_FLAGS_INITIATE_RESET.\n"); 694 Print (L" -OD: Delivery of Capsules via file on Mass Storage device.\n"); 695 Print (L" -S: Dump capsule report variable (EFI_CAPSULE_REPORT_GUID),\n"); 696 Print (L" which is defined in UEFI specification.\n"); 697 Print (L" -C: Clear capsule report variable (EFI_CAPSULE_REPORT_GUID),\n"); 698 Print (L" which is defined in UEFI specification.\n"); 699 Print (L" -P: Dump UEFI FMP protocol info, or get image with specified\n"); 700 Print (L" ImageTypeId and Index (decimal format) to a file if 'GET'\n"); 701 Print (L" option is used.\n"); 702 Print (L" -E: Dump UEFI ESRT table info.\n"); 703 Print (L" -L: Dump provisioned capsule image information.\n"); 704 Print (L" -F: Dump all EFI System Partition.\n"); 705 Print (L" -G: Convert a BMP file to be an UX capsule,\n"); 706 Print (L" according to Windows Firmware Update document\n"); 707 Print (L" -N: Append a Capsule Header to an existing FMP capsule image\n"); 708 Print (L" with its ImageTypeId supported by the system,\n"); 709 Print (L" according to Windows Firmware Update document\n"); 710 Print (L" -O: Output new Capsule file name\n"); 711 Print (L" -D: Dump Capsule image header information, image payload\n"); 712 Print (L" information if it is an UX capsule and FMP header\n"); 713 Print (L" information if it is a FMP capsule.\n"); 700 714 } 701 715 … … 739 753 UINTN ImageIndex; 740 754 741 BlockDescriptors 742 MapFsStr 743 CapsuleNum 744 745 Status = GetArg ();746 if (EFI_ERROR (Status)) {747 Print (L"Please use UEFI SHELL to run this application!\n", Status);755 BlockDescriptors = NULL; 756 MapFsStr = NULL; 757 CapsuleNum = 0; 758 759 Status = GetArg (); 760 if (EFI_ERROR (Status)) { 761 Print (L"Please use UEFI SHELL to run this application!\n", Status); 748 762 return Status; 749 763 } 764 750 765 if (Argc < 2) { 751 PrintUsage ();766 PrintUsage (); 752 767 return EFI_UNSUPPORTED; 753 768 } 754 if (StrCmp(Argv[1], L"-D") == 0) { 769 770 if (StrCmp (Argv[1], L"-D") == 0) { 755 771 if (Argc != 3) { 756 Print (L"CapsuleApp: Incorrect parameter count.\n");772 Print (L"CapsuleApp: Incorrect parameter count.\n"); 757 773 return EFI_UNSUPPORTED; 758 774 } 759 Status = DumpCapsule(Argv[2]); 775 776 Status = DumpCapsule (Argv[2]); 760 777 return Status; 761 778 } 762 if (StrCmp(Argv[1], L"-G") == 0) { 763 Status = CreateBmpFmp(); 779 780 if (StrCmp (Argv[1], L"-G") == 0) { 781 Status = CreateBmpFmp (); 764 782 return Status; 765 783 } 766 if (StrCmp(Argv[1], L"-N") == 0) { 767 Status = CreateNestedFmp(); 784 785 if (StrCmp (Argv[1], L"-N") == 0) { 786 Status = CreateNestedFmp (); 768 787 return Status; 769 788 } 770 if (StrCmp(Argv[1], L"-S") == 0) { 771 Status = DumpCapsuleStatusVariable(); 789 790 if (StrCmp (Argv[1], L"-S") == 0) { 791 Status = DumpCapsuleStatusVariable (); 772 792 return EFI_SUCCESS; 773 793 } 774 if (StrCmp(Argv[1], L"-C") == 0) { 775 Status = ClearCapsuleStatusVariable(); 794 795 if (StrCmp (Argv[1], L"-C") == 0) { 796 Status = ClearCapsuleStatusVariable (); 776 797 return Status; 777 798 } 778 if (StrCmp(Argv[1], L"-P") == 0) { 799 800 if (StrCmp (Argv[1], L"-P") == 0) { 779 801 if (Argc == 2) { 780 DumpFmpData(); 781 } 802 DumpFmpData (); 803 } 804 782 805 if (Argc >= 3) { 783 if (StrCmp (Argv[2], L"GET") != 0) {784 Print (L"CapsuleApp: Unrecognized option(%s).\n", Argv[2]);806 if (StrCmp (Argv[2], L"GET") != 0) { 807 Print (L"CapsuleApp: Unrecognized option(%s).\n", Argv[2]); 785 808 return EFI_UNSUPPORTED; 786 809 } else { 787 810 if (Argc != 7) { 788 Print (L"CapsuleApp: Incorrect parameter count.\n");811 Print (L"CapsuleApp: Incorrect parameter count.\n"); 789 812 return EFI_UNSUPPORTED; 790 813 } … … 798 821 return EFI_INVALID_PARAMETER; 799 822 } 800 ImageIndex = StrDecimalToUintn(Argv[4]); 801 if (StrCmp(Argv[5], L"-O") != 0) { 802 Print(L"CapsuleApp: NO output file name.\n"); 823 824 ImageIndex = StrDecimalToUintn (Argv[4]); 825 if (StrCmp (Argv[5], L"-O") != 0) { 826 Print (L"CapsuleApp: NO output file name.\n"); 803 827 return EFI_UNSUPPORTED; 804 828 } 805 DumpFmpImage(&ImageTypeId, ImageIndex, Argv[6]); 829 830 DumpFmpImage (&ImageTypeId, ImageIndex, Argv[6]); 806 831 } 807 832 } 833 808 834 return EFI_SUCCESS; 809 835 } 810 836 811 if (StrCmp (Argv[1], L"-E") == 0) {812 DumpEsrtData ();837 if (StrCmp (Argv[1], L"-E") == 0) { 838 DumpEsrtData (); 813 839 return EFI_SUCCESS; 814 840 } 815 841 816 if (StrCmp (Argv[1], L"-L") == 0) {817 if ( Argc >= 3 && StrCmp(Argv[2], L"INFO") == 0) {818 DumpProvisionedCapsule (TRUE);842 if (StrCmp (Argv[1], L"-L") == 0) { 843 if ((Argc >= 3) && (StrCmp (Argv[2], L"INFO") == 0)) { 844 DumpProvisionedCapsule (TRUE); 819 845 } else { 820 DumpProvisionedCapsule(FALSE); 821 } 846 DumpProvisionedCapsule (FALSE); 847 } 848 822 849 return EFI_SUCCESS; 823 850 } 824 851 825 if (StrCmp (Argv[1], L"-F") == 0) {826 DumpAllEfiSysPartition ();852 if (StrCmp (Argv[1], L"-F") == 0) { 853 DumpAllEfiSysPartition (); 827 854 return EFI_SUCCESS; 828 855 } 829 856 830 857 if (Argv[1][0] == L'-') { 831 Print (L"CapsuleApp: Unrecognized option(%s).\n", Argv[1]);858 Print (L"CapsuleApp: Unrecognized option(%s).\n", Argv[1]); 832 859 return EFI_UNSUPPORTED; 833 860 } 834 861 835 862 CapsuleFirstIndex = 1; 836 NoReset = FALSE;837 CapsuleOnDisk = FALSE;838 ParaOdIndex = 0;839 ParaNrIndex = 0;863 NoReset = FALSE; 864 CapsuleOnDisk = FALSE; 865 ParaOdIndex = 0; 866 ParaNrIndex = 0; 840 867 841 868 for (Index = 1; Index < Argc; Index++) { 842 if (StrCmp (Argv[Index], L"-OD") == 0) {843 ParaOdIndex = Index;869 if (StrCmp (Argv[Index], L"-OD") == 0) { 870 ParaOdIndex = Index; 844 871 CapsuleOnDisk = TRUE; 845 } else if (StrCmp (Argv[Index], L"-NR") == 0) {872 } else if (StrCmp (Argv[Index], L"-NR") == 0) { 846 873 ParaNrIndex = Index; 847 NoReset = TRUE;874 NoReset = TRUE; 848 875 } 849 876 } … … 887 914 888 915 if (CapsuleFirstIndex > CapsuleLastIndex) { 889 Print (L"CapsuleApp: NO capsule image.\n");916 Print (L"CapsuleApp: NO capsule image.\n"); 890 917 return EFI_UNSUPPORTED; 891 918 } 919 892 920 if (CapsuleNum > MAX_CAPSULE_NUM) { 893 Print (L"CapsuleApp: Too many capsule images.\n");921 Print (L"CapsuleApp: Too many capsule images.\n"); 894 922 return EFI_UNSUPPORTED; 895 923 } 896 924 897 ZeroMem (&CapsuleBuffer, sizeof(CapsuleBuffer));898 ZeroMem (&CapsuleBufferSize, sizeof(CapsuleBufferSize));925 ZeroMem (&CapsuleBuffer, sizeof (CapsuleBuffer)); 926 ZeroMem (&CapsuleBufferSize, sizeof (CapsuleBufferSize)); 899 927 BlockDescriptors = NULL; 900 928 901 929 for (Index = 0; Index < CapsuleNum; Index++) { 902 930 CapsuleName = Argv[CapsuleFirstIndex + Index]; 903 Status = ReadFileToBuffer(CapsuleName, &CapsuleBufferSize[Index], &CapsuleBuffer[Index]);904 if (EFI_ERROR (Status)) {905 Print (L"CapsuleApp: capsule image (%s) is not found.\n", CapsuleName);931 Status = ReadFileToBuffer (CapsuleName, &CapsuleBufferSize[Index], &CapsuleBuffer[Index]); 932 if (EFI_ERROR (Status)) { 933 Print (L"CapsuleApp: capsule image (%s) is not found.\n", CapsuleName); 906 934 goto Done; 907 935 } 936 908 937 if (!IsValidCapsuleHeader (CapsuleBuffer[Index], CapsuleBufferSize[Index])) { 909 Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);938 Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName); 910 939 return EFI_INVALID_PARAMETER; 911 940 } 941 912 942 CapsuleNames[Index] = CapsuleName; 913 943 } … … 916 946 // Every capsule use 2 descriptor 1 for data 1 for end 917 947 // 918 Status = BuildGatherList (CapsuleBuffer, CapsuleBufferSize, CapsuleNum, &BlockDescriptors);919 if (EFI_ERROR (Status)) {948 Status = BuildGatherList (CapsuleBuffer, CapsuleBufferSize, CapsuleNum, &BlockDescriptors); 949 if (EFI_ERROR (Status)) { 920 950 goto Done; 921 951 } … … 926 956 NeedReset = FALSE; 927 957 for (Index = 0; Index < CapsuleNum; Index++) { 928 CapsuleHeaderArray[Index] = (EFI_CAPSULE_HEADER *) 958 CapsuleHeaderArray[Index] = (EFI_CAPSULE_HEADER *)CapsuleBuffer[Index]; 929 959 if ((CapsuleHeaderArray[Index]->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) { 930 960 NeedReset = TRUE; 931 961 } 932 962 } 963 933 964 CapsuleHeaderArray[CapsuleNum] = NULL; 934 965 … … 937 968 // 938 969 Status = gRT->QueryCapsuleCapabilities (CapsuleHeaderArray, CapsuleNum, &MaxCapsuleSize, &ResetType); 939 if (EFI_ERROR (Status)) {970 if (EFI_ERROR (Status)) { 940 971 Print (L"CapsuleApp: failed to query capsule capability - %r\n", Status); 941 972 goto Done; … … 971 1002 // 972 1003 if (NeedReset) { 973 Status = gRT->UpdateCapsule (CapsuleHeaderArray,CapsuleNum,(UINTN)BlockDescriptors);1004 Status = gRT->UpdateCapsule (CapsuleHeaderArray, CapsuleNum, (UINTN)BlockDescriptors); 974 1005 if (Status != EFI_SUCCESS) { 975 1006 Print (L"CapsuleApp: failed to update capsule - %r\n", Status); 976 1007 goto Done; 977 1008 } 1009 978 1010 // 979 1011 // For capsule with CAPSULE_FLAGS_PERSIST_ACROSS_RESET + CAPSULE_FLAGS_INITIATE_RESET, … … 995 1027 // system reset. The service will process the capsule immediately. 996 1028 // 997 Status = gRT->UpdateCapsule (CapsuleHeaderArray, CapsuleNum,(UINTN)BlockDescriptors);1029 Status = gRT->UpdateCapsule (CapsuleHeaderArray, CapsuleNum, (UINTN)BlockDescriptors); 998 1030 if (Status != EFI_SUCCESS) { 999 1031 Print (L"CapsuleApp: failed to update capsule - %r\n", Status); … … 1010 1042 } 1011 1043 1012 CleanGatherList (BlockDescriptors, CapsuleNum);1044 CleanGatherList (BlockDescriptors, CapsuleNum); 1013 1045 1014 1046 return Status;
Note:
See TracChangeset
for help on using the changeset viewer.