Welcome! Log In Create A New Profile

Advanced

Homebrew Channel Freezes w/o Internet

Posted by Qufa 
Homebrew Channel Freezes w/o Internet
December 06, 2011 10:33PM
I have the homebrew channel and the emulators FCE Ultra GX, Snes 9x GX, VBA GX, Genesis Plus, and Wii 64 and Wii MC. With the Wii connected to the internet everything works fine, but if the internet is not connected then the emulator or app will spontaneously crash. Usually within the first minute after loading it. I don't understand why this happens. These apps shouldn't require the internet to use, but without the internet they crash. It takes me to a black screen giving me an error message and then says it's going to reload, but then it doesn't reload. Would using a different homebrew loader help?
Also, in VBA GX, if I do get it to work (e.g. it doesn't crash) then if I press the home button the game continues to play but the controls no longer works and it doesn't go to the menu.



Edited 1 time(s). Last edit at 12/06/2011 10:34PM by Qufa.
Re: Homebrew Channel Freezes w/o Internet
December 06, 2011 10:49PM
It's a bug in HBC that causes a crash in any app loaded without reloading IOS (some apps now do not reload IOS due to a new feature added to HBC which allows them to use more advanced features of the Wii if they do not). Whether an app reloads IOS or not is controlled by a line in the meta.xml of the application, which has the line "" if IOS is not reloaded. You could try removing this line and the apps should no longer crash, but they may not function correctly without the features gained by preventing IOS reload.

There is a fix for this, that must be applied to the source of apps, so you could contact the author of the emulators and ask them to add it.

Here is the code, written by davebaol and posted at a forum we can't link to here:

#define HAVE_AHBPROT ((*(vu32*)0xcd800064 == 0xFFFFFFFF) ? 1 : 0)
#define MEM_REG_BASE 0xd8b4000
#define MEM_PROT (MEM_REG_BASE + 0x20a)

static void disable_memory_protection() {
    write32(MEM_PROT, read32(MEM_PROT) & 0x0000FFFF);
}

static u32 apply_patch(char *name, const u8 *pattern, u32 pattern_size, const u8 *patch, u32 patch_size, u32 patch_offset) {
    u8 *ptr_start = (u8*)*((u32*)0x80003134), *ptr_end = (u8*)0x94000000;
    u32 found = 0;
    u8 *location = NULL;
    while (ptr_start < (ptr_end - patch_size)) {
        if (!memcmp(ptr_start, pattern, pattern_size)) {
            found++;
            location = ptr_start + patch_offset;
            u8 *start = location;
            u32 i;
            for (i = 0; i < patch_size; i++) {
                *location++ = patch;
            }
            DCFlushRange((u8 *)(((u32)start) >> 5 << 5), (patch_size >> 5 << 5) + 64);
            ICInvalidateRange((u8 *)(((u32)start) >> 5 << 5), (patch_size >> 5 << 5) + 64);
        }
        ptr_start++;
    }
    return found;
}

const u8 es_set_ahbprot_pattern[] = { 0x68, 0x5B, 0x22, 0xEC, 0x00, 0x52, 0x18, 0x9B, 0x68, 0x1B, 0x46, 0x98, 0x07, 0xDB };
const u8 es_set_ahbprot_patch[]   = { 0x01 };

u32 IOSPATCH_AHBPROT() {
    if (HAVE_AHBPROT) {
        disable_memory_protection();
        return apply_patch("es_set_ahbprot", es_set_ahbprot_pattern, sizeof(es_set_ahbprot_pattern), es_set_ahbprot_patch, sizeof(es_set_ahbprot_patch), 25);
    }
    return 0;
}

int main(int argc, char* argv[])
{
    int ret;
  
    /* Enable AHBPROT on title launch */
    ret = IOSPATCH_AHBPROT();
    if (ret) {
        /* Reload current IOS, typically IOS58 */
        IOS_ReloadIOS(IOS_GetVersion());
    }
    else {
        /*
         * Fatal error!!!
         * Unable to patch the running IOS.
         * The application has been likely launched without AHBPROT access rights. 
         */
    }

    /*
     * Put your code here
     */
}

If the author of the emulators is willing to add this, it should fix your problems.
Re: Homebrew Channel Freezes w/o Internet
December 06, 2011 11:45PM
Neat... thank for the code, will test it and eventually add it, this bug is kinda annoying indeed.
Re: Homebrew Channel Freezes w/o Internet
December 06, 2011 11:56PM
If you're interested, what the code does is patch the currently running IOS to bypass the HW_AHBPROT flag check, making the current IOS always load the next title with HW_AHBPROT enabled. It then reloads IOS. This allows it to reload IOS and keep HW_AHBPROT. Reloading IOS fixes the bug cuased by HBC.
Re: Homebrew Channel Freezes w/o Internet
December 07, 2011 12:20AM
yes, I figured that... though you still have to re-enable DVD Video commands (which is what the no_ios_reload feature was used here for in the first place) after reloading IOS, but since you have full hardware access, it's as easy as writing the good register

actually I looked more closely and it's actually the exact same patch I was given to by some user a few months ago so it seems we have similar sources ^^
for some reason though, i noted that this code would sometime fail as I lose DVD access randomly when reloading the app. not sure where this comes from though.



Edited 4 time(s). Last edit at 12/07/2011 12:35AM by ekeeke.
Re: Homebrew Channel Freezes w/o Internet
December 08, 2011 12:02AM
There are several things wrong with that code:
- The ptr_start and ptr_end addresses used by that patch are completely ridiculous. Not only does it start way down near the beginning of MEM1 (where IOS obviously won't be located), it also iterates through all the (invalid) memory between MEM1 and MEM2 which will cause a DSI if the BATs aren't set in a lazy way (luckily libogc is lazy).
- It's stupid to increment by a single byte when it's searching for code that will be aligned to (at least) halfword addresses.
- Uses ICInvalidateRange on memory that the CPU will never ever execute.
- Uses write32/read32 on MEM_PROT which is a 16-bit register at a non mod 4 address - this will cause an alignment exception.
Re: Homebrew Channel Freezes w/o Internet
December 08, 2011 01:23AM
Will using a different loader stop it from freezing? Or installing the channels for the emulators?
I'm all for getting everything updated and fixed, but I would like at least a temporary solution since I have a friend who has a wii, but no internet.
Re: Homebrew Channel Freezes w/o Internet
December 08, 2011 05:51PM
Installing the channels should work I think.

and tueidj, I'm no programmer so I don't know these things. I just posted what I had found and had been reported by some to work. Don't shoot the messenger ;)
Re: Homebrew Channel Freezes w/o Internet
December 08, 2011 09:20PM
@tuedj: start address is nowhere near MEM1, it is actually the end of IOS heap in MEM2, which, as system value can be read at $80003134 according to wiibrew. As for read32/write32, i think libogc actually "realigns" things properly so no exceptions. I agree though, the code is not "perfect" and i modified it a little bit personally but I was more interested in the ARM code patch anyway, which was out of my competences, and i like the idea of safe "on the fly" IOS patching.

@Qufa: the easiest temporary solution is as said earlier to remove the no_ios_reload in meta xml files. You lose ability to load games from a DVD but it's no big loss if you don't use that feature.



Edited 2 time(s). Last edit at 12/08/2011 10:02PM by ekeeke.
Re: Homebrew Channel Freezes w/o Internet
December 08, 2011 09:44PM
Quote
ekeeke
@tuedj: start address is nowhere near MEM1, it is actually the address of IOS area start, which is stored at $80000134 according to wiibrew.
It's the end of the IOS heap area. IOS sets that value when it is loaded and since it hasn't been reloaded before the app starts, there's no way of knowing if it has been modified. It would be safer (or at the very least, more consistent) to hardcode it like the end value.
Quote

As for read32/write32, i think libogc actually "realigns" things properly so no exceptions.
Nope, libogc doesn't have a handler for alignment exceptions. Some PowerPC CPUs do support unaligned integer loads/stores without raising an exception by breaking the data into smaller chunks, obviously this should be avoided because it's slower and in this case it's especially dumb because the register we want to change is only 16 bits (hence the masking).
Re: Homebrew Channel Freezes w/o Internet
December 08, 2011 10:32PM
I was just editing it yeah, anyway it doesn't scan MEM1 or invalid gaps as you initially pointed out, that's just what i wanted to say. What kind of hard-coded value would you advise ? Is there really any maximal size for IOS occupation ? I 'd rather first check if the values stored into sys area for IOS heap are valid then eventually use hard-coded value in the rare case of the loader corrupting things...

About memory access macros, i was more talking about a mask on the address passed as parameter than a specific handler, but i just checked and it doesn't, thing is i don't remember this code causing any exceptions when i tested it , so wii PPC is probably the kind of model that allows this. Good to know but as you said, better avoid it.



Edited 1 time(s). Last edit at 12/08/2011 10:37PM by ekeeke.
Re: Homebrew Channel Freezes w/o Internet
December 08, 2011 10:50PM
Quote
ekeeke
@Qufa: the easiest temporary solution is as said earlier to remove the no_ios_reload in meta xml files. You lose ability to load games from a DVD but it's no big loss if you don't use that feature.
Awesome. Thanks. Thank you, too, SifJar. When SifJar said it would lose some functionality, I didn't know it would only be DVD support and I didn't want to screw things up for my friend. We can do without the DVD support for now, though, so thank you guys again.
Re: Homebrew Channel Freezes w/o Internet
December 08, 2011 11:54PM
I wasn't sure if there was anything else that the emulators used HW_AHBPROT for or not, or I would have specified. Apologies for making you think you'd lose more than you actually would.
Re: Homebrew Channel Freezes w/o Internet
December 09, 2011 01:46AM
Quote
SifJar
I wasn't sure if there was anything else that the emulators used HW_AHBPROT for or not, or I would have specified. Apologies for making you think you'd lose more than you actually would.
It's all good, man. I appreciate that you only said what you know instead of pretending to know things that you're not sure about.
Sorry, only registered users may post in this forum.

Click here to login