VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Reset.c

Last change on this file was 105670, checked in by vboxsync, 4 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

  • Property svn:eol-style set to native
File size: 5.7 KB
Line 
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
12STATIC 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**/
26SHELL_STATUS
27EFIAPI
28ShellCommandRunReset (
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
83 if (EFI_ERROR (Status)) {
84 ShellStatus = SHELL_UNSUPPORTED;
85 goto Error;
86 }
87
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,
92 &gEfiGlobalVariableGuid,
93 &Attr,
94 &DataSize,
95 &OsIndications
96 );
97
98 if (EFI_ERROR (Status)) {
99 OsIndications = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
100 } else {
101 OsIndications |= EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
102 }
103
104 Status = gRT->SetVariable (
105 EFI_OS_INDICATIONS_VARIABLE_NAME,
106 &gEfiGlobalVariableGuid,
107 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
108 sizeof (OsIndications),
109 &OsIndications
110 );
111 }
112
113 if (EFI_ERROR (Status)) {
114 ShellStatus = SHELL_UNSUPPORTED;
115 goto Error;
116 }
117 }
118
119 //
120 // check for warm reset flag, then shutdown reset flag, then cold (default) reset flag
121 //
122 if (ShellCommandLineGetFlag (Package, L"-w")) {
123 if (ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-c")) {
124 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
125 ShellStatus = SHELL_INVALID_PARAMETER;
126 } else {
127 String = ShellCommandLineGetValue (Package, L"-w");
128 if (String != NULL) {
129 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, StrSize (String), (VOID *)String);
130 } else {
131 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
132 }
133 }
134 } else if (ShellCommandLineGetFlag (Package, L"-s")) {
135 if (ShellCommandLineGetFlag (Package, L"-c")) {
136 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
137 ShellStatus = SHELL_INVALID_PARAMETER;
138 } else {
139 String = ShellCommandLineGetValue (Package, L"-s");
140 DEBUG_CODE (
141 ShellPrintEx (-1, -1, L"Reset with %s (%d bytes)", String, String != NULL ? StrSize (String) : 0);
142 );
143 if (String != NULL) {
144 gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, StrSize (String), (VOID *)String);
145 } else {
146 gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL);
147 }
148 }
149 } else {
150 //
151 // this is default so dont worry about flag...
152 //
153 String = ShellCommandLineGetValue (Package, L"-c");
154 if (String != NULL) {
155 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, StrSize (String), (VOID *)String);
156 } else {
157 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
158 }
159 }
160 }
161 }
162
163 //
164 // we should never get here... so the free and return are for formality more than use
165 // as the ResetSystem function should not return...
166 //
167
168Error:
169 //
170 // free the command line package
171 //
172 ShellCommandLineFreeVarList (Package);
173
174 //
175 // return the status
176 //
177 return (ShellStatus);
178}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette