ResetSystem: Initial version

closes acidanthera/bugtracker#861
This commit is contained in:
vit9696 2020-04-20 13:12:06 +03:00
parent 19cae8046e
commit 3cd9ace60c
12 changed files with 193 additions and 3 deletions

View File

@ -0,0 +1,101 @@
/** @file
Play beep.
Copyright (c) 2020, vit9696. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcMiscLib.h>
#include <Library/UefiApplicationEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/DevicePath.h>
#include <Protocol/ShellParameters.h>
STATIC
EFI_STATUS
GetArguments (
OUT UINTN *Argc,
OUT CHAR16 ***Argv
)
{
EFI_STATUS Status;
EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters;
Status = gBS->HandleProtocol (
gImageHandle,
&gEfiShellParametersProtocolGuid,
(VOID**) &ShellParameters
);
if (EFI_ERROR (Status)) {
return Status;
}
*Argc = ShellParameters->Argc;
*Argv = ShellParameters->Argv;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
UefiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
UINTN Argc;
CHAR16 **Argv;
CHAR16 *Mode;
EFI_RESET_TYPE ResetMode;
Status = GetArguments (&Argc, &Argv);
if (!EFI_ERROR (Status) && Argc >= 2) {
Mode = Argv[1];
} else {
DEBUG ((DEBUG_INFO, "OCRST: Assuming default to be ResetCold...\n"));
Mode = L"ResetCold";
}
if (StrCmp (Mode, L"ColdReset") == 0) {
DEBUG ((DEBUG_INFO, "OCRST: Perform cold reset...\n"));
ResetMode = EfiResetCold;
} else if (StrCmp (Mode, L"WarmReset") == 0) {
DEBUG ((DEBUG_INFO, "OCRST: Perform warm reset...\n"));
ResetMode = EfiResetWarm;
} else if (StrCmp (Mode, L"Shutdown") == 0) {
DEBUG ((DEBUG_INFO, "OCRST: Perform shutdown...\n"));
ResetMode = EfiResetShutdown;
} else {
DEBUG ((DEBUG_INFO, "OCRST: Unknown argument %s, defaulting to cold reset...\n", Mode));
ResetMode = EfiResetCold;
}
gRT->ResetSystem (
ResetMode,
EFI_SUCCESS,
0,
NULL
);
DEBUG ((DEBUG_INFO, "OCRST: Failed to reset, trying direct\n"));
DirectRestCold ();
DEBUG ((DEBUG_INFO, "OCRST: Failed to reset directly, entering dead loop\n"));
CpuDeadLoop ();
return EFI_SUCCESS; //< Unreachable
}

View File

@ -0,0 +1,52 @@
## @file
# Reset system in some way.
#
# Copyright (c) 2020, vit9696. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = ResetSystem
FILE_GUID = E0CAD01B-51A1-4591-87FF-EA9216D431BD
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = UefiMain
#
# This flag specifies whether HII resource section is generated into PE image.
#
UEFI_HII_RESOURCE_SECTION = TRUE
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
ResetSystem.c
[Protocols]
gEfiShellParametersProtocolGuid
[Packages]
EfiPkg/EfiPkg.dec
MdePkg/MdePkg.dec
OpenCorePkg/OpenCorePkg.dec
[LibraryClasses]
BaseLib
DebugLib
OcMiscLib
UefiApplicationEntryPoint
UefiBootServicesTableLib
UefiRuntimeServicesTableLib
UefiLib

View File

@ -1,5 +1,5 @@
/** @file
Play beep.
RTC memory read/write.
Copyright (c) 2020, vit9696. All rights reserved.<BR>
This program and the accompanying materials

View File

@ -16,6 +16,7 @@ OpenCore Changelog
- Added `PatchAppleRtcChecksum` kernel quirk
- Added `AppleRtcRam` protocol implementation
- Renamed `Protocols` to `ProtocolOverrides` for clarity
- Added ResetSystem tool to allow shutdown/reset actions in the menu
#### v0.5.7
- Added TimeMachine detection to picker

Binary file not shown.

View File

@ -4044,6 +4044,9 @@ Some of the known tools are listed below (builtin tools are marked with \textbf{
with a broad range of firmwares. \\
\href{https://github.com/acidanthera/OpenCorePkg}{\texttt{PavpProvision}}
& Perform EPID provisioning (requires certificate data configuration). \\
\href{https://github.com/acidanthera/OpenCorePkg}{\texttt{ResetSystem}}\textbf{*}
& Utility to perform system reset. Takes reset type as an argument:
\texttt{ColdReset}, \texttt{WarmReset}, \texttt{Shutdown}. Defaults to \texttt{ColdReset}. \\
\href{https://github.com/acidanthera/OpenCorePkg}{\texttt{RtcRw}}\textbf{*}
& Utility to read and write RTC (CMOS) memory. \\
\href{https://github.com/acidanthera/OpenCorePkg}{\texttt{VerifyMsrE2}}\textbf{*}

Binary file not shown.

View File

@ -1,7 +1,7 @@
\documentclass[]{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL PreviousConfiguration.tex Tue Apr 7 19:32:13 2020
%DIF ADD ../Configuration.tex Mon Apr 20 09:29:28 2020
%DIF ADD ../Configuration.tex Mon Apr 20 13:11:07 2020
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
@ -4116,7 +4116,10 @@ Some of the known tools are listed below (builtin tools are marked with \textbf{
with a broad range of firmwares. \\
\href{https://github.com/acidanthera/OpenCorePkg}{\texttt{PavpProvision}}
& Perform EPID provisioning (requires certificate data configuration). \\
\DIFaddbegin \href{https://github.com/acidanthera/OpenCorePkg}{\texttt{RtcRw}}\textbf{\DIFadd{*}}
\DIFaddbegin \href{https://github.com/acidanthera/OpenCorePkg}{\texttt{ResetSystem}}\textbf{\DIFadd{*}}
& \DIFadd{Utility to perform system reset. Takes reset type as an argument:
}\texttt{\DIFadd{ColdReset}}\DIFadd{, }\texttt{\DIFadd{WarmReset}}\DIFadd{, }\texttt{\DIFadd{Shutdown}}\DIFadd{. Defaults to }\texttt{\DIFadd{ColdReset}}\DIFadd{. }\\
\href{https://github.com/acidanthera/OpenCorePkg}{\texttt{RtcRw}}\textbf{\DIFadd{*}}
& \DIFadd{Utility to read and write RTC (CMOS) memory. }\\
\DIFaddend \href{https://github.com/acidanthera/OpenCorePkg}{\texttt{VerifyMsrE2}}\textbf{*}
& Check \texttt{CFG Lock} (MSR \texttt{0xE2} write protection) consistency across all cores.

View File

@ -649,6 +649,20 @@
<key>Path</key>
<string>memcheck/memcheck.efi</string>
</dict>
<dict>
<key>Arguments</key>
<string>Shutdown</string>
<key>Auxiliary</key>
<true/>
<key>Comment</key>
<string>Perform shutdown</string>
<key>Enabled</key>
<false/>
<key>Name</key>
<string>Shutdown</string>
<key>Path</key>
<string>ResetSystem.efi</string>
</dict>
</array>
</dict>
<key>NVRAM</key>

View File

@ -649,6 +649,20 @@
<key>Path</key>
<string>memcheck/memcheck.efi</string>
</dict>
<dict>
<key>Arguments</key>
<string>Shutdown</string>
<key>Auxiliary</key>
<true/>
<key>Comment</key>
<string>Perform shutdown</string>
<key>Enabled</key>
<false/>
<key>Name</key>
<string>Shutdown</string>
<key>Path</key>
<string>ResetSystem.efi</string>
</dict>
</array>
</dict>
<key>NVRAM</key>

View File

@ -151,6 +151,7 @@
OpenCorePkg/Application/MmapDump/MmapDump.inf
OpenCorePkg/Application/OpenControl/OpenControl.inf
OpenCorePkg/Application/PavpProvision/PavpProvision.inf
OpenCorePkg/Application/ResetSystem/ResetSystem.inf
OpenCorePkg/Application/RtcRw/RtcRw.inf
OpenCorePkg/Application/VerifyMsrE2/VerifyMsrE2.inf
OpenCorePkg/Debug/GdbSyms/GdbSyms.inf

View File

@ -36,6 +36,7 @@ package() {
cp HiiDatabase.efi tmp/EFI/OC/Drivers/ || exit 1
cp KeyTester.efi tmp/EFI/OC/Tools/ || exit 1
cp MmapDump.efi tmp/EFI/OC/Tools/ || exit 1
cp ResetSystem.efi tmp/EFI/OC/Tools || exit 1
cp RtcRw.efi tmp/EFI/OC/Tools || exit 1
cp NvmExpressDxe.efi tmp/EFI/OC/Drivers/ || exit 1
cp OpenCanopy.efi tmp/EFI/OC/Drivers/ || exit 1