From b1fe895eec9dd047ef883701d4a38c73452b3a0f Mon Sep 17 00:00:00 2001 From: Ty Lamontagne Date: Mon, 8 Jul 2024 13:39:03 -0400 Subject: [PATCH] feat(usb): Use fatfs driver (exFAT support!) --- Makefile | 8 +++--- README.md | 10 +++++--- biosdrain.c | 74 +++++++++++++++++++++++++++++++---------------------- dump.c | 19 ++++++++++++-- ui/menu.c | 4 +-- 5 files changed, 73 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 0484b29..463b6a5 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ EE_BIN = biosdrain.elf EE_OBJS = biosdrain.o OSDInit.o sysman_rpc.o ui/menu.o dump.o modelname.o EE_OBJS += ui/fontqueue.o ui/tex/font/font_tex.o ui/tex/font/font_pallete_tex.o ui/fontengine.o EE_OBJS += ui/graphic.o ui/graphic_vu.o ui/tex/bongo_tex_1.o ui/tex/bongo_tex_2.o ui/tex/biosdrain_tex.o -IRX_OBJS = irx/usbmass_bd_irx.o irx/usbd_irx.o irx/bdm_irx.o irx/bdmfs_vfat_irx.o irx/sysman_irx.o +IRX_OBJS = irx/usbmass_bd_irx.o irx/usbd_irx.o irx/bdm_irx.o irx/bdmfs_fatfs_irx.o irx/sysman_irx.o # Bin2c objects that will be linked in EE_OBJS += $(IRX_OBJS) EE_LIBS = -lkernel -lpatches -ldebug -lgraph -ldma -ldraw @@ -14,7 +14,7 @@ GIT_VERSION := "$(shell git describe --abbrev=4 --always --tags)" EE_CFLAGS = -I$(shell pwd) -Werror -DGIT_VERSION="\"$(GIT_VERSION)\"" -IRX_C_FILES = usbmass_bd_irx.c bdm_irx.c bdmfs_vfat_irx.c usbd_irx.c sysman_irx.c +IRX_C_FILES = usbmass_bd_irx.c bdm_irx.c bdmfs_fatfs_irx.c usbd_irx.c sysman_irx.c all: sysman_irx $(EE_BIN) @@ -34,8 +34,8 @@ irx/usbmass_bd_irx.c: $(PS2SDK)/iop/irx/usbmass_bd.irx irx/bdm_irx.c: $(PS2SDK)/iop/irx/bdm.irx bin2c $< irx/bdm_irx.c bdm_irx -irx/bdmfs_vfat_irx.c: $(PS2SDK)/iop/irx/bdmfs_vfat.irx - bin2c $< irx/bdmfs_vfat_irx.c bdmfs_vfat_irx +irx/bdmfs_fatfs_irx.c: $(PS2SDK)/iop/irx/bdmfs_fatfs.irx + bin2c $< irx/bdmfs_fatfs_irx.c bdmfs_fatfs_irx ui/tex/biosdrain_tex.c: ui/tex/biosdrain_tex.raw bin2c $< ui/tex/biosdrain_tex.c biosdrain_tex diff --git a/README.md b/README.md index 8fd5f17..7003e4e 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,17 @@ Execute biosdrain on the EE. For example: `ps2client execee host:biosdrain.elf` biosdrain should automatically detect a host filesystem, and dump the files directly to your computer. ### - **For USB users (using uLaunchELF)** -Put the biosdrain.elf file onto a FAT32 formatted USB drive. +Put the biosdrain.elf file onto a FAT32 (or exFAT!) formatted USB drive. In uLaunchELF, navigate to `mass:` and execute the biosdrain.elf file you just transferred. biosdrain should automatically detect a USB drive, and dump the files to the root of the USB drive. +**In the case that biosdrain does not detect a USB drive, try creating a smaller 1GB partition and +leaving the rest unformatted.** + ### **Using the BIOS with PCSX2** -Simply download the files (if you've used a USB drive) back to your computer, and keep them somewhere safe so you don't have to do this process again. +Simply copy the files (if you've used a USB drive) back to your computer, and keep them somewhere safe so you don't have to do this process again.
@@ -50,4 +53,5 @@ If the path to your bios was `D:\ps2bios\dump` you'd see one of the below. This software has been based off of the work from [PS2Ident](https://github.com/ps2homebrew/PS2Ident) licensed under AFL license-3.0 . The Sysman and Romdrv module source have been taken from there as well. -Issues and pull requests are very much welcome. The issue tracker may be used by users to report successful dumping as well, as I only have a single 39K to test on. Please make sure your model doesn't already have a report though. +Check out https://fobes.dev for some interesting PS2 programming blogs. +You can support me on KoFi [here](Ko-fi.com/f0bes). diff --git a/biosdrain.c b/biosdrain.c index e52eb66..b576683 100644 --- a/biosdrain.c +++ b/biosdrain.c @@ -24,8 +24,8 @@ extern unsigned int size_bdm_irx; extern unsigned char bdm_irx[]; -extern unsigned int size_bdmfs_vfat_irx; -extern unsigned char bdmfs_vfat_irx[]; +extern unsigned int size_bdmfs_fatfs_irx; +extern unsigned char bdmfs_fatfs_irx[]; extern unsigned int size_usbmass_bd_irx; extern unsigned char usbmass_bd_irx[]; @@ -72,27 +72,47 @@ void LoadSystemInformation() void load_irx_usb() { - int usbd_irx_id = SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, NULL); - printf("USBD ID is %d\n", usbd_irx_id); - int bdm_irx_id = SifExecModuleBuffer(&bdm_irx, size_bdm_irx, 0, NULL, NULL); printf("BDM ID: %d\n", bdm_irx_id); - int bdmfs_vfat_irx_id = SifExecModuleBuffer(&bdmfs_vfat_irx, size_bdmfs_vfat_irx, 0, NULL, NULL); - printf("BDMFS VFAT ID: %d\n", bdmfs_vfat_irx_id); + int bdmfs_fatfs_irx_id = SifExecModuleBuffer(&bdmfs_fatfs_irx, size_bdmfs_fatfs_irx, 0, NULL, NULL); + printf("BDMFS FATFS ID: %d\n", bdmfs_fatfs_irx_id); + + int usbd_irx_id = SifExecModuleBuffer(&usbd_irx, size_usbd_irx, 0, NULL, NULL); + printf("USBD ID is %d\n", usbd_irx_id); int usbmass_irx_id = SifExecModuleBuffer(&usbmass_bd_irx, size_usbmass_bd_irx, 0, NULL, NULL); printf("USB Mass ID is %d\n", usbmass_irx_id); +}; - printf("Waiting 5 seconds for the USB driver to detect the USB device\n"); - // We are too fast for the USB driver sometimes, so wait ~ 5 seconds - u32 v_cnt = 0; - while (v_cnt < 300) - { +int wait_usb_ready() +{ + menu_status("Waiting for USB to be ready...\n"); + //struct stat buffer; + int ret = -1; + int retries = 600; + + while (ret != 0 && retries > 0) { + //ret = stat("mass:/", &buffer); + if (mkdir("mass:/tmp", 0777)) + { + rmdir("mass:/tmp"); + ret = 0; + break; + } WaitSema(graphic_vsync_sema); - v_cnt++; + retries--; } -}; + + menu_status("USB ready after %d attempts.\n", 601 - retries); + if(ret != 0) + { + menu_status("USB not ready after 10 seconds :(.\n Try a smaller FAT32 partition?.\n"); + return -1; + } + + return 0; +} void reset_iop() { @@ -122,30 +142,18 @@ int determine_device() menu_status("Built to force USB and skip HOST.\n"); #endif { - use_usb_dir = 1; - -#ifndef NO_RESET_IOP_WHEN_USB + printf("Resetting IOP, bye bye!\n"); reset_iop(); -#endif load_irx_usb(); - if (!mkdir("mass:tmp", 0777)) - { - rmdir("mass:tmp"); - use_usb_dir = 1; - } - else + use_usb_dir = !wait_usb_ready(); + + if(!use_usb_dir) { menu_status("USB not found, and HOST is not available, not continuing.\n"); -#ifdef NO_RESET_IOP_WHEN_USB - menu_status("This is a noreset build.\n" - "This is usually necessary for uLaunchELF and USB users.\n" - "Please try the 'regular' biosdrain.elf build.\n"); -#endif return 1; } } - return 0; } @@ -184,6 +192,10 @@ int main(void) dump_exec(); dump_cleanup(); exit_main: - menu_status("Finished everything.\n"); + menu_status("Finished everything. You're free to turn off the system.\n"); + menu_status("\n"); + menu_status("Interested in PS2 development?\n"); + menu_status("Check out fobes.dev!\n"); + menu_status("Support me on ko-fi.com/f0bes!\n"); SleepThread(); } diff --git a/dump.c b/dump.c index d5a2ae3..7151357 100644 --- a/dump.c +++ b/dump.c @@ -26,16 +26,31 @@ static t_dump dump_jobs[6]; static char dump_filename[MODEL_NAME_MAX_LEN]; static u32 dump_file_usb = 0; +extern int errno; static u32 dump_file(t_dump job) { char path[256]; sprintf(path, "%s%s.%s", dump_file_usb ? "mass:" : "host:", dump_filename, job.dump_fext); - FILE *f = fopen(path, "wb+"); + FILE *f = fopen(path, "wb"); if (!f) + { + menu_status("Failed to open %d file %s\n", f, path); return 1; + } - fwrite(dump_shared_buffer, 1, job.dump_size, f); + u32 written_size = job.dump_size; + while(written_size > 0) + { + u32 write_size = fwrite(dump_shared_buffer, 1, written_size, f); + if (write_size == 0) + { + menu_status("Failed to write to file %s\n", path); + fclose(f); + return 2; + } + written_size -= write_size; + } FlushCache(0); diff --git a/ui/menu.c b/ui/menu.c index 9c46219..0573175 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -70,7 +70,7 @@ static void gs_init(void) void menu_init(void) { gs_init(); - fontqueue_init(4096); + fontqueue_init(8192); graph_wait_vsync(); @@ -110,7 +110,7 @@ void menu_status(const char* fmt, ...) va_list args; va_start(args, fmt); - char str[256]; + char str[1024]; vsnprintf(str, sizeof(str), fmt, args); sio_puts(str);