add kip detection
This commit is contained in:
@@ -24,10 +24,7 @@
|
||||
#define CRASH(msg, ...) { ams::diag::AbortImpl(msg, __PRETTY_FUNCTION__, "", 0); __builtin_unreachable(); }
|
||||
|
||||
#include "customize.hpp"
|
||||
|
||||
#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)
|
||||
#include "oc_log.hpp"
|
||||
#endif
|
||||
#include "oc_log.hpp"
|
||||
|
||||
#define PATCH_OFFSET(offset, value) \
|
||||
static_assert(sizeof(__typeof__(offset)) <= sizeof(u64)); \
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
namespace ams::ldr::hoc {
|
||||
|
||||
Result SmcCopyToIram(uintptr_t dest, const void *src, u32 size);
|
||||
void Log(const char *data, ...);
|
||||
void ViewLog();
|
||||
|
||||
|
||||
@@ -170,6 +170,12 @@ namespace ams::ldr::hoc::pcv {
|
||||
}
|
||||
}
|
||||
|
||||
void WriteKipLoadToIram() {
|
||||
const u32 hocMagic = 0x686F634D;
|
||||
constexpr uintptr_t LoadMagicAddress = 0x4003DC00 ; /* Should be a pretty safe address. */
|
||||
R_DISCARD(SmcCopyToIram(LoadMagicAddress, &hocMagic, sizeof(hocMagic)));
|
||||
}
|
||||
|
||||
void Patch(uintptr_t mapped_nso, size_t nso_size) {
|
||||
SafetyCheck();
|
||||
|
||||
@@ -179,6 +185,8 @@ namespace ams::ldr::hoc::pcv {
|
||||
} else {
|
||||
erista::Patch(mapped_nso, nso_size);
|
||||
}
|
||||
|
||||
WriteKipLoadToIram();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -81,9 +81,10 @@ typedef struct {
|
||||
u16 resolutionHeight;
|
||||
u8 custRev;
|
||||
u16 kipVersion;
|
||||
bool isKipLoaded;
|
||||
|
||||
// Reserved for future use
|
||||
u8 reserved[0x35B];
|
||||
u8 reserved[0x35A];
|
||||
} HocClkContext;
|
||||
|
||||
typedef struct
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
// tsl::elm::ListItem* custRevItem = NULL;
|
||||
tsl::elm::ListItem* kipVersionItem = NULL;
|
||||
tsl::elm::ListItem* kipLoadedItem = NULL;
|
||||
tsl::elm::ListItem* SpeedoItem = NULL;
|
||||
tsl::elm::ListItem* IddqItem = NULL;
|
||||
tsl::elm::ListItem* DramModule = NULL;
|
||||
@@ -155,6 +156,9 @@ void AboutGui::listUI()
|
||||
kipVersionItem = new tsl::elm::ListItem("KIP version:");
|
||||
this->listElement->addItem(kipVersionItem);
|
||||
|
||||
kipLoadedItem = new tsl::elm::ListItem("KIP status:");
|
||||
this->listElement->addItem(kipLoadedItem);
|
||||
|
||||
if(!IsHoag()) {
|
||||
sysdockStatusItem =
|
||||
new tsl::elm::ListItem("sys-dock status:");
|
||||
@@ -246,6 +250,8 @@ void AboutGui::refresh()
|
||||
// custRevItem->setValue(std::to_string(this->context->custRev));
|
||||
|
||||
kipVersionItem->setValue(std::to_string((this->context->kipVersion / 100) % 10) + "." + std::to_string((this->context->kipVersion / 10) % 10) + "." + std::to_string( this->context->kipVersion % 10) + " (Cust Rev " + std::to_string(this->context->custRev) + ")");
|
||||
kipLoadedItem->setValue(this->context->isKipLoaded ? "Loaded" : "Not Loaded");
|
||||
|
||||
if(!IsHoag())
|
||||
sysdockStatusItem->setValue(this->context->isSysDockInstalled ? "Installed" : "Not Installed");
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#include "../i2c/i2cDrv.h"
|
||||
#include "../mgr/clock_manager.hpp"
|
||||
#include "file_utils.hpp"
|
||||
#include "../mapping/mem_map.hpp"
|
||||
#include "kip.hpp"
|
||||
|
||||
|
||||
namespace kip {
|
||||
|
||||
bool kipAvailable = false;
|
||||
@@ -172,6 +172,24 @@ namespace kip {
|
||||
}
|
||||
}
|
||||
|
||||
bool IsKipLoaded() {
|
||||
constexpr u32 ExpectedMagic = 0x686F634D;
|
||||
constexpr uintptr_t LoadMagicAddress = 0x4003DC00;
|
||||
u32 iramValue = {};
|
||||
|
||||
SmcCopyFromIram(&iramValue, LoadMagicAddress, sizeof(iramValue));
|
||||
|
||||
if (iramValue == ExpectedMagic) {
|
||||
iramValue = 0;
|
||||
SmcCopyToIram(LoadMagicAddress, &iramValue, sizeof(iramValue));
|
||||
return true;
|
||||
}
|
||||
|
||||
notification::writeNotification("Kip is not loaded!");
|
||||
fileUtils::LogLine("Kip was not loaded!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// I know this is very hacky, but the config system in the sysmodule doesn't really support writing
|
||||
|
||||
void GetKipData() {
|
||||
@@ -231,6 +249,7 @@ namespace kip {
|
||||
return;
|
||||
}
|
||||
|
||||
clockManager::gContext.isKipLoaded = IsKipLoaded();
|
||||
clockManager::gContext.kipVersion = kipVersion;
|
||||
configValues.values[KipConfigValue_custRev] = cust_get_cust_rev(&table);
|
||||
configValues.values[KipConfigValue_KipVersion] = cust_get_kip_version(&table); // Run this after the check so we can do migration process
|
||||
@@ -350,4 +369,5 @@ namespace kip {
|
||||
}
|
||||
config::SetConfigValues(&configValues, true);
|
||||
}
|
||||
|
||||
} // namespace kip
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "../file/file_utils.hpp"
|
||||
|
||||
|
||||
Result QueryMemoryMapping(u64 *virtaddr, u64 physaddr, u64 size) {
|
||||
if (hosversionAtLeast(10, 0, 0)) {
|
||||
u64 out_size;
|
||||
@@ -37,3 +36,33 @@ Result MapAddress(u64 &va, const u64 &physAddr, const char *name) {
|
||||
|
||||
return mapResult;
|
||||
}
|
||||
|
||||
Result SmcCopyFromIram(void *dest, uintptr_t src, u32 size) {
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xF0000201;
|
||||
args.X[1] = (u64)dest;
|
||||
args.X[2] = (u64)src;
|
||||
args.X[3] = size;
|
||||
args.X[4] = 0;
|
||||
svcCallSecureMonitor(&args);
|
||||
Result rc = 0;
|
||||
if (args.X[0] != 0) {
|
||||
rc = (26u | ((u32)args.X[0] << 9u));
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result SmcCopyToIram(uintptr_t dest, const void *src, u32 size) {
|
||||
SecmonArgs args;
|
||||
args.X[0] = 0xF0000201;
|
||||
args.X[1] = (u64)src;
|
||||
args.X[2] = (u64)dest;
|
||||
args.X[3] = size;
|
||||
args.X[4] = 1;
|
||||
svcCallSecureMonitor(&args);
|
||||
Result rc = 0;
|
||||
if (args.X[0] != 0) {
|
||||
rc = (26u | ((u32)args.X[0] << 9u));
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -20,3 +20,5 @@
|
||||
|
||||
Result QueryMemoryMapping(u64 *virtaddr, u64 physaddr, u64 size);
|
||||
Result MapAddress(u64 &va, const u64 &physAddr, const char *name);
|
||||
Result SmcCopyFromIram(void *dest, uintptr_t src, u32 size);
|
||||
Result SmcCopyToIram(uintptr_t dest, const void *src, u32 size);
|
||||
|
||||
Reference in New Issue
Block a user