From 7c61e935ee2139667f1338ca1e216a665801ca31 Mon Sep 17 00:00:00 2001 From: hexkyz Date: Wed, 14 Nov 2018 21:12:36 +0000 Subject: [PATCH] exosphere: Fix virtual mapping of MC_SECURITY_CFG3. Allow DRAM magic test value to be written on < 4.0.0. --- exosphere/src/bootup.c | 18 ++++++++---------- exosphere/src/mc.h | 3 +++ exosphere/src/warmboot_init.c | 2 +- exosphere/src/warmboot_main.c | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/exosphere/src/bootup.c b/exosphere/src/bootup.c index 82c009837..e2bbbbee3 100644 --- a/exosphere/src/bootup.c +++ b/exosphere/src/bootup.c @@ -49,15 +49,13 @@ static bool g_has_booted_up = false; void setup_dram_magic_numbers(void) { /* These DRAM writes test and set values for the GPU UCODE carveout. */ unsigned int target_fw = exosphere_get_target_firmware(); - if (EXOSPHERE_TARGET_FIRMWARE_400 <= target_fw) { - (*(volatile uint32_t *)(0x8005FFFC)) = 0xC0EDBBCC; /* Access test value. */ - flush_dcache_range((void *)0x8005FFFC, (void *)0x80060000); - if (EXOSPHERE_TARGET_FIRMWARE_600 <= target_fw) { - (*(volatile uint32_t *)(0x8005FF00)) = 0x00000083; /* SKU code. */ - (*(volatile uint32_t *)(0x8005FF04)) = 0x00000002; - (*(volatile uint32_t *)(0x8005FF08)) = 0x00000210; /* Tegra210 code. */ - flush_dcache_range((void *)0x8005FF00, (void *)0x8005FF0C); - } + (*(volatile uint32_t *)(0x8005FFFC)) = 0xC0EDBBCC; /* Access test value. */ + flush_dcache_range((void *)0x8005FFFC, (void *)0x80060000); + if (EXOSPHERE_TARGET_FIRMWARE_600 <= target_fw) { + (*(volatile uint32_t *)(0x8005FF00)) = 0x00000083; /* SKU code. */ + (*(volatile uint32_t *)(0x8005FF04)) = 0x00000002; + (*(volatile uint32_t *)(0x8005FF08)) = 0x00000210; /* Tegra210 code. */ + flush_dcache_range((void *)0x8005FF00, (void *)0x8005FF0C); } __dsb_sy(); } @@ -82,7 +80,7 @@ void bootup_misc_mmio(void) { se_generate_random_key(KEYSLOT_SWITCH_SRKGENKEY, KEYSLOT_SWITCH_RNGKEY); se_generate_srk(KEYSLOT_SWITCH_SRKGENKEY); - if (!g_has_booted_up && EXOSPHERE_TARGET_FIRMWARE_600 > exosphere_get_target_firmware() && exosphere_get_target_firmware() >= EXOSPHERE_TARGET_FIRMWARE_400) { + if (!g_has_booted_up && (EXOSPHERE_TARGET_FIRMWARE_600 > exosphere_get_target_firmware())) { setup_dram_magic_numbers(); } diff --git a/exosphere/src/mc.h b/exosphere/src/mc.h index 04e199e8d..6d467d655 100644 --- a/exosphere/src/mc.h +++ b/exosphere/src/mc.h @@ -493,6 +493,9 @@ static inline uintptr_t get_mc_base(void) { #define MC_ERR_APB_ASID_UPDATE_STATUS 0x9d0 #define MC_DA_CONFIG0 0x9dc +/* Virtual aliases */ +#define VIRT_MC_SECURITY_CFG3 MAKE_MC_REG(MC_SECURITY_CFG3) + /* Memory Controller clients */ #define CLIENT_ACCESS_NUM_CLIENTS 32 typedef enum { diff --git a/exosphere/src/warmboot_init.c b/exosphere/src/warmboot_init.c index 678879aba..6a22294a4 100644 --- a/exosphere/src/warmboot_init.c +++ b/exosphere/src/warmboot_init.c @@ -199,7 +199,7 @@ void warmboot_init(void) { invalidate_icache_all(); /* On warmboot (not cpu_on) only */ - if (MC_SECURITY_CFG3 == 0) { + if (VIRT_MC_SECURITY_CFG3 == 0) { init_dma_controllers(g_exosphere_target_firmware_for_init); } diff --git a/exosphere/src/warmboot_main.c b/exosphere/src/warmboot_main.c index 04f1afb03..8ee15c4fd 100644 --- a/exosphere/src/warmboot_main.c +++ b/exosphere/src/warmboot_main.c @@ -54,7 +54,7 @@ void __attribute__((noreturn)) warmboot_main(void) { identity_unmap_iram_cd_tzram(); /* On warmboot (not cpu_on) only */ - if (MC_SECURITY_CFG3 == 0) { + if (VIRT_MC_SECURITY_CFG3 == 0) { if (!configitem_is_retail()) { /* TODO: uart_log("OHAYO"); */ }