VirtualBox

Ignore:
Timestamp:
Apr 14, 2023 3:17:44 PM (22 months ago)
Author:
vboxsync
Message:

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c

    r85718 r99404  
    2828  )
    2929{
    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");
     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");
    4848    return EFI_UNSUPPORTED;
    4949  }
     50
    5051  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);
    5455  // HorizontalResolution >= BMP_IMAGE_HEADER.PixelWidth
    5556  // VerticalResolution   >= BMP_IMAGE_HEADER.PixelHeight
    5657
    5758  if (Argc != 5) {
    58     Print(L"CapsuleApp: Incorrect parameter count.\n");
     59    Print (L"CapsuleApp: Incorrect parameter count.\n");
    5960    return EFI_UNSUPPORTED;
    6061  }
    6162
    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");
    6465    return EFI_UNSUPPORTED;
    6566  }
     67
    6668  OutputCapsuleName = Argv[4];
    6769
    68   BmpBuffer = NULL;
    69   FileSize = 0;
     70  BmpBuffer         = NULL;
     71  FileSize          = 0;
    7072  FullCapsuleBuffer = NULL;
    7173
    7274  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);
    7678    goto Done;
    7779  }
     
    8688             &Width
    8789             );
    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
    9295  if (GopBlt != NULL) {
    9396    FreePool (GopBlt);
    9497  }
    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);
    96100
    97101  if (Height > Info->VerticalResolution) {
    98102    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
    102107  if (Width > Info->HorizontalResolution) {
    103108    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);
    110115  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);
    112117    Status = EFI_OUT_OF_RESOURCES;
    113118    goto Done;
     
    115120
    116121  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;
    120125  DisplayCapsule->CapsuleHeader.CapsuleImageSize = (UINT32)FullCapsuleBufferSize;
    121126
    122   DisplayCapsule->ImagePayload.Version = 1;
    123   DisplayCapsule->ImagePayload.Checksum = 0;
     127  DisplayCapsule->ImagePayload.Version   = 1;
     128  DisplayCapsule->ImagePayload.Checksum  = 0;
    124129  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;
    127132
    128133  //
     
    141146      );
    142147
    143   Print(L"BMP image (%s), OffsetX - %d, OffsetY - %d\n",
     148  Print (
     149    L"BMP image (%s), OffsetX - %d, OffsetY - %d\n",
    144150    BmpName,
    145151    DisplayCapsule->ImagePayload.OffsetX,
     
    147153    );
    148154
    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);
    155161
    156162Done:
    157163  if (BmpBuffer != NULL) {
    158     FreePool(BmpBuffer);
     164    FreePool (BmpBuffer);
    159165  }
    160166
    161167  if (FullCapsuleBuffer != NULL) {
    162     FreePool(FullCapsuleBuffer);
     168    FreePool (FullCapsuleBuffer);
    163169  }
    164170
     
    175181EFI_GUID *
    176182GetCapsuleImageTypeId (
    177   IN EFI_CAPSULE_HEADER                            *CapsuleHeader
     183  IN EFI_CAPSULE_HEADER  *CapsuleHeader
    178184  )
    179185{
    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;
    183189
    184190  FmpCapsuleHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *)((UINT8 *)CapsuleHeader + CapsuleHeader->HeaderSize);
    185   ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1);
     191  ItemOffsetList   = (UINT64 *)(FmpCapsuleHeader + 1);
    186192  if (FmpCapsuleHeader->PayloadItemCount == 0) {
    187193    return NULL;
    188194  }
     195
    189196  ImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[FmpCapsuleHeader->EmbeddedDriverCount]);
    190197  return &ImageHeader->UpdateImageTypeId;
     
    200207UINT32
    201208GetEsrtFwType (
    202   IN  EFI_GUID                                      *ImageTypeId
     209  IN  EFI_GUID  *ImageTypeId
    203210  )
    204211{
     
    211218  // Check ESRT
    212219  //
    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);
    216223    EsrtEntry = (VOID *)(Esrt + 1);
    217224    for (Index = 0; Index < Esrt->FwResourceCount; Index++, EsrtEntry++) {
    218       if (CompareGuid(&EsrtEntry->FwClass, ImageTypeId)) {
     225      if (CompareGuid (&EsrtEntry->FwClass, ImageTypeId)) {
    219226        return EsrtEntry->FwType;
    220227      }
     
    239246BOOLEAN
    240247IsValidCapsuleHeader (
    241   IN EFI_CAPSULE_HEADER     *CapsuleHeader,
    242   IN UINT64                 CapsuleSize
     248  IN EFI_CAPSULE_HEADER  *CapsuleHeader,
     249  IN UINT64              CapsuleSize
    243250  )
    244251{
     
    246253    return FALSE;
    247254  }
     255
    248256  if (CapsuleHeader->CapsuleImageSize != CapsuleSize) {
    249257    return FALSE;
    250258  }
     259
    251260  if (CapsuleHeader->HeaderSize > CapsuleHeader->CapsuleImageSize) {
    252261    return FALSE;
    253262  }
     263
    254264  if (CapsuleHeader->HeaderSize < sizeof (EFI_CAPSULE_HEADER)) {
    255265    return FALSE;
     
    272282  )
    273283{
    274   if (CompareGuid(&gEfiFmpCapsuleGuid, CapsuleGuid)) {
     284  if (CompareGuid (&gEfiFmpCapsuleGuid, CapsuleGuid)) {
    275285    return TRUE;
    276286  }
     
    292302  )
    293303{
    294   CHAR16                                        *OutputCapsuleName;
    295   VOID                                          *CapsuleBuffer;
    296   UINTN                                         FileSize;
    297   CHAR16                                        *CapsuleName;
    298   UINT8                                         *FullCapsuleBuffer;
    299   UINTN                                         FullCapsuleBufferSize;
    300   EFI_CAPSULE_HEADER                            *NestedCapsuleHeader;
    301   EFI_GUID                                      *ImageTypeId;
    302   UINT32                                        FwType;
    303   EFI_STATUS                                    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;
    304314
    305315  if (Argc != 5) {
    306     Print(L"CapsuleApp: Incorrect parameter count.\n");
     316    Print (L"CapsuleApp: Incorrect parameter count.\n");
    307317    return EFI_UNSUPPORTED;
    308318  }
    309319
    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");
    312322    return EFI_UNSUPPORTED;
    313323  }
     324
    314325  OutputCapsuleName = Argv[4];
    315326
    316   CapsuleBuffer = NULL;
    317   FileSize = 0;
     327  CapsuleBuffer     = NULL;
     328  FileSize          = 0;
    318329  FullCapsuleBuffer = NULL;
    319330
    320331  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
    326338  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);
    328340    Status = EFI_INVALID_PARAMETER;
    329341    goto Done;
    330342  }
    331343
    332   if (!IsFmpCapsuleGuid (&((EFI_CAPSULE_HEADER *) CapsuleBuffer)->CapsuleGuid)) {
    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);
    334346    Status = EFI_INVALID_PARAMETER;
    335347    goto Done;
    336348  }
    337349
    338   ImageTypeId = GetCapsuleImageTypeId(CapsuleBuffer);
     350  ImageTypeId = GetCapsuleImageTypeId (CapsuleBuffer);
    339351  if (ImageTypeId == NULL) {
    340     Print(L"CapsuleApp: Capsule ImageTypeId is not found.\n");
     352    Print (L"CapsuleApp: Capsule ImageTypeId is not found.\n");
    341353    Status = EFI_INVALID_PARAMETER;
    342354    goto Done;
    343355  }
    344   FwType = GetEsrtFwType(ImageTypeId);
     356
     357  FwType = GetEsrtFwType (ImageTypeId);
    345358  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");
    347360    Status = EFI_INVALID_PARAMETER;
    348361    goto Done;
     
    350363
    351364  FullCapsuleBufferSize = NESTED_CAPSULE_HEADER_SIZE + FileSize;
    352   FullCapsuleBuffer = AllocatePool(FullCapsuleBufferSize);
     365  FullCapsuleBuffer     = AllocatePool (FullCapsuleBufferSize);
    353366  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);
    355368    Status = EFI_OUT_OF_RESOURCES;
    356369    goto Done;
     
    358371
    359372  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;
    364377  NestedCapsuleHeader->CapsuleImageSize = (UINT32)FullCapsuleBufferSize;
    365378
    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);
    370383
    371384Done:
    372385  if (CapsuleBuffer != NULL) {
    373     FreePool(CapsuleBuffer);
     386    FreePool (CapsuleBuffer);
    374387  }
    375388
    376389  if (FullCapsuleBuffer != NULL) {
    377     FreePool(FullCapsuleBuffer);
     390    FreePool (FullCapsuleBuffer);
    378391  }
    379392
    380393  return Status;
    381394}
    382 
    383395
    384396/**
     
    392404  )
    393405{
    394   EFI_STATUS                          Status;
    395   UINT32                              Index;
    396   CHAR16                              CapsuleVarName[20];
    397   CHAR16                              *TempVarName;
    398   BOOLEAN                             Found;
    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");
    401413  TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
    402   Index = 0;
     414  Index       = 0;
    403415
    404416  Found = FALSE;
    405417  while (TRUE) {
    406     UnicodeSPrint (TempVarName, 5 * sizeof(CHAR16), L"%04x", Index);
     418    UnicodeSPrint (TempVarName, 5 * sizeof (CHAR16), L"%04x", Index);
    407419
    408420    Status = gRT->SetVariable (
     
    419431      break;
    420432    }
     433
    421434    Found = TRUE;
    422435
     
    448461EFI_STATUS
    449462BuildGatherList (
    450   IN VOID                          **CapsuleBuffer,
    451   IN UINTN                         *FileSize,
    452   IN UINTN                         CapsuleNum,
    453   OUT EFI_CAPSULE_BLOCK_DESCRIPTOR **BlockDescriptors
     463  IN VOID                           **CapsuleBuffer,
     464  IN UINTN                          *FileSize,
     465  IN UINTN                          CapsuleNum,
     466  OUT EFI_CAPSULE_BLOCK_DESCRIPTOR  **BlockDescriptors
    454467  )
    455468{
     
    483496    }
    484497
    485     Size               = Count * sizeof (EFI_CAPSULE_BLOCK_DESCRIPTOR);
    486     BlockDescriptors1  = AllocateRuntimeZeroPool (Size);
     498    Size              = Count * sizeof (EFI_CAPSULE_BLOCK_DESCRIPTOR);
     499    BlockDescriptors1 = AllocateRuntimeZeroPool (Size);
    487500    if (BlockDescriptors1 == NULL) {
    488501      Print (L"CapsuleApp: failed to allocate memory for descriptors\n");
     
    490503      goto ERREXIT;
    491504    } else {
    492       Print (L"CapsuleApp: creating capsule descriptors at 0x%X\n", (UINTN) BlockDescriptors1);
    493       Print (L"CapsuleApp: capsule data starts          at 0x%X with size 0x%X\n", (UINTN) CapsuleBuffer[Index], FileSize[Index]);
     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]);
    494507    }
    495508
     
    502515
    503516    if (BlockDescriptorPre != NULL) {
    504       BlockDescriptorPre->Union.ContinuationPointer = (UINTN) BlockDescriptors1;
    505       BlockDescriptorPre->Length = 0;
     517      BlockDescriptorPre->Union.ContinuationPointer = (UINTN)BlockDescriptors1;
     518      BlockDescriptorPre->Length                    = 0;
    506519    }
    507520
     
    509522    // Fill them in
    510523    //
    511     TempBlockPtr  = BlockDescriptors1;
    512     TempDataPtr   = CapsuleBuffer[Index];
    513     SizeLeft      = FileSize[Index];
     524    TempBlockPtr = BlockDescriptors1;
     525    TempDataPtr  = CapsuleBuffer[Index];
     526    SizeLeft     = FileSize[Index];
    514527    for (Number = 0; (Number < Count - 1) && (SizeLeft != 0); Number++) {
    515528      //
     
    525538        Size = SizeLeft;
    526539      }
    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;
    531545      TempDataPtr += Size;
    532546      TempBlockPtr++;
     
    556570      // Point the first list's last element to point to this second list.
    557571      //
    558       TempBlockPtr->Union.ContinuationPointer   = (UINTN) BlockDescriptors2;
    559 
    560       TempBlockPtr->Length  = 0;
    561       TempBlockPtr = BlockDescriptors2;
     572      TempBlockPtr->Union.ContinuationPointer = (UINTN)BlockDescriptors2;
     573
     574      TempBlockPtr->Length = 0;
     575      TempBlockPtr         = BlockDescriptors2;
    562576      for (Number = 0; Number < Count - 1; Number++) {
    563577        //
     
    577591        }
    578592
    579         TempBlockPtr->Union.DataBlock    = (UINTN)TempDataPtr;
    580         TempBlockPtr->Length  = Size;
    581         Print (L"CapsuleApp: capsule block/size              0x%X/0x%X\n", (UINTN) TempDataPtr, Size);
    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;
    583597        TempDataPtr += Size;
    584598        TempBlockPtr++;
     
    597611  //
    598612  if (TempBlockPtr != NULL) {
    599     TempBlockPtr->Union.ContinuationPointer    = (UINTN)NULL;
    600     TempBlockPtr->Length  = 0;
    601     *BlockDescriptors = BlockDescriptorsHeader;
     613    TempBlockPtr->Union.ContinuationPointer = (UINTN)NULL;
     614    TempBlockPtr->Length                    = 0;
     615    *BlockDescriptors                       = BlockDescriptorsHeader;
    602616  }
    603617
     
    606620ERREXIT:
    607621  if (BlockDescriptors1 != NULL) {
    608     FreePool(BlockDescriptors1);
     622    FreePool (BlockDescriptors1);
    609623  }
    610624
    611625  if (BlockDescriptors2 != NULL) {
    612     FreePool(BlockDescriptors2);
     626    FreePool (BlockDescriptors2);
    613627  }
    614628
     
    624638VOID
    625639CleanGatherList (
    626   IN EFI_CAPSULE_BLOCK_DESCRIPTOR   *BlockDescriptors,
    627   IN UINTN                          CapsuleNum
     640  IN EFI_CAPSULE_BLOCK_DESCRIPTOR  *BlockDescriptors,
     641  IN UINTN                         CapsuleNum
    628642  )
    629643{
    630   EFI_CAPSULE_BLOCK_DESCRIPTOR   *TempBlockPtr;
    631   EFI_CAPSULE_BLOCK_DESCRIPTOR   *TempBlockPtr1;
    632   EFI_CAPSULE_BLOCK_DESCRIPTOR   *TempBlockPtr2;
    633   UINTN                          Index;
     644  EFI_CAPSULE_BLOCK_DESCRIPTOR  *TempBlockPtr;
     645  EFI_CAPSULE_BLOCK_DESCRIPTOR  *TempBlockPtr1;
     646  EFI_CAPSULE_BLOCK_DESCRIPTOR  *TempBlockPtr2;
     647  UINTN                         Index;
    634648
    635649  if (BlockDescriptors != NULL) {
    636650    TempBlockPtr1 = BlockDescriptors;
    637     while (1){
     651    while (1) {
    638652      TempBlockPtr = TempBlockPtr1;
    639653      for (Index = 0; Index < CapsuleNum; Index++) {
     
    647661      }
    648662
    649       TempBlockPtr2 = (VOID *) ((UINTN) TempBlockPtr[Index].Union.ContinuationPointer);
    650       FreePool(TempBlockPtr1);
     663      TempBlockPtr2 = (VOID *)((UINTN)TempBlockPtr[Index].Union.ContinuationPointer);
     664      FreePool (TempBlockPtr1);
    651665      TempBlockPtr1 = TempBlockPtr2;
    652666    }
     
    662676  )
    663677{
    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");
    700714}
    701715
     
    739753  UINTN                         ImageIndex;
    740754
    741   BlockDescriptors  = NULL;
    742   MapFsStr          = NULL;
    743   CapsuleNum        = 0;
    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);
    748762    return Status;
    749763  }
     764
    750765  if (Argc < 2) {
    751     PrintUsage();
     766    PrintUsage ();
    752767    return EFI_UNSUPPORTED;
    753768  }
    754   if (StrCmp(Argv[1], L"-D") == 0) {
     769
     770  if (StrCmp (Argv[1], L"-D") == 0) {
    755771    if (Argc != 3) {
    756       Print(L"CapsuleApp: Incorrect parameter count.\n");
     772      Print (L"CapsuleApp: Incorrect parameter count.\n");
    757773      return EFI_UNSUPPORTED;
    758774    }
    759     Status = DumpCapsule(Argv[2]);
     775
     776    Status = DumpCapsule (Argv[2]);
    760777    return Status;
    761778  }
    762   if (StrCmp(Argv[1], L"-G") == 0) {
    763     Status = CreateBmpFmp();
     779
     780  if (StrCmp (Argv[1], L"-G") == 0) {
     781    Status = CreateBmpFmp ();
    764782    return Status;
    765783  }
    766   if (StrCmp(Argv[1], L"-N") == 0) {
    767     Status = CreateNestedFmp();
     784
     785  if (StrCmp (Argv[1], L"-N") == 0) {
     786    Status = CreateNestedFmp ();
    768787    return Status;
    769788  }
    770   if (StrCmp(Argv[1], L"-S") == 0) {
    771     Status = DumpCapsuleStatusVariable();
     789
     790  if (StrCmp (Argv[1], L"-S") == 0) {
     791    Status = DumpCapsuleStatusVariable ();
    772792    return EFI_SUCCESS;
    773793  }
    774   if (StrCmp(Argv[1], L"-C") == 0) {
    775     Status = ClearCapsuleStatusVariable();
     794
     795  if (StrCmp (Argv[1], L"-C") == 0) {
     796    Status = ClearCapsuleStatusVariable ();
    776797    return Status;
    777798  }
    778   if (StrCmp(Argv[1], L"-P") == 0) {
     799
     800  if (StrCmp (Argv[1], L"-P") == 0) {
    779801    if (Argc == 2) {
    780       DumpFmpData();
    781     }
     802      DumpFmpData ();
     803    }
     804
    782805    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]);
    785808        return EFI_UNSUPPORTED;
    786809      } else {
    787810        if (Argc != 7) {
    788           Print(L"CapsuleApp: Incorrect parameter count.\n");
     811          Print (L"CapsuleApp: Incorrect parameter count.\n");
    789812          return EFI_UNSUPPORTED;
    790813        }
     
    798821          return EFI_INVALID_PARAMETER;
    799822        }
    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");
    803827          return EFI_UNSUPPORTED;
    804828        }
    805         DumpFmpImage(&ImageTypeId, ImageIndex, Argv[6]);
     829
     830        DumpFmpImage (&ImageTypeId, ImageIndex, Argv[6]);
    806831      }
    807832    }
     833
    808834    return EFI_SUCCESS;
    809835  }
    810836
    811   if (StrCmp(Argv[1], L"-E") == 0) {
    812     DumpEsrtData();
     837  if (StrCmp (Argv[1], L"-E") == 0) {
     838    DumpEsrtData ();
    813839    return EFI_SUCCESS;
    814840  }
    815841
    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);
    819845    } else {
    820       DumpProvisionedCapsule(FALSE);
    821     }
     846      DumpProvisionedCapsule (FALSE);
     847    }
     848
    822849    return EFI_SUCCESS;
    823850  }
    824851
    825   if (StrCmp(Argv[1], L"-F") == 0) {
    826     DumpAllEfiSysPartition();
     852  if (StrCmp (Argv[1], L"-F") == 0) {
     853    DumpAllEfiSysPartition ();
    827854    return EFI_SUCCESS;
    828855  }
    829856
    830857  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]);
    832859    return EFI_UNSUPPORTED;
    833860  }
    834861
    835862  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;
    840867
    841868  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;
    844871      CapsuleOnDisk = TRUE;
    845     } else if (StrCmp(Argv[Index], L"-NR") == 0) {
     872    } else if (StrCmp (Argv[Index], L"-NR") == 0) {
    846873      ParaNrIndex = Index;
    847       NoReset = TRUE;
     874      NoReset     = TRUE;
    848875    }
    849876  }
     
    887914
    888915  if (CapsuleFirstIndex > CapsuleLastIndex) {
    889     Print(L"CapsuleApp: NO capsule image.\n");
     916    Print (L"CapsuleApp: NO capsule image.\n");
    890917    return EFI_UNSUPPORTED;
    891918  }
     919
    892920  if (CapsuleNum > MAX_CAPSULE_NUM) {
    893     Print(L"CapsuleApp: Too many capsule images.\n");
     921    Print (L"CapsuleApp: Too many capsule images.\n");
    894922    return EFI_UNSUPPORTED;
    895923  }
    896924
    897   ZeroMem(&CapsuleBuffer, sizeof(CapsuleBuffer));
    898   ZeroMem(&CapsuleBufferSize, sizeof(CapsuleBufferSize));
     925  ZeroMem (&CapsuleBuffer, sizeof (CapsuleBuffer));
     926  ZeroMem (&CapsuleBufferSize, sizeof (CapsuleBufferSize));
    899927  BlockDescriptors = NULL;
    900928
    901929  for (Index = 0; Index < CapsuleNum; Index++) {
    902930    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);
    906934      goto Done;
    907935    }
     936
    908937    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);
    910939      return EFI_INVALID_PARAMETER;
    911940    }
     941
    912942    CapsuleNames[Index] = CapsuleName;
    913943  }
     
    916946  // Every capsule use 2 descriptor 1 for data 1 for end
    917947  //
    918   Status = BuildGatherList(CapsuleBuffer, CapsuleBufferSize, CapsuleNum, &BlockDescriptors);
    919   if (EFI_ERROR(Status)) {
     948  Status = BuildGatherList (CapsuleBuffer, CapsuleBufferSize, CapsuleNum, &BlockDescriptors);
     949  if (EFI_ERROR (Status)) {
    920950    goto Done;
    921951  }
     
    926956  NeedReset = FALSE;
    927957  for (Index = 0; Index < CapsuleNum; Index++) {
    928     CapsuleHeaderArray[Index] = (EFI_CAPSULE_HEADER *) CapsuleBuffer[Index];
     958    CapsuleHeaderArray[Index] = (EFI_CAPSULE_HEADER *)CapsuleBuffer[Index];
    929959    if ((CapsuleHeaderArray[Index]->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) {
    930960      NeedReset = TRUE;
    931961    }
    932962  }
     963
    933964  CapsuleHeaderArray[CapsuleNum] = NULL;
    934965
     
    937968  //
    938969  Status = gRT->QueryCapsuleCapabilities (CapsuleHeaderArray, CapsuleNum, &MaxCapsuleSize, &ResetType);
    939   if (EFI_ERROR(Status)) {
     970  if (EFI_ERROR (Status)) {
    940971    Print (L"CapsuleApp: failed to query capsule capability - %r\n", Status);
    941972    goto Done;
     
    9711002  //
    9721003  if (NeedReset) {
    973     Status = gRT->UpdateCapsule(CapsuleHeaderArray,CapsuleNum,(UINTN) BlockDescriptors);
     1004    Status = gRT->UpdateCapsule (CapsuleHeaderArray, CapsuleNum, (UINTN)BlockDescriptors);
    9741005    if (Status != EFI_SUCCESS) {
    9751006      Print (L"CapsuleApp: failed to update capsule - %r\n", Status);
    9761007      goto Done;
    9771008    }
     1009
    9781010    //
    9791011    // For capsule with CAPSULE_FLAGS_PERSIST_ACROSS_RESET + CAPSULE_FLAGS_INITIATE_RESET,
     
    9951027    // system reset. The service will process the capsule immediately.
    9961028    //
    997     Status = gRT->UpdateCapsule (CapsuleHeaderArray,CapsuleNum,(UINTN) BlockDescriptors);
     1029    Status = gRT->UpdateCapsule (CapsuleHeaderArray, CapsuleNum, (UINTN)BlockDescriptors);
    9981030    if (Status != EFI_SUCCESS) {
    9991031      Print (L"CapsuleApp: failed to update capsule - %r\n", Status);
     
    10101042  }
    10111043
    1012   CleanGatherList(BlockDescriptors, CapsuleNum);
     1044  CleanGatherList (BlockDescriptors, CapsuleNum);
    10131045
    10141046  return Status;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette