]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel2CommandsLib/Reset.c
ShellPkg/Dp: Add null pointer check
[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 - 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
10
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.
13
14 **/
15
16 #include "UefiShellLevel2CommandsLib.h"
17
18 STATIC CONST SHELL_PARAM_ITEM ResetParamList[] = {
19 {L"-w", TypeValue},
20 {L"-s", TypeValue},
21 {L"-c", TypeValue},
22 {L"-fwui", TypeFlag },
23 {NULL, TypeMax }
24 };
25
26 /**
27 Function for 'reset' command.
28
29 @param[in] ImageHandle Handle to the Image (NULL if Internal).
30 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
31 **/
32 SHELL_STATUS
33 EFIAPI
34 ShellCommandRunReset (
35 IN EFI_HANDLE ImageHandle,
36 IN EFI_SYSTEM_TABLE *SystemTable
37 )
38 {
39 EFI_STATUS Status;
40 LIST_ENTRY *Package;
41 CONST CHAR16 *String;
42 CHAR16 *ProblemParam;
43 SHELL_STATUS ShellStatus;
44 UINT64 OsIndications;
45 UINT32 Attr;
46 UINTN DataSize;
47
48 ShellStatus = SHELL_SUCCESS;
49 ProblemParam = NULL;
50
51 //
52 // initialize the shell lib (we must be in non-auto-init...)
53 //
54 Status = ShellInitialize();
55 ASSERT_EFI_ERROR(Status);
56
57 //
58 // parse the command line
59 //
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);
66 } else {
67 ASSERT(FALSE);
68 }
69 } else {
70 //
71 // check for "-?"
72 //
73 if (ShellCommandLineGetFlag(Package, L"-?")) {
74 ASSERT(FALSE);
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;
78 } else {
79
80 if (ShellCommandLineGetFlag (Package, L"-fwui")) {
81
82 DataSize = sizeof (OsIndications);
83 Status = gRT->GetVariable (
84 EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME, &gEfiGlobalVariableGuid,
85 &Attr, &DataSize, &OsIndications
86 );
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
93 );
94 if (!EFI_ERROR (Status)) {
95 OsIndications |= EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
96 } else {
97 OsIndications = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
98 }
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
103 );
104 }
105 }
106 if (EFI_ERROR (Status)) {
107 ShellStatus = SHELL_UNSUPPORTED;
108 goto Error;
109 }
110 }
111
112 //
113 // check for warm reset flag, then shutdown reset flag, then cold (default) reset flag
114 //
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;
119 } else {
120 String = ShellCommandLineGetValue(Package, L"-w");
121 if (String != NULL) {
122 gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, StrSize(String), (VOID*)String);
123 } else {
124 gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
125 }
126 }
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;
131 } else {
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);
136 } else {
137 gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
138 }
139 }
140 } else {
141 //
142 // this is default so dont worry about flag...
143 //
144 String = ShellCommandLineGetValue(Package, L"-c");
145 if (String != NULL) {
146 gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, StrSize(String), (VOID*)String);
147 } else {
148 gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
149 }
150 }
151 }
152 }
153
154 //
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...
157 //
158
159 Error:
160 //
161 // free the command line package
162 //
163 ShellCommandLineFreeVarList (Package);
164
165 //
166 // return the status
167 //
168 return (ShellStatus);
169 }
170