Erista EMC volt in uV; Add safety checks (voltage and cust)

This commit is contained in:
KazushiM
2022-02-07 02:04:19 +08:00
parent c3432281da
commit 1421586391
3 changed files with 24 additions and 8 deletions

View File

@@ -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,

View File

@@ -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);

View File

@@ -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<EristaMtcTable *>(const_cast<u8 *>(EmptyMtcTable)),
};
}