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 |
|
---|
12 | STATIC 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 | **/
|
---|
26 | SHELL_STATUS
|
---|
27 | EFIAPI
|
---|
28 | ShellCommandRunReset (
|
---|
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 |
|
---|
74 | if (ShellCommandLineGetFlag (Package, L"-fwui")) {
|
---|
75 |
|
---|
76 | DataSize = sizeof (OsIndications);
|
---|
77 | Status = gRT->GetVariable (
|
---|
78 | EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME, &gEfiGlobalVariableGuid,
|
---|
79 | &Attr, &DataSize, &OsIndications
|
---|
80 | );
|
---|
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
|
---|
87 | );
|
---|
88 | if (!EFI_ERROR (Status)) {
|
---|
89 | OsIndications |= EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
|
---|
90 | } else {
|
---|
91 | OsIndications = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
|
---|
92 | }
|
---|
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
|
---|
97 | );
|
---|
98 | }
|
---|
99 | }
|
---|
100 | if (EFI_ERROR (Status)) {
|
---|
101 | ShellStatus = SHELL_UNSUPPORTED;
|
---|
102 | goto Error;
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | //
|
---|
107 | // check for warm reset flag, then shutdown reset flag, then cold (default) reset flag
|
---|
108 | //
|
---|
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;
|
---|
113 | } else {
|
---|
114 | String = ShellCommandLineGetValue(Package, L"-w");
|
---|
115 | if (String != NULL) {
|
---|
116 | gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, StrSize(String), (VOID*)String);
|
---|
117 | } else {
|
---|
118 | gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
|
---|
119 | }
|
---|
120 | }
|
---|
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;
|
---|
125 | } else {
|
---|
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);
|
---|
130 | } else {
|
---|
131 | gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
|
---|
132 | }
|
---|
133 | }
|
---|
134 | } else {
|
---|
135 | //
|
---|
136 | // this is default so dont worry about flag...
|
---|
137 | //
|
---|
138 | String = ShellCommandLineGetValue(Package, L"-c");
|
---|
139 | if (String != NULL) {
|
---|
140 | gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, StrSize(String), (VOID*)String);
|
---|
141 | } else {
|
---|
142 | gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
|
---|
143 | }
|
---|
144 | }
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | //
|
---|
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...
|
---|
151 | //
|
---|
152 |
|
---|
153 | Error:
|
---|
154 | //
|
---|
155 | // free the command line package
|
---|
156 | //
|
---|
157 | ShellCommandLineFreeVarList (Package);
|
---|
158 |
|
---|
159 | //
|
---|
160 | // return the status
|
---|
161 | //
|
---|
162 | return (ShellStatus);
|
---|
163 | }
|
---|
164 |
|
---|