Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with BDM devices and fileXio after #671 #683

Open
pcm720 opened this issue Nov 28, 2024 · 4 comments
Open

Issues with BDM devices and fileXio after #671 #683

pcm720 opened this issue Nov 28, 2024 · 4 comments

Comments

@pcm720
Copy link

pcm720 commented Nov 28, 2024

@fjtrujy @uyjulian

It looks like #671 introduced a serious issue with mixed usage of fileXio and POSIX calls (at least) on BDM devices.
NHDDL needs to get the device driver name and device number for launching Neutrino.
Currently, the only way to get those is to use the fileXioIoctl2 call.

Since after #671 has been merged, I keep getting strange errors on real PS2 hardware (PS2 SCPH-70000), even when compling using the latest PS2SDK commit.
When multiple BDM modules and devices are loaded, I get errors when using opendir/closedir calls.
Most of the times opendir can't open mass0: even though it was successfully opened and closed with fileXioDopen previously. Sometimes trying to call closedir on an opened directory when traversing directories crashes PS2 because the DIR pointer suddenly becomes NULL.

In addition to this, when only one BDM device is initialized, using mkdir call after fileXioIoctl2 causes open("rom0:FONTM"...) to fail. This particular issue can be reliably reproduced with the following code when launched from PS2LINK:
https://github.com/pcm720/ps2sdk-test/blob/main/main.c

Note that the issue occurs only on a real hardware when using fileXio.irx.
It never fails with fileXio_verbose.irx or when running on PCSX2.

Reverting 2a131ac or calling fileXioExit after fileXioIoctl2 fixes all of those issues.


@fjtrujy's example that demonstrates this issue on PCSX2 with USB mass drivers:
https://github.com/fjtrujy/helloWorldPS2/blob/mass_driver_bug/main.c

@fjtrujy
Copy link
Member

fjtrujy commented Nov 29, 2024

Hi, @pcm720 could you double-check that things are working fine after this PR is merged?

Please if it is working as expected, close this issue.

@pcm720
Copy link
Author

pcm720 commented Nov 29, 2024

Sadly, it doesn't seem to fix the issue.
Both NHDDL and my example fail with FONTM.
NHDDL:

  Failed to open FONTM from ROM0
  ERROR: Failed to upload FONTM: -1
  ERROR: Failed to init UI: -1
  Get Reboot Request From EE

Example:

Opening mass0 via open
dopen name mass0:/
dopen fd = 3
Getting driver name via fileXioIoctl2
Driver name is ata
Creating mass0:/testdir
ERROR: Failed to create: -1
Opening FONTM
ERROR: Failed to open: -1

Your example also fails on both my console and PCSX2 if there are no USB devices connected:
PS2:

Poweroff_Handler: Poweroff already registered
fileXio: fileXio: fileXio RPC Server v1.00
Copyright (c) 2003 adresd
Block Device Manager (BDM) v1.1
BDM: connecting fs MBR
BDM: connecting fs GPT
BDM: BDM event thread running
BDM FatFs driver (FAT/exFAT) v1.4
BDM: connecting fs fatfs
USB Driver (Version 1.6.0)
usbmass_bd: USB MASS Driver v1.1
cdfs Filedriver vDRIVER_UNIT_VERSION
Re-edited by fjtrujy
Original implementation
by A.Lee (aka Hiryu) & Nicholas Van Veen (aka Sjeep)
CDFS: Initializing 'cdfs' file driver.

DEV9 device driver v1.0 - Copyright (c) 2003 Marcus R. Brown

dev9: CXD9611 detected.
Opening mass0 via open
ERROR: Failed to open: -1
Creating mass0:/testdir
ERROR: Failed to create: -1
Opening FONTM
ERROR: Failed to open: -1, errno: 2

PCSX2:

[  312.1278] dev9: CXD9611 detected.
[  313.1027] DEV9: Adapter Detection Hack - Resetting RX/TX
[  313.1092] dev9: SPEED chip 'ES2', revision 11
[  313.1307] dev9: CXD9611 (SSBUS Buffer) driver start.
[  327.4417] read/write allocate memory 4000
[  327.4460] Opening mass0 via open
[  327.4555] ERROR: Failed to open: -1
[  327.4584] Creating mass0:/testdir
[  327.4687] ERROR: Failed to create: -1
[  327.4696] Opening FONTM
[  327.4703] ERROR: Failed to open: -1, errno: 6

@fjtrujy
Copy link
Member

fjtrujy commented Nov 29, 2024

@uyjulian looks like we still have something wrong with current filexio

The next dummy example (using ps2_drivers) is not working in real hardware and PCSX2 (no matter if USB are connected/disconnected)

#include <tamtypes.h>
#include <kernel.h>
#include <sifrpc.h>
#include <loadfile.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <iopcontrol.h>
#include <sbv_patches.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <ps2_filesystem_driver.h>

// Used to get BDM driver name
#define NEWLIB_PORT_AWARE
#include <fileXio_rpc.h>
#include <io_common.h>
#include <usbhdfsd-common.h>
#include <ps2sdkapi.h>

static void reset_IOP() {
    SifInitRpc(0);
#if !defined(DEBUG) || defined(BUILD_FOR_PCSX2)
    /* Comment this line if you don't wanna debug the output */
    while (!SifIopReset(NULL, 0)) {};
#endif

    while (!SifIopSync()) {};
    SifInitRpc(0);
    sbv_patch_enable_lmb();
    sbv_patch_disable_prefix_check();
}

static void init_drivers() {
    init_ps2_filesystem_driver();
}

static void deinit_drivers() {
    deinit_ps2_filesystem_driver();
}

int main(int argc, char **argv) {
    int res, fd;
    reset_IOP();
    init_drivers();

    printf("Opening FONTM\n");
    fd = open("rom0:FONTM", O_RDONLY);
    if (fd < 0) {
        printf("ERROR: Failed to open: %d, errno: %d\n", fd, errno);
    } else {
        close(fd);
    }

    printf("Done");

    deinit_drivers();
    SleepThread();
}

PCSX2 output:

ELF host:/Users/fjtrujy/Projects/ps2_drivers/samples/filesystem_sample/filesystem_sample.elf with entry point at 0x00127208 is executing.
ELF changed, active CRC 3F092655 (host:/Users/fjtrujy/Projects/ps2_drivers/samples/filesystem_sample/filesystem_sample.elf)
Applying core settings...
Updating CPU configuration...
EE/iR5900 Recompiler Reset
Warning: GetOsdConfigParam2 Reading extended language/version configs, may be incorrect!
Get Reboot Request From EE

PlayStation 2 ======== Soft reboot

IOP Realtime Kernel Ver.0.9.1
    Copyright 1999 (C) Sony Computer Entertainment Inc. 
Reboot service module.(99/11/10)
cdvd driver module version 0.1.1 (C)SCEI
Load File service.(99/11/05)
Multi Threaded Fileio module.(99/11/15) 
iop heap service (99/11/03)
Poweroff_Handler: Poweroff installed
fileXio: fileXio: fileXio RPC Server v1.00
Copyright (c) 2003 adresd
Block Device Manager (BDM) v1.1
BDM: connecting fs MBR
BDM: connecting fs GPT
BDM: BDM event thread running
BDM FatFs driver (FAT/exFAT) v1.4
BDM: connecting fs fatfs
USB Driver (Version 1.6.0)
usbmass_bd: USB MASS Driver v1.1
cdfs Filedriver vDRIVER_UNIT_VERSION
Re-edited by fjtrujy
Original implementation
by A.Lee (aka Hiryu) & Nicholas Van Veen (aka Sjeep)
CDFS: Initializing 'cdfs' file driver.

DEV9 device driver v1.0 - Copyright (c) 2003 Marcus R. Brown

dev9: CXD9611 detected.
DEV9: Adapter Detection Hack - Resetting RX/TX
dev9: SPEED chip 'ES2', revision 11
dev9: CXD9611 (SSBUS Buffer) driver start.
read/write allocate memory 4000
Opening FONTM
ERROR: Failed to open: -1, errno: 6

@uyjulian
Copy link
Member

Cannot reproduce the issue on either PCSX2 or real hardware

After rebuilding ps2sdk ( e3bea49 ) and ps2_drivers

[  535.7877] ELF host:C:\Users\Julian\Desktop\wle\usb_mass.elf with entry point at 0x1052552 is executing.
[  535.7882] ELF changed, active CRC 22BF4EDA (host:C:\Users\Julian\Desktop\wle\usb_mass.elf)
[  535.7890] Applying core settings...
[  535.7892] Updating CPU configuration...
[  535.8178] EE/iR5900 Recompiler Reset
Get Reboot Request From EE

PlayStation 2 ======== Soft reboot

IOP Realtime Kernel Ver.0.9.1
    Copyright 1999 (C) Sony Computer Entertainment Inc.
Reboot service module.(99/11/10)
cdvd driver module version 0.1.1 (C)SCEI
Load File service.(99/11/05)
Multi Threaded Fileio module.(99/11/15)
iop heap service (99/11/03)
Poweroff_Handler: Poweroff installed
fileXio: fileXio: fileXio RPC Server v1.00
Copyright (c) 2003 adresd
Block Device Manager (BDM) v1.1
BDM: connecting fs MBR
BDM: connecting fs GPT
BDM: BDM event thread running
BDM FatFs driver (FAT/exFAT) v1.4
BDM: connecting fs fatfs
USB Driver (Version 1.6.0)
usbmass_bd: USB MASS Driver v1.1
cdfs Filedriver vDRIVER_UNIT_VERSION
Re-edited by fjtrujy
Original implementation
by A.Lee (aka Hiryu) & Nicholas Van Veen (aka Sjeep)
CDFS: Initializing 'cdfs' file driver.

DEV9 device driver v1.0 - Copyright (c) 2003 Marcus R. Brown

dev9: unknown dev9 hardware.
read/write allocate memory 4000
Opening FONTM
Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants