• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 - 2012, 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   {NULL, TypeMax}
23   };
24 
25 /**
26   Function for 'reset' command.
27 
28   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
29   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
30 **/
31 SHELL_STATUS
32 EFIAPI
ShellCommandRunReset(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)33 ShellCommandRunReset (
34   IN EFI_HANDLE        ImageHandle,
35   IN EFI_SYSTEM_TABLE  *SystemTable
36   )
37 {
38   EFI_STATUS    Status;
39   LIST_ENTRY    *Package;
40   CONST CHAR16  *String;
41   CHAR16        *ProblemParam;
42   SHELL_STATUS  ShellStatus;
43 
44   ShellStatus = SHELL_SUCCESS;
45   ProblemParam = NULL;
46 
47   //
48   // initialize the shell lib (we must be in non-auto-init...)
49   //
50   Status = ShellInitialize();
51   ASSERT_EFI_ERROR(Status);
52 
53   //
54   // parse the command line
55   //
56   Status = ShellCommandLineParse (ResetParamList, &Package, &ProblemParam, TRUE);
57   if (EFI_ERROR(Status)) {
58     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
59       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"reset", ProblemParam);
60       FreePool(ProblemParam);
61       return (SHELL_INVALID_PARAMETER);
62     } else {
63       ASSERT(FALSE);
64     }
65   } else {
66     //
67     // check for "-?"
68     //
69     if (ShellCommandLineGetFlag(Package, L"-?")) {
70       ASSERT(FALSE);
71     } else if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
72       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
73       ShellStatus = SHELL_INVALID_PARAMETER;
74     } else {
75       //
76       // check for warm reset flag, then shutdown reset flag, then cold (default) reset flag
77       //
78       if (ShellCommandLineGetFlag(Package, L"-w")) {
79         if (ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-c")) {
80           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
81           ShellStatus = SHELL_INVALID_PARAMETER;
82         } else {
83           String = ShellCommandLineGetValue(Package, L"-w");
84           if (String != NULL) {
85             gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, StrSize(String), (VOID*)String);
86           } else {
87             gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
88           }
89         }
90       } else if (ShellCommandLineGetFlag(Package, L"-s")) {
91         if (ShellCommandLineGetFlag(Package, L"-c")) {
92           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
93           ShellStatus = SHELL_INVALID_PARAMETER;
94         } else {
95           String = ShellCommandLineGetValue(Package, L"-s");
96           DEBUG_CODE(ShellPrintEx(-1,-1,L"Reset with %s (%d bytes)", String, String!=NULL?StrSize(String):0););
97           if (String != NULL) {
98             gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, StrSize(String), (VOID*)String);
99           } else {
100             gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
101           }
102         }
103       } else {
104         //
105         // this is default so dont worry about flag...
106         //
107         String = ShellCommandLineGetValue(Package, L"-c");
108         if (String != NULL) {
109           gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, StrSize(String), (VOID*)String);
110         } else {
111           gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
112         }
113       }
114     }
115   }
116 
117   //
118   // we should never get here... so the free and return are for formality more than use
119   // as the ResetSystem function should not return...
120   //
121 
122   //
123   // free the command line package
124   //
125   ShellCommandLineFreeVarList (Package);
126 
127   //
128   // return the status
129   //
130   return (ShellStatus);
131 }
132 
133