2 Main file for attrib shell level 2 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellLevel2CommandsLib.h"
18 STATIC CONST SHELL_PARAM_ITEM ResetParamList
[] = {
22 {L
"-fwui", TypeFlag
},
27 Function for 'reset' command.
29 @param[in] ImageHandle Handle to the Image (NULL if Internal).
30 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
34 ShellCommandRunReset (
35 IN EFI_HANDLE ImageHandle
,
36 IN EFI_SYSTEM_TABLE
*SystemTable
43 SHELL_STATUS ShellStatus
;
48 ShellStatus
= SHELL_SUCCESS
;
52 // initialize the shell lib (we must be in non-auto-init...)
54 Status
= ShellInitialize();
55 ASSERT_EFI_ERROR(Status
);
58 // parse the command line
60 Status
= ShellCommandLineParse (ResetParamList
, &Package
, &ProblemParam
, TRUE
);
61 if (EFI_ERROR(Status
)) {
62 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
63 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"reset", ProblemParam
);
64 FreePool(ProblemParam
);
65 return (SHELL_INVALID_PARAMETER
);
73 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
75 } else if (ShellCommandLineGetRawValue(Package
, 1) != NULL
) {
76 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"reset");
77 ShellStatus
= SHELL_INVALID_PARAMETER
;
80 if (ShellCommandLineGetFlag (Package
, L
"-fwui")) {
82 DataSize
= sizeof (OsIndications
);
83 Status
= gRT
->GetVariable (
84 EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME
, &gEfiGlobalVariableGuid
,
85 &Attr
, &DataSize
, &OsIndications
87 if (!EFI_ERROR (Status
)) {
88 if ((OsIndications
& EFI_OS_INDICATIONS_BOOT_TO_FW_UI
) != 0) {
89 DataSize
= sizeof (OsIndications
);
90 Status
= gRT
->GetVariable (
91 EFI_OS_INDICATIONS_VARIABLE_NAME
, &gEfiGlobalVariableGuid
,
92 &Attr
, &DataSize
, &OsIndications
94 if (!EFI_ERROR (Status
)) {
95 OsIndications
|= EFI_OS_INDICATIONS_BOOT_TO_FW_UI
;
97 OsIndications
= EFI_OS_INDICATIONS_BOOT_TO_FW_UI
;
99 Status
= gRT
->SetVariable (
100 EFI_OS_INDICATIONS_VARIABLE_NAME
, &gEfiGlobalVariableGuid
,
101 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
102 sizeof (OsIndications
), &OsIndications
106 if (EFI_ERROR (Status
)) {
107 ShellStatus
= SHELL_UNSUPPORTED
;
113 // check for warm reset flag, then shutdown reset flag, then cold (default) reset flag
115 if (ShellCommandLineGetFlag(Package
, L
"-w")) {
116 if (ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-c")) {
117 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"reset");
118 ShellStatus
= SHELL_INVALID_PARAMETER
;
120 String
= ShellCommandLineGetValue(Package
, L
"-w");
121 if (String
!= NULL
) {
122 gRT
->ResetSystem(EfiResetWarm
, EFI_SUCCESS
, StrSize(String
), (VOID
*)String
);
124 gRT
->ResetSystem(EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
127 } else if (ShellCommandLineGetFlag(Package
, L
"-s")) {
128 if (ShellCommandLineGetFlag(Package
, L
"-c")) {
129 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"reset");
130 ShellStatus
= SHELL_INVALID_PARAMETER
;
132 String
= ShellCommandLineGetValue(Package
, L
"-s");
133 DEBUG_CODE(ShellPrintEx(-1,-1,L
"Reset with %s (%d bytes)", String
, String
!=NULL
?StrSize(String
):0););
134 if (String
!= NULL
) {
135 gRT
->ResetSystem(EfiResetShutdown
, EFI_SUCCESS
, StrSize(String
), (VOID
*)String
);
137 gRT
->ResetSystem(EfiResetShutdown
, EFI_SUCCESS
, 0, NULL
);
142 // this is default so dont worry about flag...
144 String
= ShellCommandLineGetValue(Package
, L
"-c");
145 if (String
!= NULL
) {
146 gRT
->ResetSystem(EfiResetCold
, EFI_SUCCESS
, StrSize(String
), (VOID
*)String
);
148 gRT
->ResetSystem(EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
155 // we should never get here... so the free and return are for formality more than use
156 // as the ResetSystem function should not return...
161 // free the command line package
163 ShellCommandLineFreeVarList (Package
);
168 return (ShellStatus
);