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
;
74 if (ShellCommandLineGetFlag (Package
, L
"-fwui")) {
76 DataSize
= sizeof (OsIndications
);
77 Status
= gRT
->GetVariable (
78 EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME
, &gEfiGlobalVariableGuid
,
79 &Attr
, &DataSize
, &OsIndications
81 if (!EFI_ERROR (Status
)) {
82 if ((OsIndications
& EFI_OS_INDICATIONS_BOOT_TO_FW_UI
) != 0) {
83 DataSize
= sizeof (OsIndications
);
84 Status
= gRT
->GetVariable (
85 EFI_OS_INDICATIONS_VARIABLE_NAME
, &gEfiGlobalVariableGuid
,
86 &Attr
, &DataSize
, &OsIndications
88 if (!EFI_ERROR (Status
)) {
89 OsIndications
|= EFI_OS_INDICATIONS_BOOT_TO_FW_UI
;
91 OsIndications
= EFI_OS_INDICATIONS_BOOT_TO_FW_UI
;
93 Status
= gRT
->SetVariable (
94 EFI_OS_INDICATIONS_VARIABLE_NAME
, &gEfiGlobalVariableGuid
,
95 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
96 sizeof (OsIndications
), &OsIndications
100 if (EFI_ERROR (Status
)) {
101 ShellStatus
= SHELL_UNSUPPORTED
;
107 // check for warm reset flag, then shutdown reset flag, then cold (default) reset flag
109 if (ShellCommandLineGetFlag(Package
, L
"-w")) {
110 if (ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-c")) {
111 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"reset");
112 ShellStatus
= SHELL_INVALID_PARAMETER
;
114 String
= ShellCommandLineGetValue(Package
, L
"-w");
115 if (String
!= NULL
) {
116 gRT
->ResetSystem(EfiResetWarm
, EFI_SUCCESS
, StrSize(String
), (VOID
*)String
);
118 gRT
->ResetSystem(EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
121 } else if (ShellCommandLineGetFlag(Package
, L
"-s")) {
122 if (ShellCommandLineGetFlag(Package
, L
"-c")) {
123 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"reset");
124 ShellStatus
= SHELL_INVALID_PARAMETER
;
126 String
= ShellCommandLineGetValue(Package
, L
"-s");
127 DEBUG_CODE(ShellPrintEx(-1,-1,L
"Reset with %s (%d bytes)", String
, String
!=NULL
?StrSize(String
):0););
128 if (String
!= NULL
) {
129 gRT
->ResetSystem(EfiResetShutdown
, EFI_SUCCESS
, StrSize(String
), (VOID
*)String
);
131 gRT
->ResetSystem(EfiResetShutdown
, EFI_SUCCESS
, 0, NULL
);
136 // this is default so dont worry about flag...
138 String
= ShellCommandLineGetValue(Package
, L
"-c");
139 if (String
!= NULL
) {
140 gRT
->ResetSystem(EfiResetCold
, EFI_SUCCESS
, StrSize(String
), (VOID
*)String
);
142 gRT
->ResetSystem(EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
149 // we should never get here... so the free and return are for formality more than use
150 // as the ResetSystem function should not return...
155 // free the command line package
157 ShellCommandLineFreeVarList (Package
);
162 return (ShellStatus
);