From 3d0b566c3d0283fe94d0761243fc31ccf8ed10c5 Mon Sep 17 00:00:00 2001 From: Extrems Date: Thu, 3 Oct 2024 19:39:53 -0400 Subject: [PATCH] Enable CRC verification on SD card --- gc/sdcard/card_io.h | 1 + libogc/sdgecko_io.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/gc/sdcard/card_io.h b/gc/sdcard/card_io.h index b71071c7..1e4176d9 100644 --- a/gc/sdcard/card_io.h +++ b/gc/sdcard/card_io.h @@ -41,6 +41,7 @@ extern u16 g_dCode[MAX_MI_NUM][MAX_DI_NUM]; void sdgecko_initIODefault(void); s32 sdgecko_initIO(s32 drv_no); s32 sdgecko_preIO(s32 drv_no); +s32 sdgecko_enableCRC(s32 drv_no,bool enable); s32 sdgecko_readCID(s32 drv_no); s32 sdgecko_readCSD(s32 drv_no); s32 sdgecko_readStatus(s32 drv_no); diff --git a/libogc/sdgecko_io.c b/libogc/sdgecko_io.c index 57cbfb7b..cc2495e2 100644 --- a/libogc/sdgecko_io.c +++ b/libogc/sdgecko_io.c @@ -1049,6 +1049,30 @@ static s32 __card_sendCMD58(s32 drv_no) return ret; } +static s32 __card_sendCMD59(s32 drv_no,u32 crc_on_off) +{ + s32 ret; + u8 ccmd[5] = {0,0,0,0,0}; + + if(drv_no<0 || drv_no>=MAX_DRIVE) return CARDIO_ERROR_NOCARD; + + ccmd[0] = 0x3B; + ccmd[1] = (crc_on_off>>24)&0xff; + ccmd[2] = (crc_on_off>>16)&0xff; + ccmd[3] = (crc_on_off>>8)&0xff; + ccmd[4] = crc_on_off&0xff; + if((ret=__card_writecmd(drv_no,ccmd,5))!=0) { +#ifdef _CARDIO_DEBUG + printf("__card_sendCMD59(%d): sd write cmd failed.\n",ret); +#endif + return ret; + } + if((ret=__card_readresponse(drv_no,_ioResponse[drv_no],1))<0) return ret; + ret = __check_response(drv_no,_ioResponse[drv_no][0]); + + return ret; +} + static s32 __card_sendcmd(s32 drv_no,u8 cmd,u8 *arg) { u8 ccmd[5] = {0,0,0,0,0}; @@ -1189,7 +1213,7 @@ static s32 __card_softreset(s32 drv_no) if((ret=__check_response(drv_no,_ioResponse[drv_no][0]))!=0) return ret; if(!(_ioError[drv_no]&CARDIO_OP_IOERR_IDLE)) return CARDIO_ERROR_IOERROR; - return CARDIO_ERROR_READY; + return __card_sendCMD59(drv_no,TRUE); } static bool __card_check(s32 drv_no) @@ -1349,6 +1373,20 @@ s32 sdgecko_preIO(s32 drv_no) return CARDIO_ERROR_READY; } +s32 sdgecko_enableCRC(s32 drv_no,bool enable) +{ + s32 ret; + + if(drv_no<0 || drv_no>=MAX_DRIVE) return CARDIO_ERROR_NOCARD; +#ifdef _CARDIO_DEBUG + printf("sdgecko_enableCRC(%d,%d)\n",drv_no,enable); +#endif + ret = sdgecko_preIO(drv_no); + if(ret!=0) return ret; + + return __card_sendCMD59(drv_no,enable); +} + s32 sdgecko_readCID(s32 drv_no) { s32 ret;