diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_customize.inc b/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_customize.inc index e74e9acc..cbb05b67 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_customize.inc +++ b/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_customize.inc @@ -55,8 +55,10 @@ static const volatile CustomizeTable C = { * - Graphical glitches * - System instabilities * - NAND corruption - * - RAM Voltage in mV - * Default(HOS): 1125 + * - RAM Voltage in uV + * Range: 600'000 to 1250'000 uV + * Value should be divided evenly by 12'500 + * Default(HOS): 1125'000 * Not enabled by default. */ .eristaEmcMaxClock = 1862400, diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_suite.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_suite.cpp index 5b4f583f..5dcf03dd 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_suite.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_suite.cpp @@ -1027,8 +1027,13 @@ namespace ams::ldr::oc { } Result MemVoltHandler(u32* ptr) { - if (C.eristaEmcVolt) - PatchOffset(ptr, C.eristaEmcVolt); + u32 emc_uv = C.eristaEmcVolt; + if (emc_uv) { + constexpr u32 uv_step = 12'500; + if (emc_uv % uv_step) + emc_uv = emc_uv / uv_step * uv_step; + PatchOffset(ptr, emc_uv); + } return ResultSuccess(); } @@ -1103,10 +1108,18 @@ namespace ams::ldr::oc { } namespace pcv { - void Patch(uintptr_t mapped_nso, size_t nso_size) { - if (C.custRev != CUST_REV) { + void SafetyCheck() { + if ( C.custRev != CUST_REV + || C.marikoCpuMaxVolt >= 1300 + || C.eristaCpuMaxVolt >= 1400 + || (C.eristaEmcVolt && (C.eristaEmcVolt < 600'000 || C.eristaEmcVolt > 1250'000))) + { CRASH(); } + } + + void Patch(uintptr_t mapped_nso, size_t nso_size) { + SafetyCheck(); #ifdef OC_TEST void* buf = malloc(nso_size); diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_suite_test.hpp b/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_suite_test.hpp index 3a334652..3d095f0b 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_suite_test.hpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/ldr_oc_suite_test.hpp @@ -12,8 +12,9 @@ typedef uint64_t u64; typedef int Result; #define R_SUCCEEDED(arg) (arg == ResultSuccess()) +#define R_FAILED(arg) (!R_SUCCEEDED(arg)) #define LOGGING(fmt, ...) { printf(fmt "\n\tin %s\n", ##__VA_ARGS__, __PRETTY_FUNCTION__); } -#define AMS_ABORT() { fprintf(stderr, "Failed!\n"); exit(-1); } +#define AMS_ABORT() { fprintf(stderr, "Failed in %s!\n", __PRETTY_FUNCTION__); exit(-1); } inline Result ResultSuccess() { return 0; } @@ -30,7 +31,7 @@ namespace ams::ldr::oc { .eristaCpuOCEnable = 1, .eristaCpuMaxVolt = 1300, .eristaEmcMaxClock = 1862400, - .eristaEmcVolt = 1250, + .eristaEmcVolt = 1200'000, .eristaMtc = reinterpret_cast(const_cast(EmptyMtcTable)), }; }