forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Trying to load an elf

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Ruj89



Joined: 12 Jun 2007
Posts: 12

PostPosted: Tue Jun 12, 2007 7:20 am    Post subject: Trying to load an elf Reply with quote

I'm using this piece of code to load a 1.00 eboot
unpack-pbp.h
Code:
// Dan Peori (peori@oopo.net)
// modded by Ruggero Russo (ruj89@crazynet.org)
// 0: no errors
//-1: infile errors
//-2: wrong infile format
//-3: memory allocation errors
//-4: outfile errors

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <string.h>
#include <stdlib.h>

#define printf pspDebugScreenPrintf

typedef struct { char signature[4]; int version; int offset[8]; } HEADER;

int extract_elf(char file_path[256]) {
  HEADER header;
  int total_size, size, infile, outfile;
  void *buffer;

  // Check the argument count.
  if(file_path == "") { printf("USAGE: %s <filename>\n", file_path); return -1; }

  // Open the input file.
  if(!(infile = sceIoOpen(file_path, PSP_O_RDONLY, 0777))) { printf("ERROR: Could not open the input file. (%s)\n", file_path); return -1; }

  // Get the input file size.
  total_size = sceIoLseek(infile, 0, PSP_SEEK_END);
  sceIoLseek(infile, 0, PSP_SEEK_SET);
  if (total_size < 0) { printf("ERROR: Could not get the input file size.\n"); return -1; }

  // Read in the input file header.
  if (sceIoRead(infile, &header, sizeof(HEADER)) < 0) { printf("ERROR: Could not read the input file header.\n"); return -1; }

  // Check the input file signature.
  if (header.signature[0] != 0x00) { printf("ERROR: Input file is not a PBP file or it is kxploited.\n"); return -2; } else
  if (header.signature[1] != 0x50) { printf("ERROR: Input file is not a PBP file or it is kxploited.\n"); return -2; } else
  if (header.signature[2] != 0x42) { printf("ERROR: Input file is not a PBP file or it is kxploited.\n"); return -2; } else
  if (header.signature[3] != 0x50) { printf("ERROR: Input file is not a PBP file or it is kxploited.\n"); return -2; }

  // For data.psp section... 
  // Get the size of the section data.
  size = header.offset[7] - header.offset[6];
 
  // Allocate the section data buffer.
  buffer = malloc(size);
  if (buffer == NULL) { printf("ERROR: Could not allocate the section data buffer. (%d)\n", size); return -3; }
 
  // Read in the section data.
  if (sceIoRead(infile, buffer, size) < 0) { printf("ERROR: Could not read in the section data.\n"); return -1; }
 
  // Open the output file.
  if(!(outfile = sceIoOpen("ms0:/eboot.elf", PSP_O_WRONLY|PSP_O_CREAT, 0777))) { printf("ERROR: Could not open the output file. (eboot.elf)\n"); return -4; }
 
  // Write out the section data.
  if (sceIoWrite(outfile, buffer, size) < 0) { printf("ERROR: Could not write out the section data.\n"); return -4; }
 
  // Close the output file.
  if (sceIoClose(outfile) < 0) { printf("ERROR: Could not close the output file.\n"); return -4; }
 
  // Free the section data buffer.
  free(buffer);
 
  // Output the section information.
  printf("%8d bytes | eboot.elf\n", size);
 
  // Close the input file.
  if (sceIoClose(infile) < 0) { printf("ERROR: Could not close the input file.\n"); return -1; }

  return 0;
}


main.c
Code:
#include <pspdebug.h>
#include <pspuser.h>
#include <string.h>
#include <pspsdk.h>

#include "unpack-pbp.h"

PSP_MODULE_INFO("ssaver",0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

#define printf   pspDebugScreenPrintf

int extract_elf(char file_path[256]);

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
   sceKernelExitGame();
   return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
   int cbid;

   cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
   sceKernelRegisterExitCallback(cbid);

   sceKernelSleepThreadCB();

   return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
   int thid = 0;

   /* Note the use of THREAD_ATTR_USER to ensure the callback thread is in user mode */
   thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, NULL);
   if(thid >= 0)
   {
      sceKernelStartThread(thid, 0, 0);
   }

   return thid;
}

int main(int argc, char **argv)
{
  SceKernelLMOption option;
  int status;
  SceUID ssaver;

  pspDebugScreenInit();
  SetupCallbacks();
  extract_elf("ms0:/eboot_mod.pbp");

  memset(&option, 0, sizeof(option));
  option.size = sizeof(option);
  option.mpidtext = 2;
  option.mpiddata = 2;
  option.position = 0;
  option.access = 1;

  ssaver = sceKernelLoadModule("ms0:/eboot.elf",0,&option);
  if(ssaver < 0) printf("Can't load the elf file");
  else sceKernelStartModule(ssaver,0,NULL,&status,NULL);

  sceKernelSleepThread();
  return 0;
}



Why does it show the error message "Can't load the elf file"? I tried to extract the elf using PSPBrew and to comment the extract_elf function, but it was the same...


Last edited by Ruj89 on Tue Jun 12, 2007 6:35 pm; edited 1 time in total
Back to top
View user's profile Send private message
be2003



Joined: 20 Apr 2006
Posts: 144

PostPosted: Tue Jun 12, 2007 7:34 am    Post subject: Reply with quote

my guess is that you cannot load and start an elf the same way you load and start a prx module

im pretty sure you can load a 1.00 eboot using sceKernelLoadExec
the prototype is in psploadexec.h
_________________
- be2003
blog
Back to top
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Tue Jun 12, 2007 10:46 am    Post subject: Reply with quote

PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);

use 0 for kmode thread
_________________
10011011 00101010 11010111 10001001 10111010
Back to top
View user's profile Send private message
be2003



Joined: 20 Apr 2006
Posts: 144

PostPosted: Tue Jun 12, 2007 11:02 am    Post subject: Reply with quote

man, i constantly feel like an idiot
_________________
- be2003
blog
Back to top
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Tue Jun 12, 2007 11:58 am    Post subject: Reply with quote

Pick your head up, cuz there are lots of people who would like to see you Fall :)

so don't get yourself down
_________________
10011011 00101010 11010111 10001001 10111010
Back to top
View user's profile Send private message
Ruj89



Joined: 12 Jun 2007
Posts: 12

PostPosted: Tue Jun 12, 2007 5:48 pm    Post subject: Reply with quote

dot_blank wrote:
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);

use 0 for kmode thread


It's the same...
I use the cf 3.40 and i put my program in GAME150 folder. I also tried in GAME folder, setting it in 1.50 mode, but my program didn't work.

Is cf ok?

be2003 wrote:
my guess is that you cannot load and start an elf the same way you load and start a prx module

im pretty sure you can load a 1.00 eboot using sceKernelLoadExec
the prototype is in psploadexec.h


Oh, I know that sceKernelLoadExec can load an eboot, but, as irshell, I don't want to reboot the kernel when I start the homebrew. That's my target...
Back to top
View user's profile Send private message
be2003



Joined: 20 Apr 2006
Posts: 144

PostPosted: Wed Jun 13, 2007 5:42 am    Post subject: Reply with quote

why dont u try using some of the functions in the pspsdk utility library?
_________________
- be2003
blog
Back to top
View user's profile Send private message
Ruj89



Joined: 12 Jun 2007
Posts: 12

PostPosted: Wed Jun 13, 2007 6:19 am    Post subject: Reply with quote

I used
Code:

  ssaver = pspSdkLoadStartModule("ms0:/eboot.elf",PSP_MEMORY_PARTITION_KERNEL);


And i got the same result.
That's 3 days i'm trying to mix functions, please help me!
Back to top
View user's profile Send private message
be2003



Joined: 20 Apr 2006
Posts: 144

PostPosted: Wed Jun 13, 2007 7:30 am    Post subject: Reply with quote

u did use all the patches in the pspsdk utility library right?
_________________
- be2003
blog
Back to top
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Wed Jun 13, 2007 8:02 am    Post subject: Reply with quote

you want to add this function just before your defined printf

Code:
__attribute__ ((constructor))
void loaderInit(){
   pspKernelSetKernelPC();
   pspSdkInstallNoDeviceCheckPatch();
   pspSdkInstallNoPlainModuleCheckPatch();
   pspSdkInstallKernelLoadModulePatch();
}

_________________
10011011 00101010 11010111 10001001 10111010
Back to top
View user's profile Send private message
Ruj89



Joined: 12 Jun 2007
Posts: 12

PostPosted: Wed Jun 13, 2007 6:57 pm    Post subject: Reply with quote

These are the errors:

1) If I use the program normally, I have a SCE_KERNEL_ERROR_UNSUPPORTED_PRX_TYPE error

2) If I extract the data.psp using a PC program, there is another error:
SCE_KERNEL_ERROR_PARTITION_MISMATCH

3) If I change the partition to PSP_MEMORY_PARTITION_USER, this is the error:
SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED


So I understand that my extract_elf function doesn't work, the elf should be loaded in an user partition, and I can't understand the third error.

Actually my main.c code is:

Code:
#include <pspdebug.h>
#include <pspuser.h>
#include <string.h>
#include <pspsdk.h>

#include "unpack-pbp.h"

PSP_MODULE_INFO("SSAVER",0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);

__attribute__ ((constructor)) void loaderInit(){
   pspKernelSetKernelPC();
   pspSdkInstallNoDeviceCheckPatch();
   pspSdkInstallNoPlainModuleCheckPatch();
   pspSdkInstallKernelLoadModulePatch();
}

#define printf   pspDebugScreenPrintf

int extract_elf(char file_path[256]);

/*(callbacks...)*/

int main(int argc, char **argv)
{
  SceUID ssaver;

  pspDebugScreenInit();
  SetupCallbacks();
  extract_elf("ms0:/eboot_mod.pbp");

  ssaver = pspSdkLoadStartModule("ms0:/eboot.elf",PSP_MEMORY_PARTITION_KERNEL);
  if(ssaver != 0) printf("ERROR: Can't load the elf file (0x%x)",ssaver);

  sceKernelSleepThread();
  return 0;
}


How can I fix it?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group