Skip to content

Commit

Permalink
feat(usb): Use fatfs driver (exFAT support!)
Browse files Browse the repository at this point in the history
  • Loading branch information
F0bes committed Jul 8, 2024
1 parent c2d8103 commit b1fe895
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 42 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<br/>

Expand Down Expand Up @@ -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).
74 changes: 43 additions & 31 deletions biosdrain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}
19 changes: 17 additions & 2 deletions dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions ui/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void gs_init(void)
void menu_init(void)
{
gs_init();
fontqueue_init(4096);
fontqueue_init(8192);
graph_wait_vsync();


Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit b1fe895

Please sign in to comment.