X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FApplication%2FCapsuleApp%2FCapsuleApp.c;h=4d907242f38b55d441fdad8dacc34dc454f83446;hb=131818ba5a83d1e8f3f1b4c041200755fff64abb;hp=df5de91ef524bb4dca0cd17e9f8f863ff2a3c6ef;hpb=10944bc390f52fcd418670fe0171da1d4f3b05cc;p=mirror_edk2.git diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c index df5de91ef5..4d907242f3 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -70,7 +69,7 @@ DumpCapsule ( @retval EFI_UNSUPPORTED Input parameter is not valid. **/ EFI_STATUS -DmpCapsuleStatusVariable ( +DumpCapsuleStatusVariable ( VOID ); @@ -362,6 +361,60 @@ GetEsrtFwType ( return ESRT_FW_TYPE_UNKNOWN; } +/** + Validate if it is valid capsule header + + This function assumes the caller provided correct CapsuleHeader pointer + and CapsuleSize. + + This function validates the fields in EFI_CAPSULE_HEADER. + + @param[in] CapsuleHeader Points to a capsule header. + @param[in] CapsuleSize Size of the whole capsule image. + +**/ +BOOLEAN +IsValidCapsuleHeader ( + IN EFI_CAPSULE_HEADER *CapsuleHeader, + IN UINT64 CapsuleSize + ) +{ + if (CapsuleSize < sizeof (EFI_CAPSULE_HEADER)) { + return FALSE; + } + if (CapsuleHeader->CapsuleImageSize != CapsuleSize) { + return FALSE; + } + if (CapsuleHeader->HeaderSize > CapsuleHeader->CapsuleImageSize) { + return FALSE; + } + if (CapsuleHeader->HeaderSize < sizeof (EFI_CAPSULE_HEADER)) { + return FALSE; + } + + return TRUE; +} + +/** + Return if this CapsuleGuid is a FMP capsule GUID or not. + + @param[in] CapsuleGuid A pointer to EFI_GUID + + @retval TRUE It is a FMP capsule GUID. + @retval FALSE It is not a FMP capsule GUID. +**/ +BOOLEAN +IsFmpCapsuleGuid ( + IN EFI_GUID *CapsuleGuid + ) +{ + if (CompareGuid(&gEfiFmpCapsuleGuid, CapsuleGuid)) { + return TRUE; + } + + return FALSE; +} + /** Append a capsule header on top of current image. This function follows Windows UEFI Firmware Update Platform document. @@ -407,15 +460,28 @@ CreateNestedFmp ( Print(L"CapsuleApp: Capsule image (%s) is not found.\n", CapsuleName); goto Done; } + if (!IsValidCapsuleHeader (CapsuleBuffer, FileSize)) { + Print(L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName); + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + if (!IsFmpCapsuleGuid (&((EFI_CAPSULE_HEADER *) CapsuleBuffer)->CapsuleGuid)) { + Print(L"CapsuleApp: Capsule image (%s) is not a FMP capsule.\n", CapsuleName); + Status = EFI_INVALID_PARAMETER; + goto Done; + } ImageTypeId = GetCapsuleImageTypeId(CapsuleBuffer); if (ImageTypeId == NULL) { Print(L"CapsuleApp: Capsule ImageTypeId is not found.\n"); + Status = EFI_INVALID_PARAMETER; goto Done; } FwType = GetEsrtFwType(ImageTypeId); if ((FwType != ESRT_FW_TYPE_SYSTEMFIRMWARE) && (FwType != ESRT_FW_TYPE_DEVICEFIRMWARE)) { Print(L"CapsuleApp: Capsule FwType is invalid.\n"); + Status = EFI_INVALID_PARAMETER; goto Done; } @@ -466,11 +532,13 @@ ClearCapsuleStatusVariable ( UINT32 Index; CHAR16 CapsuleVarName[20]; CHAR16 *TempVarName; + BOOLEAN Found; StrCpyS (CapsuleVarName, sizeof(CapsuleVarName)/sizeof(CapsuleVarName[0]), L"Capsule"); TempVarName = CapsuleVarName + StrLen (CapsuleVarName); Index = 0; + Found = FALSE; while (TRUE) { UnicodeSPrint (TempVarName, 5 * sizeof(CHAR16), L"%04x", Index); @@ -481,12 +549,15 @@ ClearCapsuleStatusVariable ( 0, (VOID *)NULL ); - if (EFI_ERROR(Status)) { + if (Status == EFI_NOT_FOUND) { // - // There is no capsule variables, quit + // There is no more capsule variables, quit // break; } + Found = TRUE; + + Print (L"Clear %s %r\n", CapsuleVarName, Status); Index++; if (Index > 0xFFFF) { @@ -494,6 +565,10 @@ ClearCapsuleStatusVariable ( } } + if (!Found) { + Print (L"No any Capsule#### variable found\n"); + } + return EFI_SUCCESS; } @@ -715,40 +790,6 @@ CleanGatherList ( } } -/** - Validate if it is valid capsule header - - This function assumes the caller provided correct CapsuleHeader pointer - and CapsuleSize. - - This function validates the fields in EFI_CAPSULE_HEADER. - - @param[in] CapsuleHeader Points to a capsule header. - @param[in] CapsuleSize Size of the whole capsule image. - -**/ -BOOLEAN -IsValidCapsuleHeader ( - IN EFI_CAPSULE_HEADER *CapsuleHeader, - IN UINT64 CapsuleSize - ) -{ - if (CapsuleSize < sizeof (EFI_CAPSULE_HEADER)) { - return FALSE; - } - if (CapsuleHeader->CapsuleImageSize != CapsuleSize) { - return FALSE; - } - if (CapsuleHeader->HeaderSize > CapsuleHeader->CapsuleImageSize) { - return FALSE; - } - if (CapsuleHeader->HeaderSize < sizeof (EFI_CAPSULE_HEADER)) { - return FALSE; - } - - return TRUE; -} - /** Print APP usage. **/ @@ -768,22 +809,26 @@ PrintUsage ( Print(L" CapsuleApp -D \n"); Print(L" CapsuleApp -P GET -O \n"); Print(L"Parameter:\n"); - Print(L" -NR: No reset will be triggered for the capsule\n"); - Print(L" with CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without CAPSULE_FLAGS_INITIATE_RESET.\n"); + Print(L" -NR: No reset will be triggered for the capsule with\n"); + Print(L" CAPSULE_FLAGS_PERSIST_ACROSS_RESET and without\n"); + Print(L" CAPSULE_FLAGS_INITIATE_RESET.\n"); Print(L" -S: Dump capsule report variable (EFI_CAPSULE_REPORT_GUID),\n"); Print(L" which is defined in UEFI specification.\n"); Print(L" -C: Clear capsule report variable (EFI_CAPSULE_REPORT_GUID),\n"); Print(L" which is defined in UEFI specification.\n"); Print(L" -P: Dump UEFI FMP protocol info, or get image with specified\n"); - Print(L" ImageTypeId and index to a file if 'GET' option is used.\n"); + Print(L" ImageTypeId and Index (decimal format) to a file if 'GET'\n"); + Print(L" option is used.\n"); Print(L" -E: Dump UEFI ESRT table info.\n"); Print(L" -G: Convert a BMP file to be an UX capsule,\n"); Print(L" according to Windows Firmware Update document\n"); - Print(L" -N: Append a Capsule Header to an existing capsule image,\n"); + Print(L" -N: Append a Capsule Header to an existing FMP capsule image\n"); + Print(L" with its ImageTypeId supported by the system,\n"); Print(L" according to Windows Firmware Update document\n"); Print(L" -O: Output new Capsule file name\n"); - Print(L" -D: Dump Capsule image header information, image payload information if it is an UX capsule\n"); - Print(L" and FMP header information if it is a FMP capsule.\n"); + Print(L" -D: Dump Capsule image header information, image payload\n"); + Print(L" information if it is an UX capsule and FMP header\n"); + Print(L" information if it is a FMP capsule.\n"); } /** @@ -809,14 +854,16 @@ UefiMain ( UINTN FileSize[MAX_CAPSULE_NUM]; VOID *CapsuleBuffer[MAX_CAPSULE_NUM]; EFI_CAPSULE_BLOCK_DESCRIPTOR *BlockDescriptors; - EFI_CAPSULE_HEADER *CapsuleHeaderArray[MAX_CAPSULE_NUM + 1]; - UINT64 MaxCapsuleSize; - EFI_RESET_TYPE ResetType; - BOOLEAN NeedReset; - BOOLEAN NoReset; - CHAR16 *CapsuleName; - UINTN CapsuleNum; - UINTN Index; + EFI_CAPSULE_HEADER *CapsuleHeaderArray[MAX_CAPSULE_NUM + 1]; + UINT64 MaxCapsuleSize; + EFI_RESET_TYPE ResetType; + BOOLEAN NeedReset; + BOOLEAN NoReset; + CHAR16 *CapsuleName; + UINTN CapsuleNum; + UINTN Index; + EFI_GUID ImageTypeId; + UINTN ImageIndex; Status = GetArg(); if (EFI_ERROR(Status)) { @@ -844,7 +891,7 @@ UefiMain ( return Status; } if (StrCmp(Argv[1], L"-S") == 0) { - Status = DmpCapsuleStatusVariable(); + Status = DumpCapsuleStatusVariable(); return EFI_SUCCESS; } if (StrCmp(Argv[1], L"-C") == 0) { @@ -865,8 +912,6 @@ UefiMain ( return EFI_UNSUPPORTED; } - EFI_GUID ImageTypeId; - UINTN ImageIndex; // // FMP->GetImage() //