mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-18 01:46:47 +00:00
pm: add support for maintenance mode
This commit is contained in:
parent
24f74312f2
commit
8a73ad996a
3 changed files with 48 additions and 3 deletions
|
@ -25,6 +25,7 @@
|
||||||
#include <stratosphere.hpp>
|
#include <stratosphere.hpp>
|
||||||
#include "pm_boot2.hpp"
|
#include "pm_boot2.hpp"
|
||||||
#include "pm_registration.hpp"
|
#include "pm_registration.hpp"
|
||||||
|
#include "pm_boot_mode.hpp"
|
||||||
|
|
||||||
static std::vector<Boot2KnownTitleId> g_boot2_titles;
|
static std::vector<Boot2KnownTitleId> g_boot2_titles;
|
||||||
|
|
||||||
|
@ -86,8 +87,41 @@ static void LaunchTitle(Boot2KnownTitleId title_id, FsStorageId storage_id, u32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ShouldForceMaintenanceMode() {
|
static bool GetGpioPadLow(GpioPadName pad) {
|
||||||
/* TODO: Contact set:sys, retrieve boot!force_maintenance, read plus/minus buttons. */
|
GpioPadSession button;
|
||||||
|
if (R_FAILED(gpioOpenSession(&button, pad))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure we close even on early return. */
|
||||||
|
ON_SCOPE_EXIT { gpioPadClose(&button); };
|
||||||
|
|
||||||
|
/* Set direction input. */
|
||||||
|
gpioPadSetDirection(&button, GpioDirection_Input);
|
||||||
|
|
||||||
|
GpioValue val;
|
||||||
|
return R_SUCCEEDED(gpioPadGetValue(&button, &val)) && val == GpioValue_Low;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsMaintenanceMode() {
|
||||||
|
/* Contact set:sys, retrieve boot!force_maintenance. */
|
||||||
|
if (R_SUCCEEDED(setsysInitialize())) {
|
||||||
|
ON_SCOPE_EXIT { setsysExit(); };
|
||||||
|
|
||||||
|
u8 force_maintenance = 1;
|
||||||
|
setsysGetSettingsItemValue("boot", "force_maintenance", &force_maintenance, sizeof(force_maintenance));
|
||||||
|
if (force_maintenance != 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Contact GPIO, read plus/minus buttons. */
|
||||||
|
if (R_SUCCEEDED(gpioInitialize())) {
|
||||||
|
ON_SCOPE_EXIT { gpioExit(); };
|
||||||
|
|
||||||
|
return GetGpioPadLow(GpioPadName_ButtonVolUp) && GetGpioPadLow(GpioPadName_ButtonVolDown);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +219,12 @@ void EmbeddedBoot2::Main() {
|
||||||
/* At this point, the SD card can be mounted. */
|
/* At this point, the SD card can be mounted. */
|
||||||
MountSdCard();
|
MountSdCard();
|
||||||
|
|
||||||
|
/* Find out whether we are maintenance mode. */
|
||||||
|
bool maintenance = IsMaintenanceMode();
|
||||||
|
if (maintenance) {
|
||||||
|
BootModeService::SetMaintenanceBootForEmbeddedBoot2();
|
||||||
|
}
|
||||||
|
|
||||||
/* Launch set:mitm, wait for it. */
|
/* Launch set:mitm, wait for it. */
|
||||||
LaunchTitle(Boot2KnownTitleId::ams_set_mitm, FsStorageId_None, 0, NULL);
|
LaunchTitle(Boot2KnownTitleId::ams_set_mitm, FsStorageId_None, 0, NULL);
|
||||||
WaitForMitm("set:sys");
|
WaitForMitm("set:sys");
|
||||||
|
@ -195,7 +235,6 @@ void EmbeddedBoot2::Main() {
|
||||||
LaunchTitle(Boot2KnownTitleId::tma, FsStorageId_NandSystem, 0, NULL);
|
LaunchTitle(Boot2KnownTitleId::tma, FsStorageId_NandSystem, 0, NULL);
|
||||||
|
|
||||||
/* Launch default programs. */
|
/* Launch default programs. */
|
||||||
bool maintenance = ShouldForceMaintenanceMode();
|
|
||||||
for (auto &launch_program : g_additional_launch_programs) {
|
for (auto &launch_program : g_additional_launch_programs) {
|
||||||
if (!maintenance || std::get<bool>(launch_program)) {
|
if (!maintenance || std::get<bool>(launch_program)) {
|
||||||
LaunchTitle(std::get<Boot2KnownTitleId>(launch_program), FsStorageId_NandSystem, 0, NULL);
|
LaunchTitle(std::get<Boot2KnownTitleId>(launch_program), FsStorageId_NandSystem, 0, NULL);
|
||||||
|
|
|
@ -27,3 +27,7 @@ void BootModeService::GetBootMode(Out<u32> out) {
|
||||||
void BootModeService::SetMaintenanceBoot() {
|
void BootModeService::SetMaintenanceBoot() {
|
||||||
g_is_maintenance_boot = true;
|
g_is_maintenance_boot = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BootModeService::SetMaintenanceBootForEmbeddedBoot2() {
|
||||||
|
g_is_maintenance_boot = true;
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ class BootModeService final : public IServiceObject {
|
||||||
/* Actual commands. */
|
/* Actual commands. */
|
||||||
void GetBootMode(Out<u32> out);
|
void GetBootMode(Out<u32> out);
|
||||||
void SetMaintenanceBoot();
|
void SetMaintenanceBoot();
|
||||||
|
public:
|
||||||
|
static void SetMaintenanceBootForEmbeddedBoot2();
|
||||||
public:
|
public:
|
||||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||||
MakeServiceCommandMeta<BootMode_Cmd_GetBootMode, &BootModeService::GetBootMode>(),
|
MakeServiceCommandMeta<BootMode_Cmd_GetBootMode, &BootModeService::GetBootMode>(),
|
||||||
|
|
Loading…
Reference in a new issue