Fix previous commit, deinit screens on ARM9 exception, add check for write protect switch on writing operations
This commit is contained in:
parent
2a6a655804
commit
618ce671ac
@ -116,7 +116,10 @@ void __attribute__((noreturn)) mainHandler(u32 *regs, u32 type)
|
||||
//Copy header (actually optimized by the compiler)
|
||||
*(ExceptionDumpHeader *)FINAL_BUFFER = dumpHeader;
|
||||
|
||||
i2cWriteRegister(I2C_DEV_MCU, 0x22, 1 << 0); //Shutdown LCD
|
||||
|
||||
((void (*)())0xFFFF0830)(); //Ensure that all memory transfers have completed and that the data cache has been flushed
|
||||
|
||||
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); //Reboot
|
||||
while(true);
|
||||
}
|
||||
|
@ -395,12 +395,16 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
|
||||
for(u32 i = 0; i < singleOptionsAmount; i++)
|
||||
configData.config |= (singleOptions[i].enabled ? 1 : 0) << i;
|
||||
|
||||
writeConfig(true);
|
||||
|
||||
u32 newPinMode = MULTICONFIG(PIN);
|
||||
|
||||
if(newPinMode != 0) newPin(oldPinStatus && newPinMode == oldPinMode, newPinMode);
|
||||
else if(oldPinStatus) fileDelete(PIN_FILE);
|
||||
|
||||
writeConfig(true);
|
||||
else if(oldPinStatus)
|
||||
{
|
||||
if(!fileDelete(PIN_FILE))
|
||||
error("Unable to delete PIN file");
|
||||
}
|
||||
|
||||
while(HID_PAD & PIN_BUTTONS);
|
||||
wait(2000ULL);
|
||||
|
@ -30,11 +30,12 @@
|
||||
|
||||
#include "emunand.h"
|
||||
#include "memory.h"
|
||||
#include "utils.h"
|
||||
#include "fatfs/sdmmc/sdmmc.h"
|
||||
#include "../build/bundled.h"
|
||||
|
||||
u32 emuOffset,
|
||||
emuHeader;
|
||||
emuHeader = 0;
|
||||
|
||||
void locateEmuNand(FirmwareSource *nandType)
|
||||
{
|
||||
@ -76,7 +77,6 @@ void locateEmuNand(FirmwareSource *nandType)
|
||||
{
|
||||
emuOffset = nandOffset + 1;
|
||||
emuHeader = nandOffset + 1;
|
||||
return;
|
||||
}
|
||||
|
||||
//Check for Gateway EmuNAND
|
||||
@ -84,6 +84,14 @@ void locateEmuNand(FirmwareSource *nandType)
|
||||
{
|
||||
emuOffset = nandOffset;
|
||||
emuHeader = nandOffset + nandSize;
|
||||
}
|
||||
|
||||
if(emuHeader != 0)
|
||||
{
|
||||
//Make sure the SD card isn't write protected
|
||||
if((*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) == 0)
|
||||
error("The SD card is locked, EmuNAND can not be used.\nPlease turn the write protection switch off.");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ DRESULT disk_write (
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
return ((pdrv == SDCARD && !sdmmc_sdcard_writesectors(sector, count, buff)) ||
|
||||
return ((pdrv == SDCARD && (*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) != 0 && !sdmmc_sdcard_writesectors(sector, count, buff)) ||
|
||||
(pdrv == CTRNAND && !ctrNandWrite(sector, count, buff))) ? RES_OK : RES_PARERR;
|
||||
}
|
||||
#endif
|
||||
@ -91,12 +91,11 @@ DRESULT disk_write (
|
||||
DRESULT disk_ioctl (
|
||||
__attribute__((unused))
|
||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||
__attribute__((unused))
|
||||
BYTE cmd, /* Control code */
|
||||
__attribute__((unused))
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
return RES_PARERR;
|
||||
return cmd == CTRL_SYNC ? RES_OK : RES_PARERR;
|
||||
}
|
||||
#endif
|
||||
|
20
source/fs.c
20
source/fs.c
@ -51,8 +51,7 @@ static bool switchToMainDir(bool isSd)
|
||||
case FR_OK:
|
||||
return true;
|
||||
case FR_NO_PATH:
|
||||
f_mkdir(mainDir);
|
||||
return switchToMainDir(isSd);
|
||||
return f_mkdir(mainDir) == FR_OK && switchToMainDir(isSd);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -88,17 +87,18 @@ u32 getFileSize(const char *path)
|
||||
bool fileWrite(const void *buffer, const char *path, u32 size)
|
||||
{
|
||||
FIL file;
|
||||
FRESULT result;
|
||||
|
||||
switch(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS))
|
||||
{
|
||||
case FR_OK:
|
||||
{
|
||||
unsigned int written;
|
||||
f_write(&file, buffer, size, &written);
|
||||
f_truncate(&file);
|
||||
f_close(&file);
|
||||
result = f_write(&file, buffer, size, &written);
|
||||
if(result == FR_OK) result = f_truncate(&file);
|
||||
result |= f_close(&file);
|
||||
|
||||
return (u32)written == size;
|
||||
return result == FR_OK && (u32)written == size;
|
||||
}
|
||||
case FR_NO_PATH:
|
||||
for(u32 i = 1; path[i] != 0; i++)
|
||||
@ -107,18 +107,18 @@ bool fileWrite(const void *buffer, const char *path, u32 size)
|
||||
char folder[i + 1];
|
||||
memcpy(folder, path, i);
|
||||
folder[i] = 0;
|
||||
f_mkdir(folder);
|
||||
result = f_mkdir(folder);
|
||||
}
|
||||
|
||||
return fileWrite(buffer, path, size);
|
||||
return result == FR_OK && fileWrite(buffer, path, size);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void fileDelete(const char *path)
|
||||
bool fileDelete(const char *path)
|
||||
{
|
||||
f_unlink(path);
|
||||
return f_unlink(path) == FR_OK;
|
||||
}
|
||||
|
||||
bool findPayload(char *path, u32 pressed)
|
||||
|
@ -34,7 +34,7 @@ bool mountFs(bool isSd, bool switchToCtrNand);
|
||||
u32 fileRead(void *dest, const char *path, u32 maxSize);
|
||||
u32 getFileSize(const char *path);
|
||||
bool fileWrite(const void *buffer, const char *path, u32 size);
|
||||
void fileDelete(const char *path);
|
||||
bool fileDelete(const char *path);
|
||||
bool findPayload(char *path, u32 pressed);
|
||||
bool payloadMenu(char *path);
|
||||
u32 firmRead(void *dest, u32 firmType);
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "crypto.h"
|
||||
#include "memory.h"
|
||||
#include "screen.h"
|
||||
#include "fatfs/sdmmc/sdmmc.h"
|
||||
|
||||
extern CfgData configData;
|
||||
extern ConfigurationStatus needConfig;
|
||||
@ -309,12 +308,6 @@ 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);
|
||||
|
@ -106,12 +106,12 @@ void mcuPowerOff(void)
|
||||
{
|
||||
if(bootType != FIRMLAUNCH && ARESCREENSINITIALIZED) clearScreens(false);
|
||||
|
||||
//Shutdown LCD
|
||||
i2cWriteRegister(I2C_DEV_MCU, 0x22, 1 << 0);
|
||||
|
||||
//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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user