From 6470a43160183cd48cad8901c912a48811f18b13 Mon Sep 17 00:00:00 2001 From: xuwei6 Date: Fri, 24 May 2019 16:52:35 +0800 Subject: [PATCH] MdeModulePkg/CapsuleApp: Enhance Capsule-On-Disk related functions. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1840 1. Add missing '\n' in usage. 2. Fix the dead loop of CapsuleApp -L. 3. Fix the bug that CapsuleApp -OD cannot perform capsules in sub- folder. 4. Optimize the handling for option -NR and -OD to support both 'CapsuleApp -OD -NR' and 'CapsuleApp -NR -OD'. 5. Check if Capsule-On-Disk is supported by "OsIndicationsSupported" variable firstly before processing capsules. If not supported, prompt an error message and quit the process. Cc: Jian J Wang Cc: Hao A Wu Cc: Chao B Zhang Signed-off-by: Wei6 Xu Reviewed-by: Chao B Zhang Acked-by: Hao A Wu --- .../Application/CapsuleApp/CapsuleApp.c | 41 +++++++------- .../Application/CapsuleApp/CapsuleDump.c | 4 +- .../Application/CapsuleApp/CapsuleOnDisk.c | 56 ++++++++++++++++++- 3 files changed, 77 insertions(+), 24 deletions(-) diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c index e3c591dbf3..0b5f7c8684 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c @@ -849,7 +849,7 @@ PrintUsage ( 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" -OD: Delivery of Capsules via file on Mass Storage device."); + Print(L" -OD: Delivery of Capsules via file on Mass Storage device.\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"); @@ -1020,40 +1020,39 @@ UefiMain ( } } - if (ParaOdIndex != 0) { - if (ParaOdIndex == Argc - 1) { + if (ParaOdIndex > ParaNrIndex) { + if (ParaNrIndex != 0) { + CapsuleLastIndex = ParaNrIndex - 1; + } else { + CapsuleLastIndex = ParaOdIndex - 1; + } + + if (ParaOdIndex == Argc -1) { MapFsStr = NULL; } else if (ParaOdIndex == Argc - 2) { MapFsStr = Argv[Argc-1]; } else { - Print (L"CapsuleApp: Invalid Position for -OD Options\n"); + Print (L"CapsuleApp: Cannot specify more than one FS mapping!\n"); Status = EFI_INVALID_PARAMETER; goto Done; } - - if (ParaNrIndex != 0) { - if (ParaNrIndex + 1 == ParaOdIndex) { - CapsuleLastIndex = ParaNrIndex - 1; - } else { - Print (L"CapsuleApp: Invalid Position for -NR Options\n"); - Status = EFI_INVALID_PARAMETER; - goto Done; - } - } else { + } else if (ParaOdIndex < ParaNrIndex) { + if (ParaOdIndex != 0) { CapsuleLastIndex = ParaOdIndex - 1; - } - } else { - if (ParaNrIndex != 0) { - if (ParaNrIndex == Argc -1) { - CapsuleLastIndex = ParaNrIndex - 1; + if (ParaOdIndex == ParaNrIndex - 1) { + MapFsStr = NULL; + } else if (ParaOdIndex == ParaNrIndex - 2) { + MapFsStr = Argv[ParaOdIndex + 1]; } else { - Print (L"CapsuleApp: Invalid Position for -NR Options\n"); + Print (L"CapsuleApp: Cannot specify more than one FS mapping!\n"); Status = EFI_INVALID_PARAMETER; goto Done; } } else { - CapsuleLastIndex = Argc - 1; + CapsuleLastIndex = ParaNrIndex - 1; } + } else { + CapsuleLastIndex = Argc - 1; } CapsuleNum = CapsuleLastIndex - CapsuleFirstIndex + 1; diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c index b81c5b7b3a..0e0c566702 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c @@ -812,8 +812,8 @@ DumpCapsuleFromDisk ( // // Get file count first // + Status = FileHandleFindFirstFile (DirHandle, &FileInfo); do { - Status = FileHandleFindFirstFile (DirHandle, &FileInfo); if (EFI_ERROR (Status) || FileInfo == NULL) { Print (L"Get File Info Fail. Status = %r\n", Status); goto Done; @@ -846,8 +846,8 @@ DumpCapsuleFromDisk ( // // Get all file info // + Status = FileHandleFindFirstFile (DirHandle, &FileInfo); do { - Status = FileHandleFindFirstFile (DirHandle, &FileInfo); if (EFI_ERROR (Status) || FileInfo == NULL) { Print (L"Get File Info Fail. Status = %r\n", Status); goto Done; diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c index a11683d66c..df43a436f2 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c @@ -23,6 +23,8 @@ #include #include +#define MAX_CAPSULE_NUM 10 + EFI_GUID mCapsuleOnDiskBootOptionGuid = { 0x4CC29BB7, 0x2413, 0x40A2, { 0xB0, 0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } }; /** @@ -744,6 +746,41 @@ SetCapsuleStatusVariable ( return Status; } +/** + Check if Capsule On Disk is supported. + + @retval TRUE Capsule On Disk is supported. + @retval FALSE Capsule On Disk is not supported. + +**/ +BOOLEAN +IsCapsuleOnDiskSupported ( + VOID + ) +{ + EFI_STATUS Status; + UINT64 OsIndicationsSupported; + UINTN DataSize; + + DataSize = sizeof(UINT64); + Status = gRT->GetVariable ( + L"OsIndicationsSupported", + &gEfiGlobalVariableGuid, + NULL, + &DataSize, + &OsIndicationsSupported + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + if (OsIndicationsSupported & EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED) { + return TRUE; + } + + return FALSE; +} + /** Process Capsule On Disk. @@ -770,6 +807,16 @@ ProcessCapsuleOnDisk ( UINT16 BootNext; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs; BOOLEAN UpdateBootNext; + CHAR16 *FileName[MAX_CAPSULE_NUM]; + UINTN Index; + + // + // Check if Capsule On Disk is supported + // + if (!IsCapsuleOnDiskSupported ()) { + Print (L"CapsuleApp: Capsule On Disk is not supported.\n"); + return EFI_UNSUPPORTED; + } // // Get a valid file system from boot path @@ -782,10 +829,17 @@ ProcessCapsuleOnDisk ( return Status; } + // + // Get file name from file path + // + for (Index = 0; Index < CapsuleNum; Index ++) { + FileName[Index] = GetFileNameFromPath (FilePath[Index]); + } + // // Copy capsule image to '\efi\UpdateCapsule\' // - Status = WriteUpdateFile (CapsuleBuffer, CapsuleBufferSize, FilePath, CapsuleNum, Fs); + Status = WriteUpdateFile (CapsuleBuffer, CapsuleBufferSize, FileName, CapsuleNum, Fs); if (EFI_ERROR (Status)) { Print (L"CapsuleApp: capsule image could not be copied for update.\n"); return Status; -- 2.39.2