Welcome! Log In Create A New Profile

Advanced

Loading an external dol/elf file

Posted by newlife 
Loading an external dol/elf file
June 17, 2010 04:09PM
hi, i have seen that it is possable to load a dol/elf file from within a application (like HBC does) and i wanted to do this. I want to make a game with mini games that can be indipendently updated without the need for a compleate rerelease. specially since i am useing saves. The mini apps would be in a standerd place 'SD:\apps\appname\minigames\minigamename.dol'

is there any easy way to do this and what libaries need useing (and adding to the make file)

thanks

new
Re: Loading an external dol/elf file
June 17, 2010 05:41PM
Take a look at the loadmii source here: [github.com]

It can boot dols or elfs
Re: Loading an external dol/elf file
June 17, 2010 11:34PM
thanks, will take a look when i have more time :)
Re: Loading an external dol/elf file
June 20, 2010 12:39AM
ok, i have has a look and looks complicated. Is there an easyer way to do it?? or atleast a tutorial or step by step guide, so i can see what each part does and why.
Re: Loading an external dol/elf file
June 20, 2010 12:52AM
ok, having done my additional research i dont suppost that 'system(Dol path);' where dol path is the path to where the .dol is held would work would it? I know it uses the stdlib.h and stdio.h, but i can include them for my app. and the wii would handel the dols wouldent it?
Re: Loading an external dol/elf file
June 20, 2010 02:29AM
I don't think that would work, but as far as understanding the source,

if (kMap & KEY_A)
                {
if (getItem(index)->size == 0)
{
updatePath(getItem(index)->name);
index = 0;
}
else
{
if (supportedFile(getItem(index)->name))
{
u8 *bufPtr = memoryLoad(getItem(index));
void (*entry)() = (void*)0x80001400;
/* Do the right relocation. */
switch (validateHeader(bufPtr))
{
case 0x0:
entry = (void *)relocateDol(bufPtr);
break;
case 0x1:
entry = (void *)relocateElf(bufPtr);
break;
}

IOS_ReloadIOS(LOADMII_DEFAULT_IOS);
cleanup();

entry();
}
}
}
Lets rewright this in psudo code:
If the key A is pressed 
  if the item has no size
    if it is a folder, then goto that folder
    set the index(current file selected to 0)
 otherwise
    if the file is a supported type .elf/.dol
      load the file into memory, and then store a pointer to it called bufPtr
      set the entry point to 0x80001400(not that this matters, it will be replaced later)
   if the file is a .dol
     set up the file as a dol
   otherwise
     set up the file as a elf
   load the correct IOS
   delete allocated memory that is no longer needed
   start the program
I hope this helped, if you want a more indepth look at any of the functions just ask. A lot of what this program does is pointer manipulation.
Re: Loading an external dol/elf file
June 20, 2010 11:47AM
thanks, looks good :) So i guess i would need to include the bootstuff.h file aswell. i dont suppose it would work if i did
{
if (supportedFile(*file location*))
{
u8 *bufPtr = memoryLoad(getItem(index));
void (*entry)() = (void*)0x80001400;
/* Do the right relocation. */
switch (validateHeader(bufPtr))
{
case 0x0:
entry = (void *)relocateDol(bufPtr);
break;
case 0x1:
entry = (void *)relocateElf(bufPtr);
break;
}

IOS_ReloadIOS(LOADMII_DEFAULT_IOS);
cleanup();

entry();
}
}
and then include all the other bits in that code.
Just wondering because i am useing set dols that i want to load. so it would be easyer if i can just pass it the dol path directally. and if my app is runing from sd:\apps\game1\game1 and my minni game is at sd:\apps\game1\minnigames\minnigame would i need to pass it sd:\apps\game1\minnigames\minnigame or just \minnigames\minnigame?
just wondering.

also would the return to loader code work to return to my main game?



Edited 1 time(s). Last edit at 06/20/2010 11:48AM by newlife.
Re: Loading an external dol/elf file
June 21, 2010 12:10AM
well, return to loader should definaitally work for you. However i dont know enough about this code to awnser weather or not your rewright would work.
Re: Loading an external dol/elf file
June 21, 2010 03:39AM
for your code, all you would need is this:

u8 *bufPtr = 0x92000000;

FILE *fp = fopen("path to file starting from root","rb")
fread(bufPtr,1,size_of_file,fp)
void (*entry)();
entry = (void *)relocateDol(bufPtr)
IOS_ReloadIOS(correctIOS)
//Do clean up stuff, like deallocating memory
entry();
assuming that correctIOS is the IOS you want to use, and that the file you want to use is a .dol this should work, but I haven't tested it yet. You also need to know the size of the file. I know there is an easy way to find this out, but I can't remember it at the moment.
Once you get your app working I would STRONGLY reccomend going back through this code and finding out how it works. If you need help, just ask, it really isn't too complicated. It just looks that way.
Re: Loading an external dol/elf file
June 21, 2010 09:51AM
I will be rereading this app to understand it once my app is working. Its just that i'm on a strict time shedual to get it working. Thanks a million.

--edit--

qucik checks:
the libs i need to include are just STDIO and FAT
The Correct IOS bit, can i just change that to the IOS number i want to use? or is it preset on the wii to whatever?
and i take it i need to set size_of_file to the file size then? anyboy know how to find the size of the dol dynamically? or am i going to have to do it manually? and i take it it is size in bites?



Edited 1 time(s). Last edit at 06/21/2010 12:40PM by newlife.
Re: Loading an external dol/elf file
June 21, 2010 07:27PM
for file size you can look here
I'm sorry i can't help you with IOS, I don't know that much about them.
Re: Loading an external dol/elf file
June 21, 2010 08:54PM
Set the IOS to the one you want to use. Not strictly necessary if you ask me to reload the IOS, because if its game type stuff, it'll be fine running on IOS36, which is what it'll load on anyway.
Re: Loading an external dol/elf file
June 21, 2010 11:09PM
OK, thanks, thats excelent. All i need to do now is impliment it :) Go me.

Also i have started reading the origonal app and i am starting to get how it works. thanks all for your help :)

Just a memo to self
u8 *bufPtr = 0x92000000;

int size_of_file
FILE *fp = fopen("path to file starting from root","rb")
fseek(fp, 0, SEEK_END); 
size_of_file = ftell(fp);
fseek(fp, 0, SEEK_SET); 
fread(bufPtr,1,size_of_file,fp)
void (*entry)();
entry = (void *)relocateDol(bufPtr)
IOS_ReloadIOS(correctIOS)
//Do clean up stuff, like deallocating memory
entry();



Edited 1 time(s). Last edit at 06/21/2010 11:17PM by newlife.
Sorry, only registered users may post in this forum.

Click here to login