USB Loader Hard Drives - Call to coders

Discussion in 'Wii - Hacking' started by Dteyn, Apr 15, 2009.

Apr 15, 2009
  1. Dteyn
    OP

    Member Dteyn GBAtemp Fan

    Joined:
    Aug 3, 2008
    Messages:
    338
    Country:
    Canada
    I've got a hard drive here that only works with the swap trick, I think if a developer lends a hand with a quick diagnostic program we might be able to figure out why it only works with the swap trick, and perhaps fix/add some stuff to the USB Loader code to enhance the compatibility with more devices.

    Here's the scoop -- I have a 120GB external USB hard drive that gives the ret -1 error when trying to load USB Loader with the hard drive connected.

    However, I saw a note on the Compatibility List mentioning a 'swap trick' -- that is, to start the USB Loader with an unformatted USB flash drive inserted, so the USB Loader says "No WBFS Partition Found - Press A to select a partition to format". At that point, I remove the USB stick and plug in the USB hard drive, and then press A... it shows the primary 120GB partition (already formatted with WBFS Manager on my computer), and by pressing B it takes me back to the main menu and I'm able to use the hard drive without issue, until the Wii is rebooted.

    I was thinking, if someone familiar with Wii coding made some quick hacks to the USB Loader code (or copy/paste some code into a new project), we should be able to print some kernel messages to the screen when the USB hard drive is swapped with the flash drive. I'm thinking kinda like when you type 'dmesg' in Linux and it prints the kernel messages, showing the USB device info and relevant driver information. Perhaps this diagnostic info will give us a clue as to why the hard drive needs the swap trick to work.

    Is anyone willing to lend a hand with this task? I would love to attempt it but I don't have any Wii or C development skills. I have the hard drive and am familiar with my Wii setup, so I can do all the testing required... unfortunately just not the coding.
     


  2. Dteyn
    OP

    Member Dteyn GBAtemp Fan

    Joined:
    Aug 3, 2008
    Messages:
    338
    Country:
    Canada
    Hmmm.. I'm just looking at the source code, I think I've found a difference that might explain why the swap trick works. Forgive me if I'm misreading this, as I mentioned above I don't have any C coding experience (although I have familiarity with other programming languages).

    I'm looking at the Ultimate USB Loader v6.7 source code. In usb-loader.c at line 102 in the main() routine, it initializes WBFS as such:
    CODEÂÂÂÂ/* Initialize WBFS */
    ÂÂÂÂret = WBFS_Init(WBFS_MIN_DEVICE);
    ÂÂÂÂif (ret < 0)
    ÂÂÂÂ{
    ÂÂÂÂÂÂÂÂFat_UnmountSDHC();
    ÂÂÂÂÂÂÂÂint i;
    ÂÂÂÂÂÂÂÂfor(i=40;i>=0;i--)
    ÂÂÂÂÂÂÂÂ{
    ÂÂÂÂÂÂÂÂÂÂÂÂprintf("\n Waiting for USB device... %d", i);
    ÂÂÂÂÂÂÂÂÂÂÂÂIOS_ReloadIOS(249);

    ÂÂÂÂÂÂÂÂÂÂÂÂsleep(1);
    ÂÂÂÂÂÂÂÂÂÂÂÂSys_Init();

    ÂÂÂÂÂÂÂÂÂÂÂÂret = WBFS_Init(WBFS_MIN_DEVICE);
    ÂÂÂÂÂÂÂÂÂÂÂÂCon_Init(CONSOLE_XCOORD, CONSOLE_YCOORD, CONSOLE_WIDTH, CONSOLE_HEIGHT);
    ÂÂÂÂÂÂÂÂÂÂÂÂCon_Clear();

    ÂÂÂÂÂÂÂÂÂÂÂÂif(ret>=0)
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂbreak;
    ÂÂÂÂÂÂÂÂ}

    ÂÂÂÂÂÂÂÂsleep(1);
    ÂÂÂÂÂÂÂÂFat_MountSDHC();
    ÂÂÂÂ}

    ÂÂÂÂif (ret < 0) {
    ÂÂÂÂÂÂÂÂprintf("ÂÂÂÂERROR! (ret = %d)\n", ret);

    ÂÂÂÂÂÂÂÂ/* Restart wait */
    ÂÂÂÂÂÂÂÂRestart_Wait();
    ÂÂÂÂ}

    And then, looking at menu.c (where the code responsible for the 'No WBFS Partition Found' message) at line 906 in the Menu_Loop() routine, we have this:

    Code:
    void Menu_Loop(void)
    {
    ÂÂÂÂs32 ret;
    ÂÂÂÂstruct discHdr *header = NULL;
    ÂÂÂÂ
    ÂÂÂÂ/* Open USB device */
    ÂÂÂÂret = WBFS_Open();
    ...
    I notice that WBFS_Open() isn't called in the main() routine in usb-loader.c, before the WBFS_Init() routine is called.

    It seems like the swap trick might work because WBFS_Init() doesn't work with all devices unless WBFS_Open() is called first.

    The anecdotal evidence supports this: insert a USB stick, the routine WBFS_Init() works and then we get to line 926 in menu.c (where the user is asked for input as to whether to proceed -- this is where the hard drive is swapped). Swap out the hard drive, press A, that's when Menu_Format() is called. Press B and that routine exits, the next routine run is WBFS_Open() and then it returns back to the main menu, with the hard drive now working.

    My guesstimate is, if we modify the source code as such:
    CODEÂÂÂÂ/* Initialize WBFS */
    ÂÂÂÂret = WBFS_Open();ÂÂ// Open the device before init
    ÂÂÂÂret = WBFS_Init(WBFS_MIN_DEVICE);
    ÂÂÂÂif (ret < 0)
    ÂÂÂÂ{
    ...
    ÂÂÂÂ}

    ... then perhaps the swap trick will no longer be necessary?

    Can an experienced coder let me know if I'm on the right track? I would try it but I don't have the dev setup for Wii software, maybe I'll set that up later and give it a go.
     
  3. Dteyn
    OP

    Member Dteyn GBAtemp Fan

    Joined:
    Aug 3, 2008
    Messages:
    338
    Country:
    Canada
    Alright, I installed devkitPro as per the Wiibrew instructions and tested the above theory. Unfortunately it results in a code dump, so the fix obviously isn't what I figured it might be.

    However I'm not gonna give up, I'll keep looking and trying things and perhaps I can come up with a solution. At least I have devkitPro installed now, so that gives me a chance to do some of my own changes and testing. [​IMG]
     
  4. frankomio

    Newcomer frankomio Member

    Joined:
    Apr 9, 2009
    Messages:
    33
    Country:
    Germany
    Hi Dteyn,
    i will compile this in a few hours (i am at work) !

    your experience with your swap-trick gives me hope to solve my problems with 4 identical USB 2,5>" disks (hitachi in Bestmedia-cases):

    I recognized, that always when i power on my Wii (from red-lightend to green),
    the USB-Drives are directly recognized by the wii and the USB-Loader works fine AT ONCE !
    But if i close then Loader and re-open it (or wake up the wii from standby),
    then USB-Loader needs at least 15 sec. to initialize !
    Thats the reason, why i always coded a loop of the WBFS_INIT() routine in the loder-sources that im testing.
    And thats why i only use loaders with the LOPST-Mod (i think exactly what you´ve posted, or not?)

    i will test your interesting idea this evening,
    but i´m not a perfect c-coder
     
  5. Dteyn
    OP

    Member Dteyn GBAtemp Fan

    Joined:
    Aug 3, 2008
    Messages:
    338
    Country:
    Canada
    I put some debug messages in the code and determined at exactly which line of code the loader bombs when trying to mount my finicky external HDD.

    It's at line 240 in wbfs.c, during the WBFS_Init() routine:
    Code:
    ÂÂÂÂÂÂÂÂÂÂÂÂ/* Get USB capacity */
    ÂÂÂÂÂÂÂÂÂÂÂÂnb_sectors = USBStorage_GetCapacity(&sector_size);
    ÂÂÂÂÂÂÂÂÂÂÂÂif (!nb_sectors)
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -1;
    For some reason the USBStorage_GetCapacity() routine fails and doesn't return anything into nb_sectors, causing a return of -1 which makes the USB Loader loop endlessly until the timer counts down to 0, at which point the Restart_Wait() routine is called.

    However, as mentioned above, if I swap a USB stick in, the hard drive works without issues... there must be some reason USBStorage_GetCapacity() fails in the above instance and yet works in other instances. The hard drive even shows the correct free space once the swap trick is completed, so the USBStorage_GetCapacity() routine does work on my HDD, just not initially. For some reason the swap trick does something that causes it to work.

    I thought maybe it was the fact the the format routine lists the partitions, so I tried a quick hack to list the partitions as soon as the loader is started, and the swap trick was still required.

    Still digging...
     
  6. substring

    Newcomer substring Member

    Joined:
    Apr 2, 2009
    Messages:
    13
    Country:
    France
    And USBStorage_GetCapacity calls IOS_IoctlvFormat, which is a core function from libogc.

    I haven't found much doc about that function, unless I download the libogc source and start digging ipc.c to find out what parameters the function takes, and where's the problem ...

    Oh btw : i'm trying to find out why some harddrives aren't recognized (those that used to get "ret = -1" with the 1.1 USB Loader, which turned into a "ret = -6" with 1.4)

    Talking about the ret = -6 ... The -6 error should be (I haven't found time to start debugging again waninkoko's job again) the value of the IPC_ENOENT const (which points once again to ipc.c)

    Let's have fun !!! w00t !
     
  7. ether2802

    Former Staff ether2802 we have the techno...!!

    Joined:
    Oct 14, 2007
    Messages:
    4,350
    Location:
    Pto. Vallarta
    Country:
    Mexico
    Just a theory from a far from a coder guy......maybe the swap trick works because it can init the USB stick perfect, and then you switch to your HDD when the USB device has been initialized, so maybe some HDD need an extra call to init right or to be recognized, how about a retry..?? I don't have a HDD to test this theory (or the requiered knowledge for that matter [​IMG] )
     
  8. Screemer

    Member Screemer GBAtemp Maniac

    Joined:
    Sep 21, 2008
    Messages:
    1,248
    Country:
    Germany
    there are still a few bugs left in libogc. the version hbc was compiled with had a bug that makes some sdhc cards unusable (this bug got fixed). a recompile of hbc woudl be great. i guess this bug in IOS_IoctlvFormat could get fixed in future releases.
     
  9. substring

    Newcomer substring Member

    Joined:
    Apr 2, 2009
    Messages:
    13
    Country:
    France
    I guess that the best would surely be to get in touch with the author of the usbstorage module. My C is a little rusty, I must admit ...
     
  10. ether2802

    Former Staff ether2802 we have the techno...!!

    Joined:
    Oct 14, 2007
    Messages:
    4,350
    Location:
    Pto. Vallarta
    Country:
    Mexico
    there is a tool that gives you info about your USB device, don't remember the name, I just know it can be downloaded thru Homebrew Browser..!! [​IMG]
     
  11. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany
    Might be not important, but:
    Am i the only one that sees that the 40 seconds wait loop inits the wbfs while the sdhc is unmounted while the loader usually mounts the sdhc module first and then tries the wbfs init. As long as your loader doesn't read anything from sd card, i would test what happens if the sdhc module isn't touched at all.

    Hmm, you get an error with wbfs init if your hdd is connected, right? What happens if you do the wbfs init with your usb pen, pause the program until button press, and then do the wbfs open?

    PS: Unfortunately my usb/firwire enclosure is too good, i never manged to see an usb storage error with it whatever i tried. And that with a HDD that i couldn't get recognized at 2 different WinXP computers(no error there, just no device at all).
     
  12. ether2802

    Former Staff ether2802 we have the techno...!!

    Joined:
    Oct 14, 2007
    Messages:
    4,350
    Location:
    Pto. Vallarta
    Country:
    Mexico
    He can use his HDD but only swapping it:

    He connects the USB stick (formatted as FAT32)
    says YES to format as WBFS, but dont' press A
    Swapps the USB stick for the HDD
    Press B to go back to the main menu, and there is when he gets the HDD to be recognized....!!! [​IMG]
     
  13. WiiPower

    Member WiiPower GBAtemp Guru

    Joined:
    Oct 17, 2008
    Messages:
    8,165
    Country:
    Germany

    PS: And i would take a closer look at USBStorage_Init too. And try to figure out which part of it fails.
     
  14. apcarr

    Member apcarr GBAtemp Regular

    Joined:
    Jun 16, 2007
    Messages:
    100
    Location:
    Manchester,England
    Country:
    United Kingdom
    Guys dont know if you know but this was kind of fixed with LoPsT edition of the 1.1 loader,I've got a drive here that will not get recognised by any loader without doing the swap trick but it works every time with USB_Loader_1.1.LoPsT_edition,Maybe someone can take a look at that and see if it helps.
     
  15. substring

    Newcomer substring Member

    Joined:
    Apr 2, 2009
    Messages:
    13
    Country:
    France
    you means lsusb ? I think it's somewhere on wiibrew, even if I saw it here too, on a post to gather data about incompatible HDD
     
  16. frankomio

    Newcomer frankomio Member

    Joined:
    Apr 9, 2009
    Messages:
    33
    Country:
    Germany
    The sourcecode that dteyn has posted in post#2 is exactly the LOPST-MOD !!!


    Has anybody compiled then "Idea" of DTEYN ?
    I wanted too, but my devkitpro is dirty
     
  17. ether2802

    Former Staff ether2802 we have the techno...!!

    Joined:
    Oct 14, 2007
    Messages:
    4,350
    Location:
    Pto. Vallarta
    Country:
    Mexico
    Yeah that's the one, maybe we should gather some info (or found the thread that already gathered this info) and start from there...!!!

    P.S. By "we" I mean you guys, cause I help more being out the room [​IMG]
     
  18. substring

    Newcomer substring Member

    Joined:
    Apr 2, 2009
    Messages:
    13
    Country:
    France
    And here we go ...
    This is the thread I have already spent some time mining everyone's report, and TBH, I couldn't find any matching pattern for unrecognized HDDs ...

    So, if i'm right : if the usbstorage can't get the right capacity, it's because it can't find the sector size ...
     
  19. substring

    Newcomer substring Member

    Joined:
    Apr 2, 2009
    Messages:
    13
    Country:
    France
  20. Dteyn
    OP

    Member Dteyn GBAtemp Fan

    Joined:
    Aug 3, 2008
    Messages:
    338
    Country:
    Canada
    I have a feeling the problem is related to my hard drive enclosure (cheap no-name model), I plan on picking up another one in the future so I'll keep you guys posted if the new enclosure works with the same hard drive or not.

    The exact procedure that I follow is:

    1. Start USB Loader with either hard drive or FAT32 USB stick, I've tested both. Sometimes the USB Loader doesn't recognize the FAT32 stick right away and requires a replug, so I usually start the USB Loader with the hard drive connected anyways, so I can then insert the USB stick.
    2. Wait for the "No WBFS Partition Found", or if the USB stick has a light, wait for it to flash twice indicating it's read the partitions, usually takes 2-3 seconds.
    3. Remove the USB stick, plug in the hard drive.
    4. Press A, then the hard drive light flashes and about 3 seconds later it shows the partitions.
    5. Press B, and the loader returns to the main menu with all my games listed and ready to play (all works fine until reboot).

    The weird thing is, I can see the loader trying to access the hard drive during the initial 40 second delay.. it flashes every second or so as it retries to init the hard drive. But as it doesn't get anywhere, it eventually times out if I don't do the swap trick. At least the 40 seconds gives me a chance to do the swap if I forget and leave the hard drive connected, older versions of the loader would just give ret -1 and I'd have to reboot the Wii with the USB stick in.

    I'll try lsusb and the USB mass storage tester and report back with results.
     

Share This Page