From 97d94180cff0e0f2fd185a2feac609e68268ed03 Mon Sep 17 00:00:00 2001 From: SciresM Date: Mon, 1 Mar 2021 14:18:27 -0800 Subject: [PATCH] set.mitm: fake compatibility for usb!usb30_force_enabled on 9.0.0+ (#1391) * set.mitm: fake compatibility for usb!usb30_force_enabled on 9.0.0+ * set.mitm: add value meaning comment for usb!usb30_force_enabled * loader: pretend to be polite about patch ordering --- .../secmon/secmon_monitor_context.hpp | 2 + .../include/stratosphere/spl/spl_api.hpp | 4 ++ .../include/stratosphere/spl/spl_types.hpp | 40 ++++++++++--------- libstratosphere/source/boot2/boot2_api.cpp | 15 ++++++- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/libexosphere/include/exosphere/secmon/secmon_monitor_context.hpp b/libexosphere/include/exosphere/secmon/secmon_monitor_context.hpp index 6c974b1c..1bfcfb95 100644 --- a/libexosphere/include/exosphere/secmon/secmon_monitor_context.hpp +++ b/libexosphere/include/exosphere/secmon/secmon_monitor_context.hpp @@ -29,6 +29,7 @@ namespace ams::secmon { SecureMonitorConfigurationFlag_EnableUserModePerformanceCounterAccess = (1u << 4), SecureMonitorConfigurationFlag_ShouldUseBlankCalibrationBinary = (1u << 5), SecureMonitorConfigurationFlag_AllowWritingToCalibrationBinarySysmmc = (1u << 6), + SecureMonitorConfigurationFlag_ForceEnableUsb30 = (1u << 7), SecureMonitorConfigurationFlag_Default = SecureMonitorConfigurationFlag_IsDevelopmentFunctionEnabledForKernel, }; @@ -101,6 +102,7 @@ namespace ams::secmon { constexpr bool EnableUserModePerformanceCounterAccess() const { return (this->flags[0] & SecureMonitorConfigurationFlag_EnableUserModePerformanceCounterAccess) != 0; } constexpr bool ShouldUseBlankCalibrationBinary() const { return (this->flags[0] & SecureMonitorConfigurationFlag_ShouldUseBlankCalibrationBinary) != 0; } constexpr bool AllowWritingToCalibrationBinarySysmmc() const { return (this->flags[0] & SecureMonitorConfigurationFlag_AllowWritingToCalibrationBinarySysmmc) != 0; } + constexpr bool IsUsb30ForceEnabled() const { return (this->flags[0] & SecureMonitorConfigurationFlag_ForceEnableUsb30) != 0; } constexpr bool IsDevelopmentFunctionEnabled(bool for_kern) const { return for_kern ? this->IsDevelopmentFunctionEnabledForKernel() : this->IsDevelopmentFunctionEnabledForUser(); } }; diff --git a/libstratosphere/include/stratosphere/spl/spl_api.hpp b/libstratosphere/include/stratosphere/spl/spl_api.hpp index 506290b3..f38a0d1e 100644 --- a/libstratosphere/include/stratosphere/spl/spl_api.hpp +++ b/libstratosphere/include/stratosphere/spl/spl_api.hpp @@ -78,6 +78,10 @@ namespace ams::spl { return ::ams::spl::GetConfigBool(::ams::spl::ConfigItem::DisableProgramVerification); } + inline bool IsUsb30ForceEnabled() { + return ::ams::spl::GetConfigBool(::ams::spl::ConfigItem::ExosphereForceEnableUsb30); + } + Result SetBootReason(BootReasonValue boot_reason); Result GetBootReason(BootReasonValue *out); diff --git a/libstratosphere/include/stratosphere/spl/spl_types.hpp b/libstratosphere/include/stratosphere/spl/spl_types.hpp index 3e1f2d74..fa510ab5 100644 --- a/libstratosphere/include/stratosphere/spl/spl_types.hpp +++ b/libstratosphere/include/stratosphere/spl/spl_types.hpp @@ -223,26 +223,30 @@ namespace ams::spl { Package2Hash = 17, /* Extension config items for exosphere. */ - ExosphereApiVersion = 65000, - ExosphereNeedsReboot = 65001, - ExosphereNeedsShutdown = 65002, - ExosphereGitCommitHash = 65003, - ExosphereHasRcmBugPatch = 65004, - ExosphereBlankProdInfo = 65005, - ExosphereAllowCalWrites = 65006, - ExosphereEmummcType = 65007, - ExospherePayloadAddress = 65008, + ExosphereApiVersion = 65000, + ExosphereNeedsReboot = 65001, + ExosphereNeedsShutdown = 65002, + ExosphereGitCommitHash = 65003, + ExosphereHasRcmBugPatch = 65004, + ExosphereBlankProdInfo = 65005, + ExosphereAllowCalWrites = 65006, + ExosphereEmummcType = 65007, + ExospherePayloadAddress = 65008, + ExosphereLogConfiguration = 65009, + ExosphereForceEnableUsb30 = 65010, }; } /* Extensions to libnx spl config item enum. */ -constexpr inline SplConfigItem SplConfigItem_ExosphereApiVersion = static_cast(65000); -constexpr inline SplConfigItem SplConfigItem_ExosphereNeedsReboot = static_cast(65001); -constexpr inline SplConfigItem SplConfigItem_ExosphereNeedsShutdown = static_cast(65002); -constexpr inline SplConfigItem SplConfigItem_ExosphereGitCommitHash = static_cast(65003); -constexpr inline SplConfigItem SplConfigItem_ExosphereHasRcmBugPatch = static_cast(65004); -constexpr inline SplConfigItem SplConfigItem_ExosphereBlankProdInfo = static_cast(65005); -constexpr inline SplConfigItem SplConfigItem_ExosphereAllowCalWrites = static_cast(65006); -constexpr inline SplConfigItem SplConfigItem_ExosphereEmummcType = static_cast(65007); -constexpr inline SplConfigItem SplConfigItem_ExospherePayloadAddress = static_cast(65008); +constexpr inline SplConfigItem SplConfigItem_ExosphereApiVersion = static_cast(65000); +constexpr inline SplConfigItem SplConfigItem_ExosphereNeedsReboot = static_cast(65001); +constexpr inline SplConfigItem SplConfigItem_ExosphereNeedsShutdown = static_cast(65002); +constexpr inline SplConfigItem SplConfigItem_ExosphereGitCommitHash = static_cast(65003); +constexpr inline SplConfigItem SplConfigItem_ExosphereHasRcmBugPatch = static_cast(65004); +constexpr inline SplConfigItem SplConfigItem_ExosphereBlankProdInfo = static_cast(65005); +constexpr inline SplConfigItem SplConfigItem_ExosphereAllowCalWrites = static_cast(65006); +constexpr inline SplConfigItem SplConfigItem_ExosphereEmummcType = static_cast(65007); +constexpr inline SplConfigItem SplConfigItem_ExospherePayloadAddress = static_cast(65008); +constexpr inline SplConfigItem SplConfigItem_ExosphereLogConfiguration = static_cast(65009); +constexpr inline SplConfigItem SplConfigItem_ExosphereForceEnableUsb30 = static_cast(65010); diff --git a/libstratosphere/source/boot2/boot2_api.cpp b/libstratosphere/source/boot2/boot2_api.cpp index a9bddc42..6e2879b8 100644 --- a/libstratosphere/source/boot2/boot2_api.cpp +++ b/libstratosphere/source/boot2/boot2_api.cpp @@ -307,6 +307,10 @@ namespace ams::boot2 { }); } + bool IsUsbRequiredToMountSdCard() { + return hos::GetVersion() >= hos::Version_9_0_0; + } + } /* Boot2 API. */ @@ -347,8 +351,10 @@ namespace ams::boot2 { /* Launch pcv. */ LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Pcv, ncm::StorageId::BuiltInSystem), 0); - /* Launch usb. */ - LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Usb, ncm::StorageId::BuiltInSystem), 0); + /* On 9.0.0+, FS depends on the USB sysmodule having been launched in order to mount the SD card. */ + if (IsUsbRequiredToMountSdCard()) { + LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Usb, ncm::StorageId::BuiltInSystem), 0); + } } /* Wait for the SD card required services to be ready. */ @@ -371,6 +377,11 @@ namespace ams::boot2 { void LaunchPostSdCardBootPrograms() { /* This code is normally run by boot2. */ + /* Launch the usb system module, if we haven't already. */ + if (!IsUsbRequiredToMountSdCard()) { + LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Usb, ncm::StorageId::BuiltInSystem), 0); + } + /* Find out whether we are maintenance mode. */ const bool maintenance = IsMaintenanceMode(); if (maintenance) {