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)
|
//Copy header (actually optimized by the compiler)
|
||||||
*(ExceptionDumpHeader *)FINAL_BUFFER = dumpHeader;
|
*(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
|
((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
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); //Reboot
|
||||||
while(true);
|
while(true);
|
||||||
}
|
}
|
||||||
|
@ -395,12 +395,16 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
|
|||||||
for(u32 i = 0; i < singleOptionsAmount; i++)
|
for(u32 i = 0; i < singleOptionsAmount; i++)
|
||||||
configData.config |= (singleOptions[i].enabled ? 1 : 0) << i;
|
configData.config |= (singleOptions[i].enabled ? 1 : 0) << i;
|
||||||
|
|
||||||
|
writeConfig(true);
|
||||||
|
|
||||||
u32 newPinMode = MULTICONFIG(PIN);
|
u32 newPinMode = MULTICONFIG(PIN);
|
||||||
|
|
||||||
if(newPinMode != 0) newPin(oldPinStatus && newPinMode == oldPinMode, newPinMode);
|
if(newPinMode != 0) newPin(oldPinStatus && newPinMode == oldPinMode, newPinMode);
|
||||||
else if(oldPinStatus) fileDelete(PIN_FILE);
|
else if(oldPinStatus)
|
||||||
|
{
|
||||||
writeConfig(true);
|
if(!fileDelete(PIN_FILE))
|
||||||
|
error("Unable to delete PIN file");
|
||||||
|
}
|
||||||
|
|
||||||
while(HID_PAD & PIN_BUTTONS);
|
while(HID_PAD & PIN_BUTTONS);
|
||||||
wait(2000ULL);
|
wait(2000ULL);
|
||||||
|
@ -30,11 +30,12 @@
|
|||||||
|
|
||||||
#include "emunand.h"
|
#include "emunand.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "utils.h"
|
||||||
#include "fatfs/sdmmc/sdmmc.h"
|
#include "fatfs/sdmmc/sdmmc.h"
|
||||||
#include "../build/bundled.h"
|
#include "../build/bundled.h"
|
||||||
|
|
||||||
u32 emuOffset,
|
u32 emuOffset,
|
||||||
emuHeader;
|
emuHeader = 0;
|
||||||
|
|
||||||
void locateEmuNand(FirmwareSource *nandType)
|
void locateEmuNand(FirmwareSource *nandType)
|
||||||
{
|
{
|
||||||
@ -76,7 +77,6 @@ void locateEmuNand(FirmwareSource *nandType)
|
|||||||
{
|
{
|
||||||
emuOffset = nandOffset + 1;
|
emuOffset = nandOffset + 1;
|
||||||
emuHeader = nandOffset + 1;
|
emuHeader = nandOffset + 1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for Gateway EmuNAND
|
//Check for Gateway EmuNAND
|
||||||
@ -84,6 +84,14 @@ void locateEmuNand(FirmwareSource *nandType)
|
|||||||
{
|
{
|
||||||
emuOffset = nandOffset;
|
emuOffset = nandOffset;
|
||||||
emuHeader = nandOffset + nandSize;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ DRESULT disk_write (
|
|||||||
UINT count /* Number of sectors to 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;
|
(pdrv == CTRNAND && !ctrNandWrite(sector, count, buff))) ? RES_OK : RES_PARERR;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -91,12 +91,11 @@ DRESULT disk_write (
|
|||||||
DRESULT disk_ioctl (
|
DRESULT disk_ioctl (
|
||||||
__attribute__((unused))
|
__attribute__((unused))
|
||||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
BYTE pdrv, /* Physical drive nmuber (0..) */
|
||||||
__attribute__((unused))
|
|
||||||
BYTE cmd, /* Control code */
|
BYTE cmd, /* Control code */
|
||||||
__attribute__((unused))
|
__attribute__((unused))
|
||||||
void *buff /* Buffer to send/receive control data */
|
void *buff /* Buffer to send/receive control data */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return RES_PARERR;
|
return cmd == CTRL_SYNC ? RES_OK : RES_PARERR;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
20
source/fs.c
20
source/fs.c
@ -51,8 +51,7 @@ static bool switchToMainDir(bool isSd)
|
|||||||
case FR_OK:
|
case FR_OK:
|
||||||
return true;
|
return true;
|
||||||
case FR_NO_PATH:
|
case FR_NO_PATH:
|
||||||
f_mkdir(mainDir);
|
return f_mkdir(mainDir) == FR_OK && switchToMainDir(isSd);
|
||||||
return switchToMainDir(isSd);
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -88,17 +87,18 @@ u32 getFileSize(const char *path)
|
|||||||
bool fileWrite(const void *buffer, const char *path, u32 size)
|
bool fileWrite(const void *buffer, const char *path, u32 size)
|
||||||
{
|
{
|
||||||
FIL file;
|
FIL file;
|
||||||
|
FRESULT result;
|
||||||
|
|
||||||
switch(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS))
|
switch(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS))
|
||||||
{
|
{
|
||||||
case FR_OK:
|
case FR_OK:
|
||||||
{
|
{
|
||||||
unsigned int written;
|
unsigned int written;
|
||||||
f_write(&file, buffer, size, &written);
|
result = f_write(&file, buffer, size, &written);
|
||||||
f_truncate(&file);
|
if(result == FR_OK) result = f_truncate(&file);
|
||||||
f_close(&file);
|
result |= f_close(&file);
|
||||||
|
|
||||||
return (u32)written == size;
|
return result == FR_OK && (u32)written == size;
|
||||||
}
|
}
|
||||||
case FR_NO_PATH:
|
case FR_NO_PATH:
|
||||||
for(u32 i = 1; path[i] != 0; i++)
|
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];
|
char folder[i + 1];
|
||||||
memcpy(folder, path, i);
|
memcpy(folder, path, i);
|
||||||
folder[i] = 0;
|
folder[i] = 0;
|
||||||
f_mkdir(folder);
|
result = f_mkdir(folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileWrite(buffer, path, size);
|
return result == FR_OK && fileWrite(buffer, path, size);
|
||||||
default:
|
default:
|
||||||
return false;
|
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)
|
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 fileRead(void *dest, const char *path, u32 maxSize);
|
||||||
u32 getFileSize(const char *path);
|
u32 getFileSize(const char *path);
|
||||||
bool fileWrite(const void *buffer, const char *path, u32 size);
|
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 findPayload(char *path, u32 pressed);
|
||||||
bool payloadMenu(char *path);
|
bool payloadMenu(char *path);
|
||||||
u32 firmRead(void *dest, u32 firmType);
|
u32 firmRead(void *dest, u32 firmType);
|
||||||
|
@ -37,7 +37,6 @@
|
|||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "fatfs/sdmmc/sdmmc.h"
|
|
||||||
|
|
||||||
extern CfgData configData;
|
extern CfgData configData;
|
||||||
extern ConfigurationStatus needConfig;
|
extern ConfigurationStatus needConfig;
|
||||||
@ -309,12 +308,6 @@ boot:
|
|||||||
if(nandType == FIRMWARE_SYSNAND) firmSource = FIRMWARE_SYSNAND;
|
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
|
//Same if we're using EmuNAND as the FIRM source
|
||||||
else if(firmSource != FIRMWARE_SYSNAND)
|
else if(firmSource != FIRMWARE_SYSNAND)
|
||||||
locateEmuNand(&firmSource);
|
locateEmuNand(&firmSource);
|
||||||
|
@ -106,12 +106,12 @@ void mcuPowerOff(void)
|
|||||||
{
|
{
|
||||||
if(bootType != FIRMLAUNCH && ARESCREENSINITIALIZED) clearScreens(false);
|
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
|
//Ensure that all memory transfers have completed and that the data cache has been flushed
|
||||||
flushEntireDCache();
|
flushEntireDCache();
|
||||||
|
|
||||||
//Deinitialize the screens
|
|
||||||
deinitScreens();
|
|
||||||
|
|
||||||
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 0);
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 0);
|
||||||
while(true);
|
while(true);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user