Hacking Problems writing to USB with cIOS 36 rev 10

zapfbandit

Active Member
OP
Newcomer
Joined
Sep 4, 2008
Messages
26
Trophies
0
XP
68
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.
 

Jacobeian

Well-Known Member
Member
Joined
May 15, 2008
Messages
1,893
Trophies
0
XP
387
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.
 

zapfbandit

Active Member
OP
Newcomer
Joined
Sep 4, 2008
Messages
26
Trophies
0
XP
68
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
 

Jacobeian

Well-Known Member
Member
Joined
May 15, 2008
Messages
1,893
Trophies
0
XP
387
Country
Cuba
QUOTE said:
Is there anyway to get the default USB behavior mixed with other functionality from the cIOS?

yes, by fixing the cIOS
unsure.gif

or maybe by not using libogc/libfat but direct access to IOS functions

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

hard to follow your logic here, afaik, USB loaders should not need to do any writes, only reads
 

Mikey242

Member
Newcomer
Joined
Nov 17, 2005
Messages
24
Trophies
0
XP
751
Country
Jacobeian said:
QUOTE said:
Is there anyway to get the default USB behavior mixed with other functionality from the cIOS?

yes, by fixing the cIOS
unsure.gif

or maybe by not using libogc/libfat but direct access to IOS functions

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

hard to follow your logic here, afaik, USB loaders should not need to do any writes, only reads


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

tueidj

I R Expert
Member
Joined
Jan 8, 2009
Messages
2,569
Trophies
0
Website
Visit site
XP
999
Country
Jacobeian said:
hard to follow your logic here, afaik, USB loaders should not need to do any writes, only reads
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?
 

Jacobeian

Well-Known Member
Member
Joined
May 15, 2008
Messages
1,893
Trophies
0
XP
387
Country
Cuba
hum, yeah, I didn't know about that, never used a Loader myself
smile.gif


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
 

zapfbandit

Active Member
OP
Newcomer
Joined
Sep 4, 2008
Messages
26
Trophies
0
XP
68
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
 

Jacobeian

Well-Known Member
Member
Joined
May 15, 2008
Messages
1,893
Trophies
0
XP
387
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
tongue.gif
)

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 ?
 

zapfbandit

Active Member
OP
Newcomer
Joined
Sep 4, 2008
Messages
26
Trophies
0
XP
68
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
 

zapfbandit

Active Member
OP
Newcomer
Joined
Sep 4, 2008
Messages
26
Trophies
0
XP
68
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
 

WiiPower

Well-Known Member
Member
Joined
Oct 17, 2008
Messages
8,165
Trophies
0
XP
345
Country
Gambia, The
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.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    SylverReZ @ SylverReZ: @OctoAori20, Thank you. Hope you're in good spirits today like I am. :)