From 2a6a655804fd541ee4f9cc356e662013afe12235 Mon Sep 17 00:00:00 2001 From: Hikari-chin Date: Sun, 27 Aug 2017 16:20:17 -0400 Subject: [PATCH] Error if emuNAND is booted while the SD card is write protected --- source/main.c | 7 +++++++ source/utils.c | 3 +++ 2 files changed, 10 insertions(+) diff --git a/source/main.c b/source/main.c index 5c1d258..dae36d0 100644 --- a/source/main.c +++ b/source/main.c @@ -37,6 +37,7 @@ #include "crypto.h" #include "memory.h" #include "screen.h" +#include "fatfs/sdmmc/sdmmc.h" extern CfgData configData; extern ConfigurationStatus needConfig; @@ -308,6 +309,12 @@ boot: if(nandType == FIRMWARE_SYSNAND) firmSource = FIRMWARE_SYSNAND; } + //If we're using EmuNAND, make sure the SD card isn't write protected + if(nandType != FIRMWARE_SYSNAND && (*(vu16*)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) == 0) + { + error("The SD card is locked, EmuNAND can not be used.\n\nPlease turn the write protection switch off."); + } + //Same if we're using EmuNAND as the FIRM source else if(firmSource != FIRMWARE_SYSNAND) locateEmuNand(&firmSource); diff --git a/source/utils.c b/source/utils.c index 3725864..e133e6f 100644 --- a/source/utils.c +++ b/source/utils.c @@ -109,6 +109,9 @@ void mcuPowerOff(void) //Ensure that all memory transfers have completed and that the data cache has been flushed flushEntireDCache(); + //Deinitialize the screens + deinitScreens(); + i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 0); while(true); }