ldr: ifdef logging
This commit is contained in:
@@ -28,11 +28,22 @@
|
|||||||
#include "customize.hpp"
|
#include "customize.hpp"
|
||||||
#include "oc_log.hpp"
|
#include "oc_log.hpp"
|
||||||
|
|
||||||
#if HOC_UART_LOG
|
#if ((!defined(HOC_UART_LOG)) && (defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)))
|
||||||
#define LOGGING(fmt, ...) ::ams::ldr::hoc::UartLog(fmt, ##__VA_ARGS__)
|
#define HOC_IRAM_LOG 1
|
||||||
#else
|
#else
|
||||||
#define LOGGING(fmt, ...) ((void)0)
|
#define HOC_IRAM_LOG 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)
|
||||||
|
#if defined(HOC_IRAM_LOG)
|
||||||
|
#define LOGGING(...) Log(__VA_ARGS__)
|
||||||
|
#else if defined(HOC_UART_LOG)
|
||||||
|
#define LOGGING(...) AMS_LOG(__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define LOGGING(...) ((void)0)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CRASH(msg, ...) { ams::diag::AbortImpl(msg, __PRETTY_FUNCTION__, "", 0); __builtin_unreachable(); }
|
#define CRASH(msg, ...) { ams::diag::AbortImpl(msg, __PRETTY_FUNCTION__, "", 0); __builtin_unreachable(); }
|
||||||
|
|
||||||
#define PATCH_OFFSET(offset, value) \
|
#define PATCH_OFFSET(offset, value) \
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "oc_common.hpp"
|
#include "oc_common.hpp"
|
||||||
|
|
||||||
#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)
|
#ifdef HOC_IRAM_LOG
|
||||||
#include "fatal_handler_bin.h"
|
#include "fatal_handler_bin.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -70,6 +70,8 @@ namespace ams::ldr::hoc {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HOC_UART_LOG
|
||||||
|
/* Remove this? */
|
||||||
void UartLog(const char *fmt, ...) {
|
void UartLog(const char *fmt, ...) {
|
||||||
char line[256];
|
char line[256];
|
||||||
constexpr size_t PrefixLen = 13; /* "[HOC] " */
|
constexpr size_t PrefixLen = 13; /* "[HOC] " */
|
||||||
@@ -92,6 +94,7 @@ namespace ams::ldr::hoc {
|
|||||||
|
|
||||||
svc::OutputDebugString(line, len);
|
svc::OutputDebugString(line, len);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct log_ctx_t {
|
struct log_ctx_t {
|
||||||
u32 magic;
|
u32 magic;
|
||||||
@@ -104,7 +107,7 @@ namespace ams::ldr::hoc {
|
|||||||
#define IRAM_LOG_CTX_ADDR 0x4003C000
|
#define IRAM_LOG_CTX_ADDR 0x4003C000
|
||||||
#define IRAM_LOG_MAX_SZ 4096
|
#define IRAM_LOG_MAX_SZ 4096
|
||||||
|
|
||||||
#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)
|
#ifdef HOC_IRAM_LOG
|
||||||
void Log(const char *data, ...) {
|
void Log(const char *data, ...) {
|
||||||
static const u32 max_log_sz = sizeof(working_buf) - sizeof(log_ctx_t);
|
static const u32 max_log_sz = sizeof(working_buf) - sizeof(log_ctx_t);
|
||||||
static bool initDone = false;
|
static bool initDone = false;
|
||||||
@@ -135,8 +138,8 @@ namespace ams::ldr::hoc {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING)
|
|
||||||
void ViewLog() {
|
void ViewLog() {
|
||||||
|
#ifdef HOC_IRAM_LOG
|
||||||
if (spl::GetSocType() == spl::SocType_Mariko) {
|
if (spl::GetSocType() == spl::SocType_Mariko) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -150,6 +153,6 @@ namespace ams::ldr::hoc {
|
|||||||
SmcRebootToIramPayload();
|
SmcRebootToIramPayload();
|
||||||
|
|
||||||
while(true) { }
|
while(true) { }
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -706,7 +706,6 @@ namespace ams::ldr::hoc::pcv::erista {
|
|||||||
for (auto &entry : patches) {
|
for (auto &entry : patches) {
|
||||||
LOGGING("%s Count: %zu\n", entry.description, entry.patched_count);
|
LOGGING("%s Count: %zu\n", entry.description, entry.patched_count);
|
||||||
if (R_FAILED(entry.CheckResult())) {
|
if (R_FAILED(entry.CheckResult())) {
|
||||||
// ViewLog();
|
|
||||||
panic::SmcError(panic::Patch);
|
panic::SmcError(panic::Patch);
|
||||||
|
|
||||||
CRASH(entry.description);
|
CRASH(entry.description);
|
||||||
|
|||||||
@@ -636,6 +636,7 @@ namespace ams::ldr::hoc::pcv::mariko {
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HOC_UART_LOG
|
||||||
/* Redirect pcv's NvLog() calls to UART */
|
/* Redirect pcv's NvLog() calls to UART */
|
||||||
Result NvLogUartRedirect(u32 *ptr) {
|
Result NvLogUartRedirect(u32 *ptr) {
|
||||||
const uintptr_t mapped_nso = reinterpret_cast<uintptr_t>(nsoStart);
|
const uintptr_t mapped_nso = reinterpret_cast<uintptr_t>(nsoStart);
|
||||||
@@ -756,6 +757,7 @@ namespace ams::ldr::hoc::pcv::mariko {
|
|||||||
nvlog_addr - mapped_nso, vsnprintf_addr - mapped_nso, helper - mapped_nso, n, patchedSites);
|
nvlog_addr - mapped_nso, vsnprintf_addr - mapped_nso, helper - mapped_nso, n, patchedSites);
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Relocate C2/C3Bus to avoid issues*/
|
/* Relocate C2/C3Bus to avoid issues*/
|
||||||
Result BusFreqReloc(u32 *ptr) {
|
Result BusFreqReloc(u32 *ptr) {
|
||||||
@@ -795,17 +797,20 @@ namespace ams::ldr::hoc::pcv::mariko {
|
|||||||
|
|
||||||
PATCH_OFFSET(call, AsmMakeBl(reinterpret_cast<uintptr_t>(call), tramp));
|
PATCH_OFFSET(call, AsmMakeBl(reinterpret_cast<uintptr_t>(call), tramp));
|
||||||
const uintptr_t base = reinterpret_cast<uintptr_t>(nsoStart);
|
const uintptr_t base = reinterpret_cast<uintptr_t>(nsoStart);
|
||||||
|
(void) base;
|
||||||
LOGGING("BusFreqReloc: call@+%lx -> tramp@+%lx realfn@+%lx (bus=x%u buf=x%u off=0x%x scratch=x%u,x%u,x%u)",
|
LOGGING("BusFreqReloc: call@+%lx -> tramp@+%lx realfn@+%lx (bus=x%u buf=x%u off=0x%x scratch=x%u,x%u,x%u)",
|
||||||
reinterpret_cast<uintptr_t>(call) - base, tramp - base, realFn - base, busReg, bufReg, bufOff, s[0], s[1], s[2]);
|
reinterpret_cast<uintptr_t>(call) - base, tramp - base, realFn - base, busReg, bufReg, bufOff, s[0], s[1], s[2]);
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HOC_UART_LOG
|
||||||
/* Force GetEffectiveVerbosityLevel to return a non-zero level so all NvLog runs. */
|
/* Force GetEffectiveVerbosityLevel to return a non-zero level so all NvLog runs. */
|
||||||
Result ForceVerbosity(u32 *ptr) {
|
Result ForceVerbosity(u32 *ptr) {
|
||||||
PATCH_OFFSET(&ptr[0], AsmMakeMovzW(0, static_cast<u16>(HOC_PCV_FORCE_VERBOSITY))); /* movz w0,#level */
|
PATCH_OFFSET(&ptr[0], AsmMakeMovzW(0, static_cast<u16>(HOC_PCV_FORCE_VERBOSITY))); /* movz w0,#level */
|
||||||
PATCH_OFFSET(&ptr[1], RetIns); /* ret */
|
PATCH_OFFSET(&ptr[1], RetIns); /* ret */
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Widen InitDram for a >32-entry EMC DVFS list. Freq array can be dropped to free 264 bytes, relocate the Soc LUT to that space */
|
/* Widen InitDram for a >32-entry EMC DVFS list. Freq array can be dropped to free 264 bytes, relocate the Soc LUT to that space */
|
||||||
Result EmcSocLutReloc(u32 *ptr) {
|
Result EmcSocLutReloc(u32 *ptr) {
|
||||||
@@ -1197,7 +1202,7 @@ namespace ams::ldr::hoc::pcv::mariko {
|
|||||||
|
|
||||||
const size_t dvbCount = std::min(newEmcList.size(), DvbTableCapacity);
|
const size_t dvbCount = std::min(newEmcList.size(), DvbTableCapacity);
|
||||||
DvbEntry emcDvbTableOc[DvbTableCapacity] = {};
|
DvbEntry emcDvbTableOc[DvbTableCapacity] = {};
|
||||||
|
|
||||||
u32 bracketIndex = 0;
|
u32 bracketIndex = 0;
|
||||||
for (size_t i = 0; i < dvbCount; ++i) {
|
for (size_t i = 0; i < dvbCount; ++i) {
|
||||||
const u32 freq = (i == dvbCount - 1) ? static_cast<u32>(newEmcList.back()) : newEmcList[i];
|
const u32 freq = (i == dvbCount - 1) ? static_cast<u32>(newEmcList.back()) : newEmcList[i];
|
||||||
@@ -1508,12 +1513,14 @@ namespace ams::ldr::hoc::pcv::mariko {
|
|||||||
{ "EMC SoC LUT", &EmcSocLutReloc, 1, &EmcSocLutPatternFn },
|
{ "EMC SoC LUT", &EmcSocLutReloc, 1, &EmcSocLutPatternFn },
|
||||||
{ "EMC Rate List", &EmcRateListLimit, 0, &EmcRateListPatternFn },
|
{ "EMC Rate List", &EmcRateListLimit, 0, &EmcRateListPatternFn },
|
||||||
{ "EMC Rate Sess", &EmcRateSessLimit, 1, &EmcRateSessPatternFn },
|
{ "EMC Rate Sess", &EmcRateSessLimit, 1, &EmcRateSessPatternFn },
|
||||||
{ "Bus Freq Reloc", &BusFreqReloc, 1, &BusFreqRelocPatternFn },
|
{ "Bus Freq Reloc", &BusFreqReloc, 1, &BusFreqRelocPatternFn },
|
||||||
{ "SOC Volt Asm", &SocVoltAsm, 1, &SocVoltPatternFn },
|
{ "SOC Volt Asm", &SocVoltAsm, 1, &SocVoltPatternFn },
|
||||||
{ "SOC Volt Limit", &SocVoltLimit, 1, nullptr, SocVoltLimitOfficial },
|
{ "SOC Volt Limit", &SocVoltLimit, 1, nullptr, SocVoltLimitOfficial },
|
||||||
/* Debugging patches */
|
/* Debugging patches */
|
||||||
|
#ifdef HOC_UART_LOG
|
||||||
{ "NvLog Redirect", &NvLogUartRedirect, 1, &NvLogVsnprintfPatternFn, 0, 0, true },
|
{ "NvLog Redirect", &NvLogUartRedirect, 1, &NvLogVsnprintfPatternFn, 0, 0, true },
|
||||||
{ "Force Verbosity", &ForceVerbosity, 3, &ForceVerbosityPatternFn, 0, 0, true },
|
{ "Force Verbosity", &ForceVerbosity, 3, &ForceVerbosityPatternFn, 0, 0, true },
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
for (uintptr_t ptr = mapped_nso; ptr <= mapped_nso + nso_size - sizeof(MarikoMtcTable); ptr += sizeof(u32)) {
|
for (uintptr_t ptr = mapped_nso; ptr <= mapped_nso + nso_size - sizeof(MarikoMtcTable); ptr += sizeof(u32)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user