2 Main file for attrib shell level 2 function.
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
10 #include "UefiShellLevel2CommandsLib.h"
12 STATIC CONST SHELL_PARAM_ITEM ResetParamList
[] = {
16 { L
"-fwui", TypeFlag
},
21 Function for 'reset' command.
23 @param[in] ImageHandle Handle to the Image (NULL if Internal).
24 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
28 ShellCommandRunReset (
29 IN EFI_HANDLE ImageHandle
,
30 IN EFI_SYSTEM_TABLE
*SystemTable
37 SHELL_STATUS ShellStatus
;
42 ShellStatus
= SHELL_SUCCESS
;
46 // initialize the shell lib (we must be in non-auto-init...)
48 Status
= ShellInitialize ();
49 ASSERT_EFI_ERROR (Status
);
52 // parse the command line
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
);
67 if (ShellCommandLineGetFlag (Package
, L
"-?")) {
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
;
73 if (ShellCommandLineGetFlag (Package
, L
"-fwui")) {
74 DataSize
= sizeof (OsIndications
);
75 Status
= gRT
->GetVariable (
76 EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME
,
77 &gEfiGlobalVariableGuid
,
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
,
92 if (!EFI_ERROR (Status
)) {
93 OsIndications
|= EFI_OS_INDICATIONS_BOOT_TO_FW_UI
;
95 OsIndications
= EFI_OS_INDICATIONS_BOOT_TO_FW_UI
;
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
),
108 if (EFI_ERROR (Status
)) {
109 ShellStatus
= SHELL_UNSUPPORTED
;
115 // check for warm reset flag, then shutdown reset flag, then cold (default) reset flag
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
;
122 String
= ShellCommandLineGetValue (Package
, L
"-w");
123 if (String
!= NULL
) {
124 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, StrSize (String
), (VOID
*)String
);
126 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
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
;
134 String
= ShellCommandLineGetValue (Package
, L
"-s");
136 ShellPrintEx (-1, -1, L
"Reset with %s (%d bytes)", String
, String
!= NULL
? StrSize (String
) : 0);
138 if (String
!= NULL
) {
139 gRT
->ResetSystem (EfiResetShutdown
, EFI_SUCCESS
, StrSize (String
), (VOID
*)String
);
141 gRT
->ResetSystem (EfiResetShutdown
, EFI_SUCCESS
, 0, NULL
);
146 // this is default so dont worry about flag...
148 String
= ShellCommandLineGetValue (Package
, L
"-c");
149 if (String
!= NULL
) {
150 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, StrSize (String
), (VOID
*)String
);
152 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
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...
165 // free the command line package
167 ShellCommandLineFreeVarList (Package
);
172 return (ShellStatus
);