From af0cd34f922b75a710a9868fe0c1c03a41491a1f Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sun, 19 Jul 2020 20:32:22 +0300 Subject: [PATCH] l4t: Add panic dump (PSTORE) --- bdk/memory_map.h | 8 ++++++-- bdk/soc/pmc.h | 2 ++ bdk/utils/util.h | 3 ++- bootloader/main.c | 21 ++++++++++++++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/bdk/memory_map.h b/bdk/memory_map.h index f45269a..cac024f 100644 --- a/bdk/memory_map.h +++ b/bdk/memory_map.h @@ -41,8 +41,12 @@ /* --- Gap: 1040MB 0xA4000000 - 0xE4FFFFFF --- */ // Virtual disk / Chainloader buffers. -#define RAM_DISK_ADDR 0xA4000000 -#define RAM_DISK_SZ 0x41000000 // 1040MB. +#define RAM_DISK_ADDR 0xA4000000 +#define RAM_DISK_SZ 0x41000000 // 1040MB. + +// L4T Kernel Panic Storage (PSTORE). +#define PSTORE_ADDR 0xB0000000 +#define PSTORE_SZ 0x200000 // 2MB. //#define DRAM_LIB_ADDR 0xE0000000 /* --- Chnldr: 252MB 0xC03C0000 - 0xCFFFFFFF --- */ //! Only used when chainloading. diff --git a/bdk/soc/pmc.h b/bdk/soc/pmc.h index a736935..597e6cd 100644 --- a/bdk/soc/pmc.h +++ b/bdk/soc/pmc.h @@ -49,6 +49,8 @@ #define PMC_CRYPTO_OP_SE_ENABLE 0 #define PMC_CRYPTO_OP_SE_DISABLE 1 #define APBDEV_PMC_SCRATCH33 0x120 +#define APBDEV_PMC_SCRATCH37 0x130 +#define PMC_SCRATCH37_KERNEL_PANIC_FLAG (1 << 24) #define APBDEV_PMC_SCRATCH40 0x13C #define APBDEV_PMC_OSC_EDPD_OVER 0x1A4 #define PMC_OSC_EDPD_OVER_OSC_CTRL_OVER 0x400000 diff --git a/bdk/utils/util.h b/bdk/utils/util.h index 948e02c..39cddbf 100644 --- a/bdk/utils/util.h +++ b/bdk/utils/util.h @@ -32,7 +32,8 @@ typedef enum { ERR_LIBSYS_LP0 = (1 << 0), ERR_SYSOLD_NYX = (1 << 1), - ERR_SYSOLD_MTC = (1 << 2), + ERR_LIBSYS_MTC = (1 << 2), + ERR_L4T_KERNEL = (1 << 24), ERR_EXCEPT_ENB = (1 << 31), } hekate_errors_t; diff --git a/bootloader/main.c b/bootloader/main.c index a806462..517446d 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include "storage/emummc.h" @@ -1144,6 +1145,13 @@ static void _show_errors() if (*excp_enabled == EXCP_MAGIC) h_cfg.errors |= ERR_EXCEPT_ENB; + if (PMC(APBDEV_PMC_SCRATCH37) & PMC_SCRATCH37_KERNEL_PANIC_FLAG) + { + // Set error and clear flag. + h_cfg.errors |= ERR_L4T_KERNEL; + PMC(APBDEV_PMC_SCRATCH37) &= ~PMC_SCRATCH37_KERNEL_PANIC_FLAG; + } + if (h_cfg.errors) { gfx_clear_grey(0x1B); @@ -1152,10 +1160,10 @@ static void _show_errors() if (h_cfg.errors & ERR_LIBSYS_LP0) WPRINTF("Missing LP0 (sleep mode) lib!\n"); - if (h_cfg.errors & ERR_SYSOLD_MTC) + if (h_cfg.errors & ERR_LIBSYS_MTC) WPRINTF("Missing or old Minerva lib!\n"); - if (h_cfg.errors & ~ERR_EXCEPT_ENB) + if (h_cfg.errors & ~(ERR_EXCEPT_ENB | ERR_L4T_KERNEL)) { WPRINTF("\nUpdate bootloader folder!\n\n"); } @@ -1184,6 +1192,13 @@ static void _show_errors() *excp_enabled = 0; } + if (h_cfg.errors & ERR_L4T_KERNEL) + { + WPRINTF("Panic occurred while running L4T.\n"); + if (!sd_save_to_file((void *)PSTORE_ADDR, PSTORE_SZ, "L4T_panic.bin")) + WPRINTF("PSTORE saved to L4T_panic.bin\n"); + } + WPRINTF("Press any key..."); msleep(1000); @@ -1486,7 +1501,7 @@ void ipl_main() // Train DRAM and switch to max frequency. if (minerva_init()) - h_cfg.errors |= ERR_SYSOLD_MTC; + h_cfg.errors |= ERR_LIBSYS_MTC; display_init();