From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: chao.b.zhang@intel.com) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by groups.io with SMTP; Mon, 27 May 2019 17:34:59 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 May 2019 17:34:58 -0700 X-ExtLoop1: 1 Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga001.jf.intel.com with ESMTP; 27 May 2019 17:34:58 -0700 Received: from shsmsx107.ccr.corp.intel.com (10.239.4.96) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 27 May 2019 17:34:58 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.249]) by SHSMSX107.ccr.corp.intel.com ([169.254.9.7]) with mapi id 14.03.0415.000; Tue, 28 May 2019 08:34:54 +0800 From: "Zhang, Chao B" To: "devel@edk2.groups.io" , "Xu, Wei6" CC: "Wang, Jian J" , "Wu, Hao A" Subject: Re: [edk2-devel][Patch] MdeModulePkg/CapsuleApp: Enhance Capsule-On-Disk related functions. Thread-Topic: [edk2-devel][Patch] MdeModulePkg/CapsuleApp: Enhance Capsule-On-Disk related functions. Thread-Index: AQHVEg9tO7JYGxd7Mk2KegtoIW4sq6Z/tOYw Date: Tue, 28 May 2019 00:34:54 +0000 Message-ID: References: <20190524090207.19728-1-wei6.xu@intel.com> In-Reply-To: <20190524090207.19728-1-wei6.xu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNGNjZmRhMWYtNWNhMS00NTBhLThhNDAtMzJmNjVhZWI5MGNlIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiaW9zaGlKb3hpODNzZEFnMEE5cURPTlwvV2VWbkhUa1ZRWFwvQ2tCall0ZFRIV2pydnBiaDZYUmgydTRBZm5pVFVkIn0= dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: chao.b.zhang@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Chao Zhang -----Original Message----- From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Xu, = Wei6 Sent: Friday, May 24, 2019 5:02 PM To: devel@edk2.groups.io Cc: Wang, Jian J ; Wu, Hao A ; = Zhang, Chao B ; Xu, Wei6 Subject: [edk2-devel][Patch] MdeModulePkg/CapsuleApp: Enhance Capsule-On-D= isk related functions. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1840 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 'CapsuleAp= p -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 e= rror message and quit the process. Cc: Jian J Wang Cc: Hao A Wu Cc: Chao B Zhang Signed-off-by: Wei6 Xu --- MdeModulePkg/Application/CapsuleApp/CapsuleApp.c | 41 ++++++++-------- MdeModulePkg/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/MdeModuleP= kg/Application/CapsuleApp/CapsuleApp.c index e3c591dbf3..0b5f7c8684 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c @@ -847,11 +847,11 @@ 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 CAPS= ULE_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=20 + 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"); Print(L" which is defined in UEFI specification.\n"); Print(L" -P: Dump UEFI FMP protocol info, or get image with specified= \n"); @@ -1018,44 +1018,43 @@ UefiMain ( ParaNrIndex =3D Index; NoReset =3D TRUE; } } =20 - if (ParaOdIndex !=3D 0) { - if (ParaOdIndex =3D=3D Argc - 1) { + if (ParaOdIndex > ParaNrIndex) { + if (ParaNrIndex !=3D 0) { + CapsuleLastIndex =3D ParaNrIndex - 1; + } else { + CapsuleLastIndex =3D ParaOdIndex - 1; + } + + if (ParaOdIndex =3D=3D Argc -1) { MapFsStr =3D NULL; } else if (ParaOdIndex =3D=3D Argc - 2) { MapFsStr =3D Argv[Argc-1]; } else { - Print (L"CapsuleApp: Invalid Position for -OD Options\n"); + Print (L"CapsuleApp: Cannot specify more than one FS=20 + mapping!\n"); Status =3D EFI_INVALID_PARAMETER; goto Done; } - - if (ParaNrIndex !=3D 0) { - if (ParaNrIndex + 1 =3D=3D ParaOdIndex) { - CapsuleLastIndex =3D ParaNrIndex - 1; - } else { - Print (L"CapsuleApp: Invalid Position for -NR Options\n"); - Status =3D EFI_INVALID_PARAMETER; - goto Done; - } - } else { + } else if (ParaOdIndex < ParaNrIndex) { + if (ParaOdIndex !=3D 0) { CapsuleLastIndex =3D ParaOdIndex - 1; - } - } else { - if (ParaNrIndex !=3D 0) { - if (ParaNrIndex =3D=3D Argc -1) { - CapsuleLastIndex =3D ParaNrIndex - 1; + if (ParaOdIndex =3D=3D ParaNrIndex - 1) { + MapFsStr =3D NULL; + } else if (ParaOdIndex =3D=3D ParaNrIndex - 2) { + MapFsStr =3D Argv[ParaOdIndex + 1]; } else { - Print (L"CapsuleApp: Invalid Position for -NR Options\n"); + Print (L"CapsuleApp: Cannot specify more than one FS=20 + mapping!\n"); Status =3D EFI_INVALID_PARAMETER; goto Done; } } else { - CapsuleLastIndex =3D Argc - 1; + CapsuleLastIndex =3D ParaNrIndex - 1; } + } else { + CapsuleLastIndex =3D Argc - 1; } =20 CapsuleNum =3D CapsuleLastIndex - CapsuleFirstIndex + 1; =20 if (CapsuleFirstIndex > CapsuleLastIndex) { diff --git a/MdeModulePkg/A= pplication/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/C= apsuleDump.c index b81c5b7b3a..0e0c566702 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c @@ -810,12 +810,12 @@ DumpCapsuleFromDisk ( } =20 // // Get file count first // + Status =3D FileHandleFindFirstFile (DirHandle, &FileInfo); do { - Status =3D FileHandleFindFirstFile (DirHandle, &FileInfo); if (EFI_ERROR (Status) || FileInfo =3D=3D NULL) { Print (L"Get File Info Fail. Status =3D %r\n", Status); goto Done; } =20 @@ -844,12 +844,12 @@ DumpCapsuleFromDisk ( NoFile =3D FALSE; =20 // // Get all file info // + Status =3D FileHandleFindFirstFile (DirHandle, &FileInfo); do { - Status =3D FileHandleFindFirstFile (DirHandle, &FileInfo); if (EFI_ERROR (Status) || FileInfo =3D=3D NULL) { Print (L"Get File Info Fail. Status =3D %r\n", Status); goto Done; } =20 diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c b/MdeModu= lePkg/Application/CapsuleApp/CapsuleOnDisk.c index a11683d66c..df43a436f2 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c @@ -21,10 +21,12 @@ #include #include #include #include =20 +#define MAX_CAPSULE_NUM 10 + EFI_GUID mCapsuleOnDiskBootOptionGuid =3D { 0x4CC29BB7, 0x2413, 0x40A2, {= 0xB0, 0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } }; =20 /** Get shell protocol. =20 @@ -742,10 +744,45 @@ SetCapsuleStatusVariable ( ); =20 return Status; } =20 +/** + 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 =3D sizeof(UINT64); + Status =3D gRT->GetVariable ( + L"OsIndicationsSupported", + &gEfiGlobalVariableGuid, + NULL, + &DataSize, + &OsIndicationsSupported + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + if (OsIndicationsSupported & EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_S= UPPORTED) { + return TRUE; + } + + return FALSE; +} + /** Process Capsule On Disk. =20 @param[in] CapsuleBuffer An array of pointer to capsule images @param[in] CapsuleBufferSize An array of UINTN to capsule images siz= e @@ -768,10 +805,20 @@ ProcessCapsuleOnDisk ( { EFI_STATUS Status; 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=20 + (!IsCapsuleOnDiskSupported ()) { + Print (L"CapsuleApp: Capsule On Disk is not supported.\n"); + return EFI_UNSUPPORTED; + } =20 // // Get a valid file system from boot path // Fs =3D NULL; @@ -780,14 +827,21 @@ ProcessCapsuleOnDisk ( if (EFI_ERROR (Status)) { Print (L"CapsuleApp: cannot find a valid file system on boot devies. = Status =3D %r\n", Status); return Status; } =20 + // + // Get file name from file path + // + for (Index =3D 0; Index < CapsuleNum; Index ++) { + FileName[Index] =3D GetFileNameFromPath (FilePath[Index]); } + // // Copy capsule image to '\efi\UpdateCapsule\' // - Status =3D WriteUpdateFile (CapsuleBuffer, CapsuleBufferSize, FilePath,= CapsuleNum, Fs); + Status =3D WriteUpdateFile (CapsuleBuffer, CapsuleBufferSize, FileName,= = =20 + CapsuleNum, Fs); if (EFI_ERROR (Status)) { Print (L"CapsuleApp: capsule image could not be copied for update.\n"= ); return Status; } =20 -- 2.16.2.windows.1