summaryrefslogtreecommitdiffstats
path: root/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.h
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2023-10-30 16:31:10 -0400
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-10-31 14:40:50 +0000
commitd4358a7f7629c996f80236588c95b62cd9c93584 (patch)
tree191250573385970bb47b6cc35897de0a2c0826b3 /ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.h
parentf3b2187d558b1540e65e86024423ee39fe6264aa (diff)
downloadedk2-d4358a7f7629c996f80236588c95b62cd9c93584.tar.gz
edk2-d4358a7f7629c996f80236588c95b62cd9c93584.tar.bz2
edk2-d4358a7f7629c996f80236588c95b62cd9c93584.zip
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>
Diffstat (limited to 'ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.h')
-rw-r--r--ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.h129
1 files changed, 129 insertions, 0 deletions
diff --git a/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.h b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.h
new file mode 100644
index 0000000000..0498232426
--- /dev/null
+++ b/ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicy.h
@@ -0,0 +1,129 @@
+/** @file
+ Internal header file for the module.
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef VAR_POLICY_DYNAMIC_SHELL_COMMAND_H_
+#define VAR_POLICY_DYNAMIC_SHELL_COMMAND_H_
+
+#include <Uefi.h>
+#include <Protocol/Shell.h>
+
+#define VAR_POLICY_COMMAND_NAME L"varpolicy"
+
+typedef enum {
+ VariableVendorCapsule,
+ VariableVendorCapsuleReport,
+ VariableVendorGlobal,
+ VariableVendorMemoryTypeInfo,
+ VariableVendorMonotonicCounter,
+ VariableVendorMorControl,
+ VariableVendorShell,
+ VariableVendorGuidMax
+} VAR_POLICY_CMD_VENDOR_GUID_TYPE;
+
+typedef struct {
+ VAR_POLICY_CMD_VENDOR_GUID_TYPE VendorGuidType;
+ EFI_GUID *VendorGuid;
+ CHAR16 *Description;
+} VAR_POLICY_CMD_VAR_NAMESPACE;
+
+/**
+ Log a formatted console message.
+
+ This is not specific to this shell command but scoped so to prevent global
+ name conflicts.
+
+ The hex dump is split into lines of 16 dumped bytes.
+
+ The full hex dump is bracketed, and its byte ascii char also print.
+ If the byte value is not an ascii code, it will print as '.'
+
+ @param[in] Offset Offset to be display after PrefixFormat.
+ Offset will be increased for each print line.
+ @param[in] Data The data to dump.
+ @param[in] DataSize Number of bytes in Data.
+
+**/
+#define VAR_POLICY_CMD_SHELL_DUMP_HEX(Offset, \
+ Data, \
+ DataSize \
+ ) \
+ { \
+ UINT8 *_DataToDump; \
+ UINT8 _Val[50]; \
+ UINT8 _Str[20]; \
+ UINT8 _TempByte; \
+ UINTN _Size; \
+ UINTN _DumpHexIndex; \
+ UINTN _LocalOffset; \
+ UINTN _LocalDataSize; \
+ CONST CHAR8 *_Hex = "0123456789ABCDEF"; \
+ _LocalOffset = (Offset); \
+ _LocalDataSize = (DataSize); \
+ _DataToDump = (UINT8 *)(Data); \
+ \
+ ASSERT (_DataToDump != NULL); \
+ \
+ while (_LocalDataSize != 0) { \
+ _Size = 16; \
+ if (_Size > _LocalDataSize) { \
+ _Size = _LocalDataSize; \
+ } \
+ \
+ for (_DumpHexIndex = 0; _DumpHexIndex < _Size; _DumpHexIndex += 1) { \
+ _TempByte = (UINT8) _DataToDump[_DumpHexIndex]; \
+ _Val[_DumpHexIndex * 3 + 0] = (UINT8) _Hex[_TempByte >> 4]; \
+ _Val[_DumpHexIndex * 3 + 1] = (UINT8) _Hex[_TempByte & 0xF]; \
+ _Val[_DumpHexIndex * 3 + 2] = \
+ (CHAR8) ((_DumpHexIndex == 7) ? '-' : ' '); \
+ _Str[_DumpHexIndex] = \
+ (CHAR8) ((_TempByte < ' ' || _TempByte > '~') ? '.' : _TempByte); \
+ } \
+ \
+ _Val[_DumpHexIndex * 3] = 0; \
+ _Str[_DumpHexIndex] = 0; \
+ \
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_HEX_DUMP_LINE), mVarPolicyShellCommandHiiHandle, _LocalOffset, _Val, _Str); \
+ _DataToDump = (UINT8 *)(((UINTN)_DataToDump) + _Size); \
+ _LocalOffset += _Size; \
+ _LocalDataSize -= _Size; \
+ } \
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_LINE_BREAK), mVarPolicyShellCommandHiiHandle); \
+ }
+
+/**
+ Retrieve HII package list from ImageHandle and publish to HII database.
+
+ @param[in] ImageHandle The image handle of the process.
+
+ @return HII handle.
+
+**/
+EFI_HII_HANDLE
+InitializeHiiPackage (
+ IN EFI_HANDLE ImageHandle
+ );
+
+/**
+ Main entry function for the "varpolicy" command/app.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+
+ @retval SHELL_SUCCESS The "varpolicy" shell command executed successfully.
+ @retval SHELL_INVALID_PARAMETER An argument passed to the shell command is invalid.
+ @retval Others A different error occurred.
+
+**/
+SHELL_STATUS
+EFIAPI
+RunVarPolicy (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+#endif