Michael Kubacki d4358a7f76 ShellPkg: Add varpolicy dynamic shell command and app
Adds a new module (dynamic shell command) to ShellPkg that lists
variable policy information for all UEFI variables on the system.

Some other UEFI variable related functionality is also included to
give a greater sense of platform UEFI variable state. This command
is intended to help make variable policies more transparent and
easier to understand and configure on a platform.

Like all dynamic shell commands, a platform only needs to include
`VariablePolicyDynamicCommand.inf` in their flash image to have
the command registered in their UEFI shell.

Include the following lines in platform DSC (in DXE components section):

```
  ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamicCommand.inf {
    <PcdsFixedAtBuild>
      gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
  }
```

Include the following line in platform FDF:

```
INF  ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamicCommand.inf
```

A standalone UEFI application can also be built that uses the same
underlying functional code as the dynamic shell command.

The path to use in the DSC and FDF for the app:

```
  ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyApp.inf
```

Cc: Zhichao Gao <zhichao.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
Message-Id: <20231030203112.736-3-mikuback@linux.microsoft.com>
2023-10-31 14:40:50 +00:00

60 lines
1.8 KiB
C

/** @file
Functionality specific for standalone UEFI application support.
This application can provide detailed UEFI variable policy configuration
information in the UEFI shell.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "VariablePolicy.h"
#include <Library/BaseLib.h>
#include <Library/HiiLib.h>
extern EFI_HII_HANDLE mVarPolicyShellCommandHiiHandle;
//
// String token ID of help message text.
// Shell supports finding the help message in the resource section of an
// application image if a .MAN file is not found. This global variable is added
// to make the build tool recognize that the help string is consumed by the user and
// then the build tool will add the string into the resource section. Thus the
// application can use '-?' option to show help message in Shell.
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_STRING_ID mStringHelpTokenId = STRING_TOKEN (STR_GET_HELP_VAR_POLICY);
/**
Entry of the UEFI variable policy application.
@param ImageHandle The image handle of the process.
@param SystemTable The EFI System Table pointer.
@retval EFI_SUCCESS The application successfully initialized.
@retval EFI_ABORTED The application failed to initialize.
@retval Others A different error occurred.
**/
EFI_STATUS
EFIAPI
VariablePolicyAppInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
mVarPolicyShellCommandHiiHandle = InitializeHiiPackage (ImageHandle);
if (mVarPolicyShellCommandHiiHandle == NULL) {
return EFI_ABORTED;
}
Status = (EFI_STATUS)RunVarPolicy (ImageHandle, SystemTable);
HiiRemovePackages (mVarPolicyShellCommandHiiHandle);
return Status;
}