PS2 Trying to read file from USD pendrive

shooter

Member
I spent a couple of days for trying to read file from USB drive. I think that this must be easy, but i really confused. I have seen a multiple examples of usage USB IOP modules in popular apps(uLaunchELF or ps2doom for example), but i can't implement this by myself.

File that i need placed in FAT32 filesystem file that be mounted to PCSX2 using a USBqemu-wheel plugin(https://github.com/jackun/USBqemu-wheel). For testing purposes i use a uLauchELF, he can read this mass storage device. But if i try to load my app i see this output in PCSX2 log window:
Code:
[DEBUG] loading module usbd
[DEBUG] module usbd loaded with id:282624 and res:0
[DEBUG] loading module usbhdfsd
[DEBUG] module usbhdfsd loaded with id:282624 and res:0
open name mass:¥LOZ.GB flag 1 data 41378
Unknown device 'mass'
Known devices are  tty:(CONSOLE)  rom:(ROM/Flash)  cdrom:(CD-ROM )
open fd = -19
[DEBUG]fd = -19
Get Reboot Request From EE

Can someone point for me, what i missed? Please.
There is my code:

main.c:
Code:
#include <stdio.h>
#include <tamtypes.h>
#include <unistd.h>
#include <loadfile.h>

extern u8 usbd_irx[];
extern int size_usbd_irx;

extern u8 usbhdfsd_irx[];
extern int size_usbhdfsd_irx;

void loadModule(char *name, u8 *irx, int size);

int main() {
    /*SifInitRpc(0);
    if (SifLoadFileInit() != 0) {
        printf("[ERROR] cannot init LOADFILE library\n");
    }*/
    
    // USB mass support
    loadModule("usbd", usbd_irx, size_usbd_irx);
    loadModule("usbhdfsd", usbhdfsd_irx, size_usbhdfsd_irx);

    sleep(5);

    int fd = open("mass:\\LOZ.GB", O_RDONLY);
    printf("[DEBUG]fd = %d\n", fd);

    return 0;
}

void loadModule(char *name, u8 *irx, int size) {
    printf("[DEBUG] loading module %s\n", name);
    if (size == 0) {
        printf("[ERROR] module is empty\n");

        return;
    }

    int id, res = 0;

    id = SifExecModuleBuffer(irx, size, 0, NULL, &res);
    if (id < 1) {
        printf("[ERROR] module exec error:%d\n", id);

        return;
    }

    printf("[DEBUG] module %s loaded with id:%d and res:%d\n", name, id, res);
}

Makefile:
Code:
BIN2S = $(PS2SDK)/bin/bin2s

EE_BIN = main.elf
EE_OBJS = main.o usbd_irx.o usbhdfsd_irx.o

all: $(EE_BIN)

usbd_irx.s: $(PS2SDK)/iop/irx/usbd.irx
    $(BIN2S) $< $@ usbd_irx

usbhdfsd_irx.s: $(PS2SDK)/iop/irx/usbhdfsd.irx
    $(BIN2S) $< $@ usbhdfsd_irx

clean:
    rm -f *.elf *.o *.s *.a

include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
 
I spent a couple of days for trying to read file from USB drive. I think that this must be easy, but i really confused. I have seen a multiple examples of usage USB IOP modules in popular apps(uLaunchELF or ps2doom for example), but i can't implement this by myself.

You didn't apply the LoadModuleBuffer patch (sbv_patch_enable_lmb). You should do this after initializing SIFRPC on the EE side. Without this patch, the IOP's default LOADFILE RPC service does not support LoadModuleBuffer(), but is incapable of returning an error code.
Notice how the module IDs look strange.

Also another thing you might want to do, is reboot the IOP. Otherwise, whatever that was loaded previously (including modules that are incompatible with your work), would still be running.
Code:
SifInitRpc(0);
while(!SifIopReset("", 0)){};
while(!SifIopSync()){};
SifInitRpc(0);
...
 
Last edited:
Oh, this is not obvious for noobs in PS2 programming like me.
I think i need to add this code as example to USBHDFSD module. This example can be useful for beginners.

Thank you!
 
Part of the problem comes from the fact that we tend to use the default IOP kernel modules, which are as early as they get. Somehow, this RPC function was just missing and even Sony applies a patch to get it working again, for their HDD Browser.
 
Back
Top