Problems writing to USB with cIOS 36 rev 10

Discussion in 'Wii - Hacking' started by zapfbandit, Jun 15, 2009.

Jun 15, 2009
  1. zapfbandit
    OP

    Newcomer zapfbandit Member

    Joined:
    Sep 4, 2008
    Messages:
    26
    Country:
    United States
    I am using cIOS 36 rev 10 and doing something equivalent to:

    Code:
    IOS_ReloadIOS(249);
    
    fatInitDefault();
    
    FILE* sd = fopen("sd:/whatever.txt", "wt");
    fprintf(sd, "hello SD world\n");
    fclose(sd);
    
    FILE* usb = fopen("usb:/whatever.txt", "wt");
    fprintf(usb, "hello USB world\n");
    fclose(usb);
    The problem is that the USB fopen will fail even though the SD open/write is OK.

    If I don't do the ReloadIOS both work.

    Any ideas / suggestions? I would really like to have USB writting with cIOS 36 rev 10.

    Thanks,
    Zapf

    Note I have also tried:

    Code:
    __io_wiisd.startup();
    fatMountSimple("sd", &__io_wiisd);
    
    __io_usbstorage.startup();
    fatMountSimple("usb", &__io_usbstorage);
    instead of fatInitDefault() to no avail.
     
  2. Jacobeian

    Member Jacobeian GBAtemp Advanced Maniac

    Joined:
    May 15, 2008
    Messages:
    1,879
    Country:
    Cuba
    unrecognized USB device seems the most logical to me

    you should try to check the return of the fatMount function to see if the problem arises during mounting or later during opening for write.

    Generally speaking, I think that the EHCI module is still a little (a lot ?) bugged in those cIOS and is known to cause issue with USB1 devices. SD device are not affected since it uses a whole diffrent module.
     
  3. zapfbandit
    OP

    Newcomer zapfbandit Member

    Joined:
    Sep 4, 2008
    Messages:
    26
    Country:
    United States
    Is there anyway to get the default USB behavior mixed with other functionality from the cIOS?

    I assume there is some way of getting USB writes working with this cIOS since Wanikoko uses this cIOS for the USB ISO loader.

    Thanks,
    Zapf
     
  4. zapfbandit
    OP

    Newcomer zapfbandit Member

    Joined:
    Sep 4, 2008
    Messages:
    26
    Country:
    United States
    Sorry, double post
     
  5. Jacobeian

    Member Jacobeian GBAtemp Advanced Maniac

    Joined:
    May 15, 2008
    Messages:
    1,879
    Country:
    Cuba
    hard to follow your logic here, afaik, USB loaders should not need to do any writes, only reads
     
  6. Mikey242

    Newcomer Mikey242 Member

    Joined:
    Nov 17, 2005
    Messages:
    17
    Country:
    United Kingdom

    USB loaders can also write to USB as you can install games from the Wii's disk drive onto the USB drive.
     
  7. tueidj

    Member tueidj I R Expert

    Joined:
    Jan 8, 2009
    Messages:
    2,569
    Country:
    They write to USB when "backing up" a disc.

    Why not look at the source code for the USB loaders to see how they do it?
     
  8. Jacobeian

    Member Jacobeian GBAtemp Advanced Maniac

    Joined:
    May 15, 2008
    Messages:
    1,879
    Country:
    Cuba
    hum, yeah, I didn't know about that, never used a Loader myself [​IMG]

    anyway, this is a different file system so they probably do not use libfat usual fopen/fwrite functions but the WBFS library, which do direct USB/SD sector access, and will only work with WBFS formatted devices.

    EDIT: Well, it seems it's at least a legit FAT device since it worked without CIOS being loaded
     
  9. zapfbandit
    OP

    Newcomer zapfbandit Member

    Joined:
    Sep 4, 2008
    Messages:
    26
    Country:
    United States
    I had a good read of the USB loader coder and it does indeed use a WBFS.

    Unfortunately for me I really wanted to use FAT32 since ultimately the files need to be read from Windows (without needing an extracting program).

    Any ideas how I could implement this? Would it be difficult to implement my own FAT system if I can do raw read/writes? Is there one already out there?

    It seems a little redundant since this is EXACTLY what the fatlib is supposed to do :-)

    Thanks for the feedback,
    Zapf
     
  10. Jacobeian

    Member Jacobeian GBAtemp Advanced Maniac

    Joined:
    May 15, 2008
    Messages:
    1,879
    Country:
    Cuba
    hum, the problem is not with libfat or with the File System, so it would not solve anything.
    The problem is with CIOS when you access the USB device at low level (function to open the /usb device on IOS side), this is done by libogc via IOS_Open calls (see usb.c & usbstorage.c)

    Libogc access the original USB1 "device", which is /dev/usb/oh0

    USB Loaders access another device (USB2), added by the Custom IOS, which is /dev/usb/ehci

    It seems compatibility is broken with oh0 in the Custom IOS, most probably because the goal was to have a working EHCI (USB2) module and they didn't really care about USB1 anymore (and because they are not as serious as Twiizers [​IMG] )

    Unless someone figure what cause that failure in CIOS, your only soultion would be to use Kwiirk's usbstorage.c (from USB Loader sourcecode) and adapt/add const DISC_INTERFACE __io_usbstorage so that it uses this instead. This will obviously only works for USB2 capable devices.

    Or maybe modify libogc's USBStorage_Open call to use "ehci" instead of "oh0" when CiOS with USB2 support is used, but I don't know if it will work so simply (there is a lot of surrounding code which might break due to the IOS device not being the same, I dunno)

    Something like that in __usbstorage_IsInserted function from usbstorage.c
    (will try EHCI first then OH0 if failed)
    CODEif(USB_GetDeviceList("/dev/usb/ehci", buffer, DEVLIST_MAXSIZE, 0, &dummy) < 0)
    {
    ÂÂ if(USB_GetDeviceList("/dev/usb/oh0", buffer, DEVLIST_MAXSIZE, 0, &dummy) < 0)
    ÂÂ {
    ÂÂÂÂÂÂ if(__vid!=0 || __pid!=0) USBStorage_Close(&__usbfd);
    ÂÂÂÂÂÂ memset(&__usbfd, 0, sizeof(__usbfd));
    ÂÂÂÂÂÂ __lun = 0;
    ÂÂÂÂÂÂ __vid = 0;
    ÂÂÂÂÂÂ __pid = 0;

    ÂÂÂÂÂÂ __lwp_heap_free(&__heap,buffer);
    ÂÂÂÂÂÂ return false;
    ÂÂ }
    }

    and :

    CODEÂÂif(USBStorage_Open(&__usbfd, "ehci", vid, pid) < 0)
    ÂÂÂÂÂÂif(USBStorage_Open(&__usbfd, "oh0", vid, pid) < 0)
    ÂÂÂÂÂÂÂÂÂÂÂÂcontinue;




    This might help you as well: http://wiibrew.org/wiki/CIOS_usb2/


    Out of curiosity, why do you absolutely want to load that CIOS before you write files ?
     
  11. zapfbandit
    OP

    Newcomer zapfbandit Member

    Joined:
    Sep 4, 2008
    Messages:
    26
    Country:
    United States
    Thanks for these suggestions.

    I tried the modifications to libogc with no luck.

    I will try modifying DISC_INTERFACE __io_usbstorage and see if I have any luck.

    Zapf
     
  12. zapfbandit
    OP

    Newcomer zapfbandit Member

    Joined:
    Sep 4, 2008
    Messages:
    26
    Country:
    United States
    I ended up modifying "usbstorage" from the USB loader as you suggested.

    Now in my code I do the following:

    CODE#include
    #include "usbstorage.h"

    ...
    IOS_ReloadIOS(249);
    ...
    bool sd_ok =ÂÂÂÂ(__io_wiisd.startup() == true) &&
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ(fatMountSimple("sd", &__io_wiisd) == true);
    bool usb_ok =ÂÂÂÂ(__my_usbstorage.startup() == true) &&
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ(fatMountSimple("usb", &__my_usbstorage) == true);
    ...
    if (sd_ok)
    {
    ÂÂÂÂFILE* sd = fopen("sd:test.txt", "wt");
    ÂÂÂÂfprintf(sd, "yay!\n");
    ÂÂÂÂfclose(sd);
    }
    if (usb_ok)
    {
    ÂÂÂÂFILE* usb = fopen("usb:test.txt", "wt");
    ÂÂÂÂfprintf(usb, "yay!\n");
    ÂÂÂÂfclose(usb);
    }
    ...
    if (sd_ok)
    {
    ÂÂÂÂfatUnmount("sd");
    ÂÂÂÂ__io_wiisd.shutdown();
    }
    if (usb_ok)
    {
    ÂÂÂÂfatUnmount("usb");
    ÂÂÂÂ__my_usbstorage.shutdown();
    }

    Note that this is incompatible with "fatInitDefault()".

    I have attached the new files for anyone who wants to use them:

    http://www.4shared.com/file/112411750/fede...usbstorage.html

    Thanks for all the help and I hope this answer helps someone else,
    Zapf
     
  13. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany
    You could try the usb storage code from WAD Manager. Or one (very bad) alternative would be to read/write from/to usb with IOS36, and then do a IOS Reload. But that method would make the usb storage unusable until the next app is started.
     

Share This Page