Skip to content

Commit

Permalink
Enable CRC verification on SD card
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Oct 4, 2024
1 parent 8b0f5c9 commit 3d0b566
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions gc/sdcard/card_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 39 additions & 1 deletion libogc/sdgecko_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3d0b566

Please sign in to comment.