From 598edc0a46bd52442a44f1d00065fb4edf319ce1 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 1 Sep 2021 18:25:36 -0700 Subject: [PATCH] fusee_cpp: move mtc code/used-tables to nv memory (needed for mariko downtrain fix) --- fusee_cpp/program/program_ovl.ld | 16 ++++++---------- fusee_cpp/program/source/mtc/fusee_mtc.cpp | 10 ++++++---- .../program/source/mtc/fusee_mtc_erista.cpp | 15 +++++++++------ .../program/source/mtc/fusee_mtc_mariko.cpp | 8 ++++---- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/fusee_cpp/program/program_ovl.ld b/fusee_cpp/program/program_ovl.ld index 0f73539c8..24262fe33 100644 --- a/fusee_cpp/program/program_ovl.ld +++ b/fusee_cpp/program/program_ovl.ld @@ -23,21 +23,17 @@ SECTIONS { BYTE(0x00); } .ovl_mtc_erista { - KEEP(*(.text._ZN3ams6nxboot22DoMemoryTrainingEristaEi)) - fusee_mtc_erista.o(.text*); - fusee_mtc_erista.o(.rodata*); - fusee_mtc_erista.o(.data*); - fusee_mtc_erista.o(.bss*); + fusee_mtc_erista.o(SORT(.rodata*)); + fusee_mtc_erista.o(SORT(.data*)); + fusee_mtc_erista.o(SORT(.bss*)); FILL(0x00000000) . = ORIGIN(ovl) + LENGTH(ovl) - 1; BYTE(0x00); } .ovl_mtc_mariko { - KEEP(*(.text._ZN3ams6nxboot22DoMemoryTrainingMarikoEi)) - fusee_mtc_mariko.o(.text*); - fusee_mtc_mariko.o(.rodata*); - fusee_mtc_mariko.o(.data*); - fusee_mtc_mariko.o(.bss*); + fusee_mtc_mariko.o(SORT(.rodata*)); + fusee_mtc_mariko.o(SORT(.data*)); + fusee_mtc_mariko.o(SORT(.bss*)); FILL(0x00000000) . = ORIGIN(ovl) + LENGTH(ovl) - 1; BYTE(0x00); diff --git a/fusee_cpp/program/source/mtc/fusee_mtc.cpp b/fusee_cpp/program/source/mtc/fusee_mtc.cpp index 8d8596546..0bbeafe36 100644 --- a/fusee_cpp/program/source/mtc/fusee_mtc.cpp +++ b/fusee_cpp/program/source/mtc/fusee_mtc.cpp @@ -17,11 +17,13 @@ namespace ams::nxboot { - void DoMemoryTrainingErista(int index); - void DoMemoryTrainingMariko(int index); + void DoMemoryTrainingErista(int index, void *mtc_tables_buffer); + void DoMemoryTrainingMariko(int index, void *mtc_tables_buffer); namespace { + alignas(4) constinit u8 g_mtc_tables_buffer[0x26C0]; + constexpr const u8 MemoryTrainingTableIndex_Invalid = std::numeric_limits::max(); constexpr const u8 MemoryTrainingTableIndices[] = { @@ -70,9 +72,9 @@ namespace ams::nxboot { const auto index = GetMemoryTrainingTableIndex(); if (fuse::GetSocType() == fuse::SocType_Erista) { - DoMemoryTrainingErista(index); + DoMemoryTrainingErista(index, g_mtc_tables_buffer); } else { - DoMemoryTrainingMariko(index); + DoMemoryTrainingMariko(index, g_mtc_tables_buffer); } } diff --git a/fusee_cpp/program/source/mtc/fusee_mtc_erista.cpp b/fusee_cpp/program/source/mtc/fusee_mtc_erista.cpp index d723854b9..beeab491b 100644 --- a/fusee_cpp/program/source/mtc/fusee_mtc_erista.cpp +++ b/fusee_cpp/program/source/mtc/fusee_mtc_erista.cpp @@ -72,15 +72,18 @@ namespace ams::nxboot { using EmcDvfsTimingTable = erista::EmcDvfsTimingTable; - EmcDvfsTimingTable *GetEmcDvfsTimingTables(int index) { + EmcDvfsTimingTable *GetEmcDvfsTimingTables(int index, void *mtc_tables_buffer) { switch (index) { case 0: case 3: - return reinterpret_cast(T210SdevEmcDvfsTableS4gb01); + std::memcpy(mtc_tables_buffer, T210SdevEmcDvfsTableS4gb01, sizeof(T210SdevEmcDvfsTableS4gb01)); + return reinterpret_cast(mtc_tables_buffer); case 1: - return reinterpret_cast(T210SdevEmcDvfsTableS6gb01); + std::memcpy(mtc_tables_buffer, T210SdevEmcDvfsTableS6gb01, sizeof(T210SdevEmcDvfsTableS6gb01)); + return reinterpret_cast(mtc_tables_buffer); case 2: - return reinterpret_cast(T210SdevEmcDvfsTableH4gb01); + std::memcpy(mtc_tables_buffer, T210SdevEmcDvfsTableH4gb01, sizeof(T210SdevEmcDvfsTableH4gb01)); + return reinterpret_cast(mtc_tables_buffer); default: ShowFatalError("Unknown EmcDvfsTimingTableIndex: %d\n", index); } @@ -2829,9 +2832,9 @@ namespace ams::nxboot { } - void DoMemoryTrainingErista(int index) { + void DoMemoryTrainingErista(int index, void *mtc_tables_buffer) { /* Get timing tables. */ - auto *timing_tables = GetEmcDvfsTimingTables(index); + auto *timing_tables = GetEmcDvfsTimingTables(index, mtc_tables_buffer); auto *src_timing = timing_tables + 0; auto *dst_timing = timing_tables + 1; diff --git a/fusee_cpp/program/source/mtc/fusee_mtc_mariko.cpp b/fusee_cpp/program/source/mtc/fusee_mtc_mariko.cpp index 8ce16623c..0980d4eaa 100644 --- a/fusee_cpp/program/source/mtc/fusee_mtc_mariko.cpp +++ b/fusee_cpp/program/source/mtc/fusee_mtc_mariko.cpp @@ -27,7 +27,7 @@ namespace ams::nxboot { using EmcDvfsTimingTable = mariko::EmcDvfsTimingTable; - EmcDvfsTimingTable *GetEmcDvfsTimingTables(int index) { + EmcDvfsTimingTable *GetEmcDvfsTimingTables(int index, void *mtc_tables_buffer) { /* Get the compressed table. */ u8 *cmp_table; size_t cmp_table_size; @@ -55,7 +55,7 @@ namespace ams::nxboot { } /* Uncompress the table. */ - EmcDvfsTimingTable *out_tables = reinterpret_cast(0x40040000 - 2 * sizeof(EmcDvfsTimingTable)); + EmcDvfsTimingTable *out_tables = reinterpret_cast(mtc_tables_buffer); Uncompress(out_tables, 2 * sizeof(EmcDvfsTimingTable), cmp_table, cmp_table_size); return out_tables; @@ -63,9 +63,9 @@ namespace ams::nxboot { } - void DoMemoryTrainingMariko(int index) { + void DoMemoryTrainingMariko(int index, void *mtc_tables_buffer) { /* Get timing tables. */ - auto *timing_tables = GetEmcDvfsTimingTables(index); + auto *timing_tables = GetEmcDvfsTimingTables(index, mtc_tables_buffer); auto *src_timing_tables = timing_tables + 0; auto *dst_timing_tables = timing_tables + 1;