Forbid writing to SD if write locked

This commit is contained in:
windows-server-2003 2018-02-27 16:53:45 +09:00 committed by d0k3
parent 915437dac0
commit 3c7ad93d1c
3 changed files with 15 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include "image.h"
#include "unittype.h"
#include "ui.h"
#include "sdmmc.h"
#define PATH_SYS_LVL1 "S:/twln.bin", "S:/twlp.bin"
#define PATH_SYS_LVL2 "1:/rw/sys/LocalFriendCodeSeed_B", "1:/rw/sys/LocalFriendCodeSeed_A", \
@ -26,6 +27,12 @@ bool CheckWritePermissions(const char* path) {
if ((drvtype & DRV_IMAGE) && !CheckWritePermissions(GetMountPath()))
return false; // endless loop when mounted file inside image, but not possible
// SD card write protection check
if ((drvtype & (DRV_SDCARD | DRV_EMUNAND | DRV_ALIAS)) && SD_WRITE_PROTECTED) {
ShowPrompt(false, "SD card is write protected!\nCan't continue.");
return false;
}
// check drive type, get permission type
if (drvtype & DRV_SYSNAND) {
u32 perms[] = { PERM_SYS_LVL0, PERM_SYS_LVL1, PERM_SYS_LVL2, PERM_SYS_LVL3 };

View File

@ -49,6 +49,12 @@ bool FormatSDCard(u64 hidden_mb, u32 cluster_size, const char* label) {
return false;
}
// Write protection check
if (SD_WRITE_PROTECTED) {
ShowPrompt(false, "SD card is write protected!\nCan't continue.");
return false;
}
// build the MBR
memcpy(mbrdata + 0x08, &fat_sector, 4);
memcpy(mbrdata + 0x0C, &fat_size, 4);

View File

@ -74,6 +74,8 @@
#define TMIO_MASK_READOP (TMIO_STAT1_RXRDY | TMIO_STAT1_DATAEND)
#define TMIO_MASK_WRITEOP (TMIO_STAT1_TXRQ | TMIO_STAT1_DATAEND)
#define SD_WRITE_PROTECTED (!((*(volatile u16*) (SDMMC_BASE + 0x1C)) & (0x1 << 7)))
typedef struct mmcdevice {
u8 *rData;
const u8 *tData;