From 8c54df039f266d9b1a7a59a9a07dd03ec5179e96 Mon Sep 17 00:00:00 2001 From: Lightos1 <124387232+Lightos1@users.noreply.github.com> Date: Sun, 26 Jul 2026 21:36:12 +0200 Subject: [PATCH] ldr: ifdef logging --- .../stratosphere/loader/source/oc/oc_common.hpp | 17 ++++++++++++++--- .../stratosphere/loader/source/oc/oc_log.cpp | 11 +++++++---- .../loader/source/oc/pcv/pcv_erista.cpp | 1 - .../loader/source/oc/pcv/pcv_mariko.cpp | 11 +++++++++-- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp b/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp index 8a9ef004..9ee12cca 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp @@ -28,11 +28,22 @@ #include "customize.hpp" #include "oc_log.hpp" -#if HOC_UART_LOG -#define LOGGING(fmt, ...) ::ams::ldr::hoc::UartLog(fmt, ##__VA_ARGS__) +#if ((!defined(HOC_UART_LOG)) && (defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING))) + #define HOC_IRAM_LOG 1 #else -#define LOGGING(fmt, ...) ((void)0) + #define HOC_IRAM_LOG 0 #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 PATCH_OFFSET(offset, value) \ diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/oc_log.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/oc_log.cpp index 27027e9a..4d5ed831 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/oc_log.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/oc_log.cpp @@ -19,7 +19,7 @@ #include "oc_common.hpp" -#if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING) +#ifdef HOC_IRAM_LOG #include "fatal_handler_bin.h" #endif @@ -70,6 +70,8 @@ namespace ams::ldr::hoc { return rc; } + #ifdef HOC_UART_LOG + /* Remove this? */ void UartLog(const char *fmt, ...) { char line[256]; constexpr size_t PrefixLen = 13; /* "[HOC] " */ @@ -92,6 +94,7 @@ namespace ams::ldr::hoc { svc::OutputDebugString(line, len); } + #endif struct log_ctx_t { u32 magic; @@ -104,7 +107,7 @@ namespace ams::ldr::hoc { #define IRAM_LOG_CTX_ADDR 0x4003C000 #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, ...) { static const u32 max_log_sz = sizeof(working_buf) - sizeof(log_ctx_t); static bool initDone = false; @@ -135,8 +138,8 @@ namespace ams::ldr::hoc { } #endif - #if defined(AMS_BUILD_FOR_AUDITING) || defined(AMS_BUILD_FOR_DEBUGGING) void ViewLog() { + #ifdef HOC_IRAM_LOG if (spl::GetSocType() == spl::SocType_Mariko) { return; } @@ -150,6 +153,6 @@ namespace ams::ldr::hoc { SmcRebootToIramPayload(); while(true) { } + #endif } - #endif } diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_erista.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_erista.cpp index d2460db3..12b0b1bd 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_erista.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_erista.cpp @@ -706,7 +706,6 @@ namespace ams::ldr::hoc::pcv::erista { for (auto &entry : patches) { LOGGING("%s Count: %zu\n", entry.description, entry.patched_count); if (R_FAILED(entry.CheckResult())) { - // ViewLog(); panic::SmcError(panic::Patch); CRASH(entry.description); diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_mariko.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_mariko.cpp index e8fce8c0..9afd0d88 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_mariko.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv_mariko.cpp @@ -636,6 +636,7 @@ namespace ams::ldr::hoc::pcv::mariko { return entry; } + #ifdef HOC_UART_LOG /* Redirect pcv's NvLog() calls to UART */ Result NvLogUartRedirect(u32 *ptr) { const uintptr_t mapped_nso = reinterpret_cast(nsoStart); @@ -756,6 +757,7 @@ namespace ams::ldr::hoc::pcv::mariko { nvlog_addr - mapped_nso, vsnprintf_addr - mapped_nso, helper - mapped_nso, n, patchedSites); R_SUCCEED(); } + #endif /* Relocate C2/C3Bus to avoid issues*/ Result BusFreqReloc(u32 *ptr) { @@ -795,17 +797,20 @@ namespace ams::ldr::hoc::pcv::mariko { PATCH_OFFSET(call, AsmMakeBl(reinterpret_cast(call), tramp)); const uintptr_t base = reinterpret_cast(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)", reinterpret_cast(call) - base, tramp - base, realFn - base, busReg, bufReg, bufOff, s[0], s[1], s[2]); R_SUCCEED(); } + #ifdef HOC_UART_LOG /* Force GetEffectiveVerbosityLevel to return a non-zero level so all NvLog runs. */ Result ForceVerbosity(u32 *ptr) { PATCH_OFFSET(&ptr[0], AsmMakeMovzW(0, static_cast(HOC_PCV_FORCE_VERBOSITY))); /* movz w0,#level */ PATCH_OFFSET(&ptr[1], RetIns); /* ret */ 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 */ Result EmcSocLutReloc(u32 *ptr) { @@ -1197,7 +1202,7 @@ namespace ams::ldr::hoc::pcv::mariko { const size_t dvbCount = std::min(newEmcList.size(), DvbTableCapacity); DvbEntry emcDvbTableOc[DvbTableCapacity] = {}; - + u32 bracketIndex = 0; for (size_t i = 0; i < dvbCount; ++i) { const u32 freq = (i == dvbCount - 1) ? static_cast(newEmcList.back()) : newEmcList[i]; @@ -1508,12 +1513,14 @@ namespace ams::ldr::hoc::pcv::mariko { { "EMC SoC LUT", &EmcSocLutReloc, 1, &EmcSocLutPatternFn }, { "EMC Rate List", &EmcRateListLimit, 0, &EmcRateListPatternFn }, { "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 Limit", &SocVoltLimit, 1, nullptr, SocVoltLimitOfficial }, /* Debugging patches */ + #ifdef HOC_UART_LOG { "NvLog Redirect", &NvLogUartRedirect, 1, &NvLogVsnprintfPatternFn, 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)) {