diff --git a/source/arm9/dev.c b/source/arm9/dev.c index e287dfd..09f5c9e 100644 --- a/source/arm9/dev.c +++ b/source/arm9/dev.c @@ -131,8 +131,12 @@ if(!dev_sd.initialized) { // thanks yellows8 - *((u16*)0x10000020) |= 0x200; //If not set, the hardware will not detect any inserted card on the sdbus. - *((u16*)0x10000020) &= ~0x1; //If set while bitmask 0x200 is set, a sdbus command timeout error will occur during sdbus init. + *((vu16*)0x10000020) |= 0x200; //If not set, the hardware will not detect any inserted card on the sdbus. + *((vu16*)0x10000020) &= ~0x1; //If set while bitmask 0x200 is set, a sdbus command timeout error will occur during sdbus init. + + u32 tries = 2000000; + while(!sdmmc_sd_is_active() && tries) --tries; + if(!tries) return false; if(SD_Init()) return false; dev_sd.initialized = true; //printf("sd init: success!\n"); diff --git a/source/arm9/main.c b/source/arm9/main.c index 885584a..46ff538 100644 --- a/source/arm9/main.c +++ b/source/arm9/main.c @@ -124,12 +124,6 @@ bootInfo.nand_status = nandRes; bootInfo.wififlash_status = wifiRes; - // TODO: avoid this somehow... - if(sdRes) - { - while(!dev_sdcard->is_active()); - } - // atm only those boot options are possible, so if the init // for both failed, this is a fatal error. return sdRes && nandRes; diff --git a/source/arm9/sdmmc.c b/source/arm9/sdmmc.c index 50486e2..53b20b6 100644 --- a/source/arm9/sdmmc.c +++ b/source/arm9/sdmmc.c @@ -462,29 +462,26 @@ int SD_Init() { - u32 tries; - set_target(&handleSD); - wait(0x10000); + wait(0xF000); sdmmc_send_command(&handleSD,0,0); sdmmc_send_command(&handleSD,0x10408,0x1AA); uint32_t temp = (handleSD.error & 0x1) << 0x1E; uint32_t temp2 = 0; - - for(tries=0; tries<100; tries++) + + do { - for(int j=0; j<20; j++) + do { sdmmc_send_command(&handleSD,0x10437,handleSD.initarg << 0x10); sdmmc_send_command(&handleSD,0x10769,0x00FF8000 | temp); temp2 = 1; - if(handleSD.error & 1) break; - } - if((handleSD.ret[0] & 0x80000000) != 0) break; + } while ( !(handleSD.error & 1) ); } + while((handleSD.ret[0] & 0x80000000) == 0); if(!((handleSD.ret[0] >> 30) & 1) || !temp) temp2 = 0; @@ -521,16 +518,6 @@ sdmmc_send_command(&handleSD,0x10410,0x200); if((handleSD.error & 0x4)) return -8; handleSD.clk |= 0x200; - - // we need a bit of time to detect an sd card has been inserted... - /*tries = 0; - for(;;) - { - wait(0x1000); - if(sdmmc_read16(REG_SDSTATUS0) & TMIO_STAT0_SIGSTATE) break; - if(tries == 0x10000) return -1; - tries++; - }*/ return 0; }