1 | /** @file
|
---|
2 | Functionality specific for dynamic UEFI shell command support.
|
---|
3 |
|
---|
4 | This command can provide detailed UEFI variable policy configuration
|
---|
5 | information in the UEFI shell.
|
---|
6 |
|
---|
7 | Copyright (c) Microsoft Corporation.
|
---|
8 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
9 |
|
---|
10 | **/
|
---|
11 |
|
---|
12 | #include "VariablePolicy.h"
|
---|
13 |
|
---|
14 | #include <Library/BaseLib.h>
|
---|
15 | #include <Library/DebugLib.h>
|
---|
16 | #include <Library/HiiLib.h>
|
---|
17 | #include <Library/ShellLib.h>
|
---|
18 | #include <Library/UefiBootServicesTableLib.h>
|
---|
19 | #include <Library/UefiRuntimeServicesTableLib.h>
|
---|
20 |
|
---|
21 | #include <Protocol/ShellDynamicCommand.h>
|
---|
22 |
|
---|
23 | extern EFI_HII_HANDLE mVarPolicyShellCommandHiiHandle;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | This is the shell command handler function pointer callback type.
|
---|
27 |
|
---|
28 | This function handles the command when it is invoked in the shell.
|
---|
29 |
|
---|
30 | @param[in] This The instance of the
|
---|
31 | EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
|
---|
32 | @param[in] SystemTable The pointer to the system table.
|
---|
33 | @param[in] ShellParameters The parameters associated with the command.
|
---|
34 | @param[in] Shell The instance of the shell protocol used in
|
---|
35 | the context of processing this command.
|
---|
36 |
|
---|
37 | @return EFI_SUCCESS the operation was successful
|
---|
38 | @return other the operation failed.
|
---|
39 |
|
---|
40 | **/
|
---|
41 | SHELL_STATUS
|
---|
42 | EFIAPI
|
---|
43 | VarPolicyCommandHandler (
|
---|
44 | IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
|
---|
45 | IN EFI_SYSTEM_TABLE *SystemTable,
|
---|
46 | IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
|
---|
47 | IN EFI_SHELL_PROTOCOL *Shell
|
---|
48 | )
|
---|
49 | {
|
---|
50 | gEfiShellParametersProtocol = ShellParameters;
|
---|
51 | gEfiShellProtocol = Shell;
|
---|
52 |
|
---|
53 | return RunVarPolicy (gImageHandle, SystemTable);
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | This is the command help handler function pointer callback type. This
|
---|
58 | function is responsible for displaying help information for the associated
|
---|
59 | command.
|
---|
60 |
|
---|
61 | @param[in] This The instance of the
|
---|
62 | EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
|
---|
63 | @param[in] Language The pointer to the language string to use.
|
---|
64 |
|
---|
65 | @return string Pool allocated help string, must be freed
|
---|
66 | by caller.
|
---|
67 |
|
---|
68 | **/
|
---|
69 | STATIC
|
---|
70 | CHAR16 *
|
---|
71 | EFIAPI
|
---|
72 | VarPolicyCommandGetHelp (
|
---|
73 | IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
|
---|
74 | IN CONST CHAR8 *Language
|
---|
75 | )
|
---|
76 | {
|
---|
77 | return HiiGetString (
|
---|
78 | mVarPolicyShellCommandHiiHandle,
|
---|
79 | STRING_TOKEN (STR_GET_HELP_VAR_POLICY),
|
---|
80 | Language
|
---|
81 | );
|
---|
82 | }
|
---|
83 |
|
---|
84 | STATIC EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mVarPolicyDynamicCommand = {
|
---|
85 | VAR_POLICY_COMMAND_NAME,
|
---|
86 | VarPolicyCommandHandler,
|
---|
87 | VarPolicyCommandGetHelp
|
---|
88 | };
|
---|
89 |
|
---|
90 | /**
|
---|
91 | Entry point of the UEFI variable policy dynamic shell command.
|
---|
92 |
|
---|
93 | Produce the Dynamic Command Protocol to handle the "varpolicy" command.
|
---|
94 |
|
---|
95 | @param[in] ImageHandle The image handle of the process.
|
---|
96 | @param[in] SystemTable The EFI System Table pointer.
|
---|
97 |
|
---|
98 | @retval EFI_SUCCESS The "varpolicy" command executed successfully.
|
---|
99 | @retval EFI_ABORTED HII package failed to initialize.
|
---|
100 | @retval others Other errors when executing "varpolicy" command.
|
---|
101 |
|
---|
102 | **/
|
---|
103 | EFI_STATUS
|
---|
104 | EFIAPI
|
---|
105 | VariablePolicyDynamicCommandEntryPoint (
|
---|
106 | IN EFI_HANDLE ImageHandle,
|
---|
107 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
108 | )
|
---|
109 | {
|
---|
110 | EFI_STATUS Status;
|
---|
111 |
|
---|
112 | mVarPolicyShellCommandHiiHandle = InitializeHiiPackage (ImageHandle);
|
---|
113 | if (mVarPolicyShellCommandHiiHandle == NULL) {
|
---|
114 | return EFI_ABORTED;
|
---|
115 | }
|
---|
116 |
|
---|
117 | Status = gBS->InstallProtocolInterface (
|
---|
118 | &ImageHandle,
|
---|
119 | &gEfiShellDynamicCommandProtocolGuid,
|
---|
120 | EFI_NATIVE_INTERFACE,
|
---|
121 | &mVarPolicyDynamicCommand
|
---|
122 | );
|
---|
123 | ASSERT_EFI_ERROR (Status);
|
---|
124 |
|
---|
125 | return Status;
|
---|
126 | }
|
---|
127 |
|
---|
128 | /**
|
---|
129 | Unload the dynamic "varpolicy" UEFI Shell command.
|
---|
130 |
|
---|
131 | @param[in] ImageHandle The image handle of the process.
|
---|
132 |
|
---|
133 | @retval EFI_SUCCESS The image is unloaded.
|
---|
134 | @retval Others Failed to unload the image.
|
---|
135 |
|
---|
136 | **/
|
---|
137 | EFI_STATUS
|
---|
138 | EFIAPI
|
---|
139 | VariablePolicyDynamicCommandUnload (
|
---|
140 | IN EFI_HANDLE ImageHandle
|
---|
141 | )
|
---|
142 | {
|
---|
143 | EFI_STATUS Status;
|
---|
144 |
|
---|
145 | Status = gBS->UninstallProtocolInterface (
|
---|
146 | ImageHandle,
|
---|
147 | &gEfiShellDynamicCommandProtocolGuid,
|
---|
148 | &mVarPolicyDynamicCommand
|
---|
149 | );
|
---|
150 | if (EFI_ERROR (Status)) {
|
---|
151 | return Status;
|
---|
152 | }
|
---|
153 |
|
---|
154 | HiiRemovePackages (mVarPolicyShellCommandHiiHandle);
|
---|
155 |
|
---|
156 | return EFI_SUCCESS;
|
---|
157 | }
|
---|