MdeModulePkg/CapsuleApp: Enhance Capsule-On-Disk related functions.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1840

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 <Capsule> -OD -NR' and 'CapsuleApp <Capsule> -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 <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Chao B Zhang <chao.b.zhang@intel.com>
Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
Reviewed-by: Chao B Zhang <chao.b.zhang@intel.com>
Acked-by: Hao A Wu <hao.a.wu@intel.com>
This commit is contained in:
Wei6 Xu
2019-06-24 13:21:35 +08:00
committed by Zhang, Chao B
parent 51f7a3e6c5
commit 8165570e3e
6 changed files with 323 additions and 332 deletions

View File

@ -5,37 +5,11 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/PrintLib.h>
#include <Library/DevicePathLib.h>
#include <Library/FileHandleLib.h>
#include <Library/UefiBootManagerLib.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/Shell.h>
#include <Guid/FileInfo.h>
#include <Guid/GlobalVariable.h>
#include <Guid/Gpt.h>
#include "CapsuleApp.h"
EFI_GUID mCapsuleOnDiskBootOptionGuid = { 0x4CC29BB7, 0x2413, 0x40A2, { 0xB0, 0x6D, 0x25, 0x3E, 0x37, 0x10, 0xF5, 0x32 } };
/**
Get shell protocol.
@return Pointer to shell protocol.
**/
EFI_SHELL_PROTOCOL *
GetShellProtocol (
VOID
);
/**
Get file name from file path.
@ -330,7 +304,6 @@ GetEfiSysPartitionFromDevPath (
**/
EFI_STATUS
EFIAPI
GetEfiSysPartitionFromBootOptionFilePath (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,
@ -398,7 +371,6 @@ GetEfiSysPartitionFromBootOptionFilePath (
**/
EFI_STATUS
EFIAPI
GetUpdateFileSystem (
IN CHAR16 *Map,
OUT UINT16 *BootNext,
@ -744,6 +716,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 +777,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 +799,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;