]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel2CommandsLib/Reset.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Reset.c
1 /** @file
2 Main file for attrib shell level 2 function.
3
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "UefiShellLevel2CommandsLib.h"
11
12 STATIC CONST SHELL_PARAM_ITEM ResetParamList[] = {
13 { L"-w", TypeValue },
14 { L"-s", TypeValue },
15 { L"-c", TypeValue },
16 { L"-fwui", TypeFlag },
17 { NULL, TypeMax }
18 };
19
20 /**
21 Function for 'reset' command.
22
23 @param[in] ImageHandle Handle to the Image (NULL if Internal).
24 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
25 **/
26 SHELL_STATUS
27 EFIAPI
28 ShellCommandRunReset (
29 IN EFI_HANDLE ImageHandle,
30 IN EFI_SYSTEM_TABLE *SystemTable
31 )
32 {
33 EFI_STATUS Status;
34 LIST_ENTRY *Package;
35 CONST CHAR16 *String;
36 CHAR16 *ProblemParam;
37 SHELL_STATUS ShellStatus;
38 UINT64 OsIndications;
39 UINT32 Attr;
40 UINTN DataSize;
41
42 ShellStatus = SHELL_SUCCESS;
43 ProblemParam = NULL;
44
45 //
46 // initialize the shell lib (we must be in non-auto-init...)
47 //
48 Status = ShellInitialize ();
49 ASSERT_EFI_ERROR (Status);
50
51 //
52 // parse the command line
53 //
54 Status = ShellCommandLineParse (ResetParamList, &Package, &ProblemParam, TRUE);
55 if (EFI_ERROR (Status)) {
56 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
57 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"reset", ProblemParam);
58 FreePool (ProblemParam);
59 return (SHELL_INVALID_PARAMETER);
60 } else {
61 ASSERT (FALSE);
62 }
63 } else {
64 //
65 // check for "-?"
66 //
67 if (ShellCommandLineGetFlag (Package, L"-?")) {
68 ASSERT (FALSE);
69 } else if (ShellCommandLineGetRawValue (Package, 1) != NULL) {
70 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
71 ShellStatus = SHELL_INVALID_PARAMETER;
72 } else {
73 if (ShellCommandLineGetFlag (Package, L"-fwui")) {
74 DataSize = sizeof (OsIndications);
75 Status = gRT->GetVariable (
76 EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME,
77 &gEfiGlobalVariableGuid,
78 &Attr,
79 &DataSize,
80 &OsIndications
81 );
82 if (!EFI_ERROR (Status)) {
83 if ((OsIndications & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0) {
84 DataSize = sizeof (OsIndications);
85 Status = gRT->GetVariable (
86 EFI_OS_INDICATIONS_VARIABLE_NAME,
87 &gEfiGlobalVariableGuid,
88 &Attr,
89 &DataSize,
90 &OsIndications
91 );
92 if (!EFI_ERROR (Status)) {
93 OsIndications |= EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
94 } else {
95 OsIndications = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
96 }
97
98 Status = gRT->SetVariable (
99 EFI_OS_INDICATIONS_VARIABLE_NAME,
100 &gEfiGlobalVariableGuid,
101 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
102 sizeof (OsIndications),
103 &OsIndications
104 );
105 }
106 }
107
108 if (EFI_ERROR (Status)) {
109 ShellStatus = SHELL_UNSUPPORTED;
110 goto Error;
111 }
112 }
113
114 //
115 // check for warm reset flag, then shutdown reset flag, then cold (default) reset flag
116 //
117 if (ShellCommandLineGetFlag (Package, L"-w")) {
118 if (ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-c")) {
119 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
120 ShellStatus = SHELL_INVALID_PARAMETER;
121 } else {
122 String = ShellCommandLineGetValue (Package, L"-w");
123 if (String != NULL) {
124 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, StrSize (String), (VOID *)String);
125 } else {
126 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
127 }
128 }
129 } else if (ShellCommandLineGetFlag (Package, L"-s")) {
130 if (ShellCommandLineGetFlag (Package, L"-c")) {
131 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
132 ShellStatus = SHELL_INVALID_PARAMETER;
133 } else {
134 String = ShellCommandLineGetValue (Package, L"-s");
135 DEBUG_CODE (
136 ShellPrintEx (-1, -1, L"Reset with %s (%d bytes)", String, String != NULL ? StrSize (String) : 0);
137 );
138 if (String != NULL) {
139 gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, StrSize (String), (VOID *)String);
140 } else {
141 gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL);
142 }
143 }
144 } else {
145 //
146 // this is default so dont worry about flag...
147 //
148 String = ShellCommandLineGetValue (Package, L"-c");
149 if (String != NULL) {
150 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, StrSize (String), (VOID *)String);
151 } else {
152 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
153 }
154 }
155 }
156 }
157
158 //
159 // we should never get here... so the free and return are for formality more than use
160 // as the ResetSystem function should not return...
161 //
162
163 Error:
164 //
165 // free the command line package
166 //
167 ShellCommandLineFreeVarList (Package);
168
169 //
170 // return the status
171 //
172 return (ShellStatus);
173 }