From nobody Wed Nov 27 00:37:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+42778+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+42778+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1561445481; cv=none; d=zoho.com; s=zohoarc; b=jv/9nOiOQwf0WiG0uimwm1mHXMRCBYIwEMHvhDKry1CwYdzBUX3jj6UnzjsTBpDabZAviKuwuXLBHwyUaLweT8/xXVcSJvgcnmuKfMrz2eqBzw6fVZsBCQhfoVQE9OdM+cXy6xQS+YJN2M5PRmW1AJcIusELHPsb0gV1qc13E2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561445481; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=47LsmyR1DLB7Rk7ySdkIQoBhbTSHmf12ARBRBplhgAI=; b=NzzTqA8YvrpjCyisCJJPlojIvQepIRbQciwtxSLsXkotBQUUlLri1jVflVSHxRmaA/ihur7+Zz45SLVpdp52Cqq4dnHdyoxcS2CtdePBwYCyOXV9oJer5NsecyE8ysX95ihn5xrWJ7a3jYYhlW4T3qIuLkzfdsm91p/VdPOAMnM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+42778+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1561445481078129.00955204220224; Mon, 24 Jun 2019 23:51:21 -0700 (PDT) Return-Path: X-Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by groups.io with SMTP; Mon, 24 Jun 2019 23:51:20 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jun 2019 23:51:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,415,1557212400"; d="scan'208";a="336749107" X-Received: from shwdeopenpsi174.ccr.corp.intel.com ([10.239.157.39]) by orsmga005.jf.intel.com with ESMTP; 24 Jun 2019 23:51:17 -0700 From: "Xu, Wei6" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Chao B Zhang Subject: [edk2-devel][Patch] MdeModulePkg/CapsuleApp: Enhance Capsule-On-Disk related functions. Date: Tue, 25 Jun 2019 14:51:13 +0800 Message-Id: <20190625065113.12488-1-wei6.xu@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,wei6.xu@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1561445480; bh=cTOrIp9UewjEJhR2PeOfu8js806g6IgpZcD3/fLC02Y=; h=Cc:Date:From:Reply-To:Subject:To; b=iDA1EH6Pjl7968ItqrFo5bNa6FN3ad//SbWtvlzMZaNBabhijWAcJIQNiTfnEBqeGZC hPbLXdZUk6USOVaq3MftXt3foDPE/bP3i4/ri7CLXXGPU7Tt+TKxHdf2mAFCslpI6OabI dDMP+w27JivWLHUY014QauGrQ4RRD2O2bfk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1840 1. Introduce an internal header file to put definitions in it. 2. Add missing '\n' in usage. 3. Fix the dead loop of CapsuleApp -L. 4. Fix the bug that CapsuleApp -OD cannot perform capsules in sub- folder. 5. Optimize the handling for option -NR and -OD to support both 'CapsuleApp -OD -NR' and 'CapsuleApp -NR -OD'. 6. 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 Acked-by: Hao A Wu Reviewed-by : Chao Zhang --- MdeModulePkg/Application/CapsuleApp/AppSupport.c | 13 +- MdeModulePkg/Application/CapsuleApp/CapsuleApp.c | 215 ++---------------- MdeModulePkg/Application/CapsuleApp/CapsuleApp.h | 240 +++++++++++++++++= ++++ MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf | 3 +- MdeModulePkg/Application/CapsuleApp/CapsuleDump.c | 98 +-------- .../Application/CapsuleApp/CapsuleOnDisk.c | 86 +++++--- 6 files changed, 323 insertions(+), 332 deletions(-) create mode 100644 MdeModulePkg/Application/CapsuleApp/CapsuleApp.h diff --git a/MdeModulePkg/Application/CapsuleApp/AppSupport.c b/MdeModulePk= g/Application/CapsuleApp/AppSupport.c index d9ce1b4843..8fe70dc3b6 100644 --- a/MdeModulePkg/Application/CapsuleApp/AppSupport.c +++ b/MdeModulePkg/Application/CapsuleApp/AppSupport.c @@ -1,23 +1,14 @@ /** @file A shell application that triggers capsule update process. =20 - Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "CapsuleApp.h" =20 UINTN Argc; CHAR16 **Argv; EFI_SHELL_PROTOCOL *mShellProtocol =3D NULL; =20 diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePk= g/Application/CapsuleApp/CapsuleApp.c index e3c591dbf3..3439ce5feb 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c @@ -4,191 +4,19 @@ Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define CAPSULE_HEADER_SIZE 0x20 - -#define NESTED_CAPSULE_HEADER_SIZE SIZE_4KB -#define SYSTEM_FIRMWARE_FLAG 0x50000 -#define DEVICE_FIRMWARE_FLAG 0x78010 - -#define MAJOR_VERSION 1 -#define MINOR_VERSION 0 - -#define MAX_CAPSULE_NUM 10 - -extern UINTN Argc; -extern CHAR16 **Argv; +#include "CapsuleApp.h" =20 // // Define how many block descriptors we want to test with. // UINTN NumberOfDescriptors =3D 1; UINTN CapsuleFirstIndex; UINTN CapsuleLastIndex; =20 -/** - Dump capsule information - - @param[in] CapsuleName The name of the capsule image. - - @retval EFI_SUCCESS The capsule information is dumped. - @retval EFI_UNSUPPORTED Input parameter is not valid. -**/ -EFI_STATUS -DumpCapsule ( - IN CHAR16 *CapsuleName - ); - -/** - Dump capsule status variable. - - @retval EFI_SUCCESS The capsule status variable is dumped. - @retval EFI_UNSUPPORTED Input parameter is not valid. -**/ -EFI_STATUS -DumpCapsuleStatusVariable ( - VOID - ); - -/** - Dump FMP protocol info. -**/ -VOID -DumpFmpData ( - VOID - ); - -/** - Dump FMP image data. - - @param[in] ImageTypeId The ImageTypeId of the FMP image. - It is used to identify the FMP protocol. - @param[in] ImageIndex The ImageIndex of the FMP image. - It is the input parameter for FMP->GetImage(). - @param[in] ImageName The file name to hold the output FMP image. -**/ -VOID -DumpFmpImage ( - IN EFI_GUID *ImageTypeId, - IN UINTN ImageIndex, - IN CHAR16 *ImageName - ); - -/** - Dump ESRT info. -**/ -VOID -DumpEsrtData ( - VOID - ); - -/** - Dump Provisioned Capsule. - - @param[in] DumpCapsuleInfo The flag to indicate whether to dump the ca= psule inforomation. -**/ -VOID -DumpProvisionedCapsule ( - IN BOOLEAN DumpCapsuleInfo - ); - -/** - Dump all EFI System Partition. -**/ -VOID -DumpAllEfiSysPartition ( - VOID - ); - -/** - Process Capsule On Disk. - - @param[in] CapsuleBuffer An array of pointer to capsule images - @param[in] CapsuleBufferSize An array of UINTN to capsule images size - @param[in] FilePath An array of capsule images file path - @param[in] Map File system mapping string - @param[in] CapsuleNum The count of capsule images - - @retval EFI_SUCCESS Capsule on disk success. - @retval others Capsule on disk fail. - -**/ -EFI_STATUS -ProcessCapsuleOnDisk ( - IN VOID **CapsuleBuffer, - IN UINTN *CapsuleBufferSize, - IN CHAR16 **FilePath, - IN CHAR16 *Map, - IN UINTN CapsuleNum - ); - -/** - Read a file. - - @param[in] FileName The file to be read. - @param[out] BufferSize The file buffer size - @param[out] Buffer The file buffer - - @retval EFI_SUCCESS Read file successfully - @retval EFI_NOT_FOUND Shell protocol or file not found - @retval others Read file failed -**/ -EFI_STATUS -ReadFileToBuffer ( - IN CHAR16 *FileName, - OUT UINTN *BufferSize, - OUT VOID **Buffer - ); - -/** - Write a file. - - @param[in] FileName The file to be written. - @param[in] BufferSize The file buffer size - @param[in] Buffer The file buffer - - @retval EFI_SUCCESS Write file successfully - @retval EFI_NOT_FOUND Shell protocol not found - @retval others Write file failed -**/ -EFI_STATUS -WriteFileFromBuffer ( - IN CHAR16 *FileName, - IN UINTN BufferSize, - IN VOID *Buffer - ); - -/** - - This function parse application ARG. - - @return Status -**/ -EFI_STATUS -GetArg ( - VOID - ); - /** Create UX capsule. =20 @retval EFI_SUCCESS The capsule header is appended. @retval EFI_UNSUPPORTED Input parameter is not valid. @@ -847,11 +675,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 CAPSU= LE_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"); 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 +846,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 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 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/Application/CapsuleApp/CapsuleApp.h b/MdeModulePk= g/Application/CapsuleApp/CapsuleApp.h new file mode 100644 index 0000000000..270d2359a3 --- /dev/null +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.h @@ -0,0 +1,240 @@ +/** @file + A shell application that triggers capsule update process. + + Copyright (c) 2019, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + + +#ifndef _CAPSULE_APP_H_ +#define _CAPSULE_APP_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CAPSULE_HEADER_SIZE 0x20 + +#define NESTED_CAPSULE_HEADER_SIZE SIZE_4KB +#define SYSTEM_FIRMWARE_FLAG 0x50000 +#define DEVICE_FIRMWARE_FLAG 0x78010 + +#define MAJOR_VERSION 1 +#define MINOR_VERSION 0 + +#define MAX_CAPSULE_NUM 10 + +// +// (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for byt= es) +// +#define MAX_FILE_NAME_SIZE 522 +#define MAX_FILE_NAME_LEN (MAX_FILE_NAME_SIZE / sizeof(CHAR16)) + +extern UINTN Argc; +extern CHAR16 **Argv; + +/** + + This function parse application ARG. + + @return Status +**/ +EFI_STATUS +GetArg ( + VOID + ); + +/** + Get shell protocol. + + @return Pointer to shell protocol. + +**/ +EFI_SHELL_PROTOCOL * +GetShellProtocol ( + VOID + ); + + +/** + Read a file. + + @param[in] FileName The file to be read. + @param[out] BufferSize The file buffer size + @param[out] Buffer The file buffer + + @retval EFI_SUCCESS Read file successfully + @retval EFI_NOT_FOUND Shell protocol or file not found + @retval others Read file failed +**/ +EFI_STATUS +ReadFileToBuffer ( + IN CHAR16 *FileName, + OUT UINTN *BufferSize, + OUT VOID **Buffer + ); + +/** + Write a file. + + @param[in] FileName The file to be written. + @param[in] BufferSize The file buffer size + @param[in] Buffer The file buffer + + @retval EFI_SUCCESS Write file successfully + @retval EFI_NOT_FOUND Shell protocol not found + @retval others Write file failed +**/ +EFI_STATUS +WriteFileFromBuffer ( + IN CHAR16 *FileName, + IN UINTN BufferSize, + IN VOID *Buffer + ); + + +/** + Dump capsule information + + @param[in] CapsuleName The name of the capsule image. + + @retval EFI_SUCCESS The capsule information is dumped. + @retval EFI_UNSUPPORTED Input parameter is not valid. +**/ +EFI_STATUS +DumpCapsule ( + IN CHAR16 *CapsuleName + ); + +/** + Dump capsule status variable. + + @retval EFI_SUCCESS The capsule status variable is dumped. + @retval EFI_UNSUPPORTED Input parameter is not valid. +**/ +EFI_STATUS +DumpCapsuleStatusVariable ( + VOID + ); + +/** + Dump FMP protocol info. +**/ +VOID +DumpFmpData ( + VOID + ); + +/** + Dump FMP image data. + + @param[in] ImageTypeId The ImageTypeId of the FMP image. + It is used to identify the FMP protocol. + @param[in] ImageIndex The ImageIndex of the FMP image. + It is the input parameter for FMP->GetImage(). + @param[in] ImageName The file name to hold the output FMP image. +**/ +VOID +DumpFmpImage ( + IN EFI_GUID *ImageTypeId, + IN UINTN ImageIndex, + IN CHAR16 *ImageName + ); + +/** + Dump ESRT info. +**/ +VOID +DumpEsrtData ( + VOID + ); + +/** + Dump Provisioned Capsule. + + @param[in] DumpCapsuleInfo The flag to indicate whether to dump the ca= psule inforomation. +**/ +VOID +DumpProvisionedCapsule ( + IN BOOLEAN DumpCapsuleInfo + ); + +/** + Dump all EFI System Partition. +**/ +VOID +DumpAllEfiSysPartition ( + VOID + ); + + +/** + Get SimpleFileSystem from boot option file path. + + @param[in] DevicePath The file path of boot option + @param[out] FullPath The full device path of boot device + @param[out] Fs The file system within EfiSysPartition + + @retval EFI_SUCCESS Get file system successfully + @retval EFI_NOT_FOUND No valid file system found + @retval others Get file system failed + +**/ +EFI_STATUS +GetEfiSysPartitionFromBootOptionFilePath ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, + OUT EFI_DEVICE_PATH_PROTOCOL **FullPath, + OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **Fs + ); + + +/** + Process Capsule On Disk. + + @param[in] CapsuleBuffer An array of pointer to capsule images + @param[in] CapsuleBufferSize An array of UINTN to capsule images size + @param[in] FilePath An array of capsule images file path + @param[in] Map File system mapping string + @param[in] CapsuleNum The count of capsule images + + @retval EFI_SUCCESS Capsule on disk success. + @retval others Capsule on disk fail. + +**/ +EFI_STATUS +ProcessCapsuleOnDisk ( + IN VOID **CapsuleBuffer, + IN UINTN *CapsuleBufferSize, + IN CHAR16 **FilePath, + IN CHAR16 *Map, + IN UINTN CapsuleNum + ); + +#endif + diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf b/MdeModule= Pkg/Application/CapsuleApp/CapsuleApp.inf index 8ca5e04104..6ed0659835 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf @@ -2,11 +2,11 @@ # A shell application that triggers capsule update process. # # This application can trigger capsule update process. It can also # generate capsule image, or dump capsule variable information. # -# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## =20 [Defines] @@ -24,10 +24,11 @@ # VALID_ARCHITECTURES =3D IA32 X64 # =20 [Sources] CapsuleApp.c + CapsuleApp.h CapsuleDump.c CapsuleOnDisk.c AppSupport.c =20 [Packages] diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModuleP= kg/Application/CapsuleApp/CapsuleDump.c index b81c5b7b3a..58a93568d0 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c @@ -4,102 +4,11 @@ Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// -// (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for byt= es) -// -#define MAX_FILE_NAME_SIZE 522 -#define MAX_FILE_NAME_LEN (MAX_FILE_NAME_SIZE / sizeof(CHAR16)) - -/** - Read a file. - - @param[in] FileName The file to be read. - @param[out] BufferSize The file buffer size - @param[out] Buffer The file buffer - - @retval EFI_SUCCESS Read file successfully - @retval EFI_NOT_FOUND File not found -**/ -EFI_STATUS -ReadFileToBuffer ( - IN CHAR16 *FileName, - OUT UINTN *BufferSize, - OUT VOID **Buffer - ); - -/** - Write a file. - - @param[in] FileName The file to be written. - @param[in] BufferSize The file buffer size - @param[in] Buffer The file buffer - - @retval EFI_SUCCESS Write file successfully -**/ -EFI_STATUS -WriteFileFromBuffer ( - IN CHAR16 *FileName, - IN UINTN BufferSize, - IN VOID *Buffer - ); - -/** - Get shell protocol. - - @return Pointer to shell protocol. - -**/ -EFI_SHELL_PROTOCOL * -GetShellProtocol ( - VOID - ); - -/** - Get SimpleFileSystem from boot option file path. - - @param[in] DevicePath The file path of boot option - @param[out] FullPath The full device path of boot device - @param[out] Fs The file system within EfiSysPartition - - @retval EFI_SUCCESS Get file system successfully - @retval EFI_NOT_FOUND No valid file system found - @retval others Get file system failed - -**/ -EFI_STATUS -EFIAPI -GetEfiSysPartitionFromBootOptionFilePath ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, - OUT EFI_DEVICE_PATH_PROTOCOL **FullPath, - OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **Fs - ); +#include "CapsuleApp.h" =20 /** Validate if it is valid capsule header =20 This function assumes the caller provided correct CapsuleHeader pointer @@ -707,11 +616,10 @@ SplitFileNameExtension ( @return <0 Buffer1 is less than Buffer2. @return >0 Buffer1 is greater than Buffer2. =20 **/ INTN -EFIAPI CompareFileNameInAlphabet ( IN VOID *Left, IN VOID *Right ) { @@ -810,12 +718,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 +752,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/MdeModul= ePkg/Application/CapsuleApp/CapsuleOnDisk.c index a11683d66c..382efa9aa0 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c @@ -3,40 +3,14 @@ =20 Copyright (c) 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include =20 -EFI_GUID mCapsuleOnDiskBootOptionGuid =3D { 0x4CC29BB7, 0x2413, 0x40A2, { = 0xB0, 0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } }; - -/** - Get shell protocol. +#include "CapsuleApp.h" =20 - @return Pointer to shell protocol. - -**/ -EFI_SHELL_PROTOCOL * -GetShellProtocol ( - VOID - ); +EFI_GUID mCapsuleOnDiskBootOptionGuid =3D { 0x4CC29BB7, 0x2413, 0x40A2, { = 0xB0, 0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } }; =20 /** Get file name from file path. =20 @param FilePath File path. @@ -328,11 +302,10 @@ GetEfiSysPartitionFromDevPath ( @retval EFI_NOT_FOUND No valid file system found @retval others Get file system failed =20 **/ EFI_STATUS -EFIAPI GetEfiSysPartitionFromBootOptionFilePath ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT EFI_DEVICE_PATH_PROTOCOL **FullPath, OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **Fs ) @@ -396,11 +369,10 @@ GetEfiSysPartitionFromBootOptionFilePath ( @retval EFI_NOT_FOUND No valid FS found @retval others Get FS failed =20 **/ EFI_STATUS -EFIAPI GetUpdateFileSystem ( IN CHAR16 *Map, OUT UINT16 *BootNext, OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **Fs, OUT BOOLEAN *UpdateBootNext @@ -742,10 +714,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_SU= PPORTED) { + 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 size @@ -768,10 +775,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 (!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 +797,21 @@ ProcessCapsuleOnDisk ( if (EFI_ERROR (Status)) { Print (L"CapsuleApp: cannot find a valid file system on boot devies. S= tatus =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, = CapsuleNum, Fs); if (EFI_ERROR (Status)) { Print (L"CapsuleApp: capsule image could not be copied for update.\n"); return Status; } =20 --=20 2.16.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#42778): https://edk2.groups.io/g/devel/message/42778 Mute This Topic: https://groups.io/mt/32200994/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-