From 85cd2c97a0a3fe824ccf9247d51bb8d4077b06e1 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 4 May 2020 23:29:44 -0700 Subject: [PATCH] ams:bpc: allow programatically setting reboot payload --- libraries/libstratosphere/source/ams/ams_bpc.c | 2 +- libraries/libstratosphere/source/ams/ams_bpc.h | 2 +- .../libstratosphere/source/ams/ams_environment.cpp | 2 +- .../ams_mitm/source/bpc_mitm/bpc_ams_power_utils.cpp | 5 ++--- .../ams_mitm/source/bpc_mitm/bpc_ams_power_utils.hpp | 2 +- .../ams_mitm/source/bpc_mitm/bpc_ams_service.cpp | 10 ++++++---- .../ams_mitm/source/bpc_mitm/bpc_ams_service.hpp | 8 ++++---- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/libraries/libstratosphere/source/ams/ams_bpc.c b/libraries/libstratosphere/source/ams/ams_bpc.c index 8a3ddee4b..1a749dc02 100644 --- a/libraries/libstratosphere/source/ams/ams_bpc.c +++ b/libraries/libstratosphere/source/ams/ams_bpc.c @@ -51,7 +51,7 @@ Result amsBpcRebootToFatalError(void *ctx) { } -Result amsBpcSetInitialPayload(const void *src, size_t src_size) { +Result amsBpcSetRebootPayload(const void *src, size_t src_size) { return serviceDispatch(&g_amsBpcSrv, 65001, .buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcMapAlias }, .buffers = { { src, src_size } }, diff --git a/libraries/libstratosphere/source/ams/ams_bpc.h b/libraries/libstratosphere/source/ams/ams_bpc.h index d8a3a9ed2..93da63092 100644 --- a/libraries/libstratosphere/source/ams/ams_bpc.h +++ b/libraries/libstratosphere/source/ams/ams_bpc.h @@ -28,7 +28,7 @@ void amsBpcExit(void); Service *amsBpcGetServiceSession(void); Result amsBpcRebootToFatalError(void *ctx); -Result amsBpcSetInitialPayload(const void *src, size_t src_size); +Result amsBpcSetRebootPayload(const void *src, size_t src_size); #ifdef __cplusplus } diff --git a/libraries/libstratosphere/source/ams/ams_environment.cpp b/libraries/libstratosphere/source/ams/ams_environment.cpp index f4bc04199..47babfb92 100644 --- a/libraries/libstratosphere/source/ams/ams_environment.cpp +++ b/libraries/libstratosphere/source/ams/ams_environment.cpp @@ -41,7 +41,7 @@ namespace ams { } void SetInitialRebootPayload(const void *src, size_t src_size) { - R_ABORT_UNLESS(amsBpcSetInitialPayload(src, src_size)); + R_ABORT_UNLESS(amsBpcSetRebootPayload(src, src_size)); } void WEAK_SYMBOL ExceptionHandler(FatalErrorContext *ctx) { diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_power_utils.cpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_power_utils.cpp index 5ca66b265..cc15f63f8 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_power_utils.cpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_power_utils.cpp @@ -97,7 +97,7 @@ namespace ams::mitm::bpc { DoRebootToPayload(ctx); } - void SetInitialRebootPayload(const void *payload, size_t payload_size) { + void SetRebootPayload(const void *payload, size_t payload_size) { /* Clear payload buffer */ std::memset(g_reboot_payload, 0xCC, sizeof(g_reboot_payload)); @@ -107,9 +107,8 @@ namespace ams::mitm::bpc { /* Copy in payload. */ std::memcpy(g_reboot_payload, payload, payload_size); - /* NOTE: Preferred reboot type will be parsed from settings later on. */ + /* NOTE: Preferred reboot type may be overrwritten when parsed from settings during boot. */ g_reboot_type = RebootType::ToPayload; - } Result LoadRebootPayload() { diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_power_utils.hpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_power_utils.hpp index 0a2ae78bb..b75ae3e39 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_power_utils.hpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_power_utils.hpp @@ -24,7 +24,7 @@ namespace ams::mitm::bpc { void ShutdownSystem(); /* Atmosphere power utilities. */ - void SetInitialRebootPayload(const void *payload, size_t payload_size); + void SetRebootPayload(const void *payload, size_t payload_size); Result LoadRebootPayload(); Result DetectPreferredRebootFunctionality(); void RebootForFatalError(const ams::FatalErrorContext *ctx); diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.cpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.cpp index bd4f63313..79d6c27e1 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.cpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.cpp @@ -29,13 +29,15 @@ namespace ams::mitm::bpc { bpc::RebootForFatalError(&ctx); } - void AtmosphereService::SetInitialRebootPayload(const ams::sf::InBuffer &payload) { + void AtmosphereService::SetRebootPayload(const ams::sf::InBuffer &payload) { + /* Set the reboot payload. */ + bpc::SetRebootPayload(payload.GetPointer(), payload.GetSize()); + + /* If this is being called for the first time (by boot sysmodule), */ + /* Then we should kick off the rest of init. */ if (!g_set_initial_payload) { g_set_initial_payload = true; - /* Set the initial reboot payload. */ - bpc::SetInitialRebootPayload(payload.GetPointer(), payload.GetSize()); - /* Start the initialization process. */ ::ams::mitm::StartInitialize(); } diff --git a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp index 794235691..fb15dc540 100644 --- a/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp +++ b/stratosphere/ams_mitm/source/bpc_mitm/bpc_ams_service.hpp @@ -22,16 +22,16 @@ namespace ams::mitm::bpc { class AtmosphereService final : public sf::IServiceObject { private: enum class CommandId { - RebootToFatalError = 65000, - SetInitialRebootPayload = 65001, + RebootToFatalError = 65000, + SetRebootPayload = 65001, }; private: void RebootToFatalError(const ams::FatalErrorContext &ctx); - void SetInitialRebootPayload(const ams::sf::InBuffer &payload); + void SetRebootPayload(const ams::sf::InBuffer &payload); public: DEFINE_SERVICE_DISPATCH_TABLE { MAKE_SERVICE_COMMAND_META(RebootToFatalError), - MAKE_SERVICE_COMMAND_META(SetInitialRebootPayload), + MAKE_SERVICE_COMMAND_META(SetRebootPayload), }; };