From befa70ba22e4ab90c608e60f9935cefaa8ec2c15 Mon Sep 17 00:00:00 2001 From: Kevin Murphy Date: Sun, 18 Feb 2024 22:29:45 -0800 Subject: [PATCH 1/2] Use device type rather than index to gate setting SD bus speed This seems less fragile. --- cubeboot/source/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cubeboot/source/sd.c b/cubeboot/source/sd.c index 6dc3991..a1768f7 100644 --- a/cubeboot/source/sd.c +++ b/cubeboot/source/sd.c @@ -68,7 +68,7 @@ static int check_available_devices() { } iprintf("Trying mount %s\n", dev_name); - if (i < MAX_DRIVE) + if (driver->ioType == DEVICE_TYPE_GC_SD) sdgecko_setSpeed(i, EXI_SPEED32MHZ); if (driver->startup() && driver->isInserted()) { From 8ffbbb371c5ffdd09989b6189c8b3a5276ea1651 Mon Sep 17 00:00:00 2001 From: Kevin Murphy Date: Sun, 18 Feb 2024 22:18:18 -0800 Subject: [PATCH 2/2] Fix GCLoader support, broken due to double-init of GCODE Commit f499333 introduced a call to GCODE_Init() in an effort to accelerate the boot device detection loop. Unfortunately, this function is called a second time inside driver->startup(), which seems to break loading files from GCLoader. In this change, we restructure the boot device detection loop to avoid the double-init of GCODE. --- cubeboot/source/sd.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/cubeboot/source/sd.c b/cubeboot/source/sd.c index a1768f7..94f41fd 100644 --- a/cubeboot/source/sd.c +++ b/cubeboot/source/sd.c @@ -48,13 +48,16 @@ static int check_available_devices() { for (int i = countof(drivers) - 1; i >= 0; i--) { const DISC_INTERFACE *driver = drivers[i]; const char *dev_name = dev_names[i]; + bool present = false; - // // skip GCLoader if we did not boot from ODE - // if (driver->ioType == DEVICE_TYPE_GAMECUBE_GCODE && low_mem->dhi.country_code != 0x03) - // continue; + switch (driver->ioType) { + case DEVICE_TYPE_GC_SD: + sdgecko_setSpeed(i, EXI_SPEED32MHZ); + present = driver->startup(); + break; - // skip ODE to speed up loading - if (driver->ioType == DEVICE_TYPE_GAMECUBE_GCODE) { + case DEVICE_TYPE_GAMECUBE_GCODE: + // The manual inquiry is faster than driver->startup(). GCODE_Init(); GCODE_InquiryAsync(&blk, &drive_info, drive_info_callback); @@ -64,14 +67,15 @@ static int check_available_devices() { udelay(100); // 100 microseconds } - if (drive_info.rel_date != 0x20196c64) continue; + present = (drive_info.rel_date != 0x20196c64); + break; + default: + // Unknown driver type? Something fatal is happening. + break; } iprintf("Trying mount %s\n", dev_name); - if (driver->ioType == DEVICE_TYPE_GC_SD) - sdgecko_setSpeed(i, EXI_SPEED32MHZ); - - if (driver->startup() && driver->isInserted()) { + if (present && driver->isInserted()) { // set driver for fatfs current_device_index = i; current_device = driver;