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 

What has changed in coding for the newer firmwares ?

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



Joined: 31 Dec 2005
Posts: 288

PostPosted: Tue Oct 09, 2007 12:46 am    Post subject: What has changed in coding for the newer firmwares ? Reply with quote

Hi folks,

I have created some code and some games for the 1.5 firmwares, that code just works fine onwards to the OE versions (tested up to 3.02 OE)
however code that works fine does not work correctly anymore on m33, since I do not want to upgrade to that firmware I am stuck with this problem. Can anybody tell me what function calls and the sort have changed/added/deleted etc.? or is there something else going on?

one thing was that a lot did not work with setting the processor to 333 but when i set it to 222 it worked a lot better but not perfect. Are there more of these kinds of things? I have searched the forum but could not find anything, if i missed something please do let me know.

greets ghoti
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
PiCkDaT



Joined: 04 Oct 2007
Posts: 69

PostPosted: Tue Oct 09, 2007 3:23 am    Post subject: Reply with quote

I dont know if this has anything to do with it.. but the newer firmwares (or just the new slim psp idk) only support 2.00+ apps. I dont know if that means you have to code it different though. I think possibly you just change the fw version in the makefile? I'm no expert so dont totally depend on my word lol. I honestly dont know the difference in coding for other versions of firmwares I just do 1.50 :\
_________________
Enlighten me, Reveal my fate -- Follow - Breaking Benjamin
Back to top
View user's profile Send private message AIM Address
Istari



Joined: 30 Sep 2005
Posts: 10

PostPosted: Tue Oct 09, 2007 3:55 am    Post subject: Reply with quote

I think that it also needs to be built as a prx before being put in the eboot.pbp
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Tue Oct 09, 2007 4:00 am    Post subject: Reply with quote

So it should be made a fw 2.0 app and it need to be build as a prx?
are there other differences ?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
PiCkDaT



Joined: 04 Oct 2007
Posts: 69

PostPosted: Tue Oct 09, 2007 4:21 am    Post subject: Reply with quote

probably not... except newer firmwares probably means better functions? :) lol
_________________
Enlighten me, Reveal my fate -- Follow - Breaking Benjamin
Back to top
View user's profile Send private message AIM Address
CpuWhiz



Joined: 04 Jun 2007
Posts: 42

PostPosted: Tue Oct 09, 2007 5:05 am    Post subject: Porting a 1.50 firmware homebrew to 3.xx firmware Reply with quote

Someone should sticky a article like this as a lot of people ask about this. Comments or suggestions would be welcome. If you want to provide links related to this to add in a links selection, that would be nice.

Porting a 1.50 firmware homebrew to 3.xx firmware

3.xx firmwares require your homebrew be in prx format. To get your homebrew in this format, you need to follow a few basic steps:

1. Modify your Makefile - You need to add the following to your Makefile to compile a prx (before the include $(PSPSDK)/lib/build.mak line):
Code:
BUILD_PRX = 1
PSP_FW_VERSION = 371


2. Set your homebrew to user mode - Your homebrew needs to start in user mode. To do this, change the 2rd argument in PSP_MODULE_INFO to 0. For most homebrew you will also need to increase your heap size. The heap size is the amount of memory available to malloc. I set mine to 20mb. The bellow code should be at the top of your main source file (normally main.c).
Code:
PSP_MODULE_INFO("My Homebrew", 0, 1, 0);
PSP_HEAP_SIZE_KB(20480);


Alternatively you can use PSP_HEAP_SIZE_MAX(); if you have a toolchain compiled on or after Sep. 30th, 2007 (revision 2321). This will allocate as big of a heap as it can. Please note you should recompile your entire toolchain (or at least pspsdk and newlib) to use this, otherwise your homebrew will crash with a Exception - Bus error (data).

3. Try running your app - You should now be able to compile your app with a normal make and copy over the EBOOT.PBP per usual. There is no kxploit or % folder for 3.xx firmware. If you are running your application from psplink, you need to run the prx file instead of the elf file or it will not run. At this point your homebrew should run unless you have kernel calls in your code. If your code has kernel calls you will get a 0x8002013C error when you try to start the homebrew. Don't panic, move on to step 4. If your homebrew runs, great, skip step 4.

4. Locate and deal with your kernel calls - You need to figure out what is a kernel call and what isn't. To do this, you can use prxtool -f <prx file>. Here is a example output:
Code:
$ prxtool -f project.prx
... output left out (it's a lot of output) ...
Import 9, Name UtilsForUser, Functions 1, Variables 0, flags 40010000
Functions:
0x79D1C3FA [0x0008CF34] - UtilsForUser_79D1C3FA
Import 10, Name LoadExecForUser, Functions 2, Variables 0, flags 40010000
Functions:
0x05572A5F [0x0008CF3C] - LoadExecForUser_05572A5F
0x4AC57943 [0x0008CF44] - LoadExecForUser_4AC57943
Import 11, Name IoFileMgrForKernel, Functions 1, Variables 0, flags 00010000
Functions:
0x411106BA [0x0008CF4C] - IoFileMgrForKernel_411106BA
Done


If you look at the above output you can see there is a import called IoFileMgrForKernel. This import has one function. Refer to this page: http://silverspring.lan.st/1.5x/kd/iofilemgr.html. Search on the page and you will find that 0x411106BA matches the function sceIoGetThreadCwd. You can now search for this function and either (a) replace the kernel call with user mode code -or- (b) move the kernel call into a kernel mode prx and load that kernel mode prx from your homebrew. Option B is out of the scope of this tutorial so search the forums to figure out how to do this. Option A is the preferable solution unless you have to use a kernel call. I went to the main page http://silverspring.lan.st and clicked on 1.5x firmware. From this page I found sceIOFileManager in the list and clicked on it to get to the above page. A search function would have been nice.


Last edited by CpuWhiz on Tue Oct 09, 2007 12:09 pm; edited 2 times in total
Back to top
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Tue Oct 09, 2007 6:14 am    Post subject: Reply with quote

Hi

that tutorial is really nice !! Can I use this information on my site? (to help others)
So basicly what you say is you can only run this in higher firmwares, so for game releases there should be a 1.50 release and a 3.x release right?
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
CpuWhiz



Joined: 04 Jun 2007
Posts: 42

PostPosted: Tue Oct 09, 2007 7:11 am    Post subject: Reply with quote

Ghoti wrote:
Can I use this information on my site? (to help others)


I don't mind. I wrote it to help others, so go for it. Just don't claim it as your own and we're cool.

Ghoti wrote:
So basically what you say is you can only run this in higher firmwares, so for game releases there should be a 1.50 release and a 3.x release right?


Yes. If you remove your kernel calls (if you had any), all you should have to do to make a 1.50 build is to comment out the two lines in the Makefile and (I think) the PSP_HEAP_SIZE_KB line, then build normally.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Tue Oct 09, 2007 7:15 am    Post subject: Re: Porting a 1.50 firmware homebrew to 3.xx firmware Reply with quote

CpuWhiz wrote:

2. Set your homebrew to user mode - Your homebrew needs to start in user mode. To do this, change the 3rd argument in PSP_MODULE_INFO to 1. For most homebrew you will also need to increase your heap size. The heap size is the amount of memory available to malloc. I set mine to 20mb. The bellow code should be at the top of your main source file (normally main.c).
Code:
PSP_MODULE_INFO("My Homebrew", 0, 1, 0);
PSP_HEAP_SIZE_KB(20480);



Not quite... the SECOND argument = 0 is user mode. The third arg is the version number, and the fourth is the revision number. Also, I think the SDK was recently updated so that the heap was expanded to the max for 2.x/3.x homebrew, so the heap size shouldn't be needed anymore.
Back to top
View user's profile Send private message AIM Address
CpuWhiz



Joined: 04 Jun 2007
Posts: 42

PostPosted: Tue Oct 09, 2007 7:20 am    Post subject: Reply with quote

Sorry, minor mistake there. Thanks for the info and corrections J.F.

Edit: Do you mean PSP_HEAP_SIZE_MAX() from this revision?
Code:
------------------------------------------------------------------------
r2321 | tyranid | 2007-09-30 11:08:16 -0600 (Sun, 30 Sep 2007) | 2 lines

Added a define to allow easy allocation of all available memory for the heap (needs an updated newlib)

------------------------------------------------------------------------
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Tue Oct 09, 2007 8:30 am    Post subject: Reply with quote

CpuWhiz wrote:
Sorry, minor mistake there. Thanks for the info and corrections J.F.

Edit: Do you mean PSP_HEAP_SIZE_MAX() from this revision?
Code:
------------------------------------------------------------------------
r2321 | tyranid | 2007-09-30 11:08:16 -0600 (Sun, 30 Sep 2007) | 2 lines

Added a define to allow easy allocation of all available memory for the heap (needs an updated newlib)

------------------------------------------------------------------------


Probably, but I'm not exactly sure how that affects the programs as I haven't tested that myself. :)

As to the minor correction, it's easier to keep track of when you do it this way:

Code:
#define VERS    1
#define REVS    3

PSP_MODULE_INFO("IdStorageManager", 0, VERS, REVS);


Then just bump REVS or VERS each time you update the program. Minor changes should bump REVS, and major changes should bump VERS.
Back to top
View user's profile Send private message AIM Address
CpuWhiz



Joined: 04 Jun 2007
Posts: 42

PostPosted: Tue Oct 09, 2007 12:13 pm    Post subject: Reply with quote

I had to recompile my toolchain to test that out. PSP_HEAP_SIZE_MAX() works good and I have added it to my guide (and my app). Thanks J.F.

As for the suggestion on VERS and REVS - I already knew I could do that, but thanks anyway.
Back to top
View user's profile Send private message
PiCkDaT



Joined: 04 Oct 2007
Posts: 69

PostPosted: Tue Oct 09, 2007 10:17 pm    Post subject: Reply with quote

I dont think I have a clue since I have only been coding for a couple of days now.. but why can't you run in kernel mode 3.xx? I've got 3.03-C(maybe this is why?) and it works fine.. BUT here is what probably makes it work

Code:
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, NULL);


PSP_THREAD_ATTR_USER should make the thread in user mode correct? why cant you put it into kernel mode and run a user thread like this?

Code:

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

..
..

//From SDK Sample
int SetupCallbacks(void)
{
   int thid = 0;

   thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, THREAD_ATTR_USER, 0);
   if(thid >= 0)
   {
      sceKernelStartThread(thid, 0, 0);
   }

   return thid;
}

I cannot run anything besides a user thread though in my firmware.. is this because this is the only way you can run it? or can you put in PSP_THREAD_ATTR_KERNEL? because I tried that(if it even works on other fw's) and it crashed :\
_________________
Enlighten me, Reveal my fate -- Follow - Breaking Benjamin
Back to top
View user's profile Send private message AIM Address
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Oct 10, 2007 1:04 am    Post subject: Reply with quote

Only 1.50 has a kernel mode exploit for running apps in kernel mode. Nothing else does, so everything else must be a user mode app. If you wish to use something from kernel level, you have to put it in an external library as demonstrated SEVERAL times in the last week in threads here.
Back to top
View user's profile Send private message AIM Address
PiCkDaT



Joined: 04 Oct 2007
Posts: 69

PostPosted: Wed Oct 10, 2007 2:50 am    Post subject: Reply with quote

Is it possible to find another kernel mode exploit or is it doomed? jw
_________________
Enlighten me, Reveal my fate -- Follow - Breaking Benjamin
Back to top
View user's profile Send private message AIM Address
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Thu Oct 11, 2007 6:12 am    Post subject: Reply with quote

It's not a question of exploits... we're already able to patch out any checks, otherwise you wouldn't be able to run code at all. Sony has restructured things a bit and it's just not easy (or correct) to run apps directly in kernel mode anymore.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Thu Oct 11, 2007 7:14 am    Post subject: Reply with quote

It think it's better not to run in kernel mode in any case. Sony can't really change user mode without breaking most the games, so sticking to user mode is better for compatibility. If you need something from kernel mode, use the external prx. Then when Sony changes kernel mode (like with 3.71), you just have to change the prx, not the entire program.
Back to top
View user's profile Send private message AIM Address
ppyyf



Joined: 19 Oct 2007
Posts: 2

PostPosted: Fri Oct 19, 2007 1:12 pm    Post subject: Re: Porting a 1.50 firmware homebrew to 3.xx firmware Reply with quote

CpuWhiz wrote:
Someone should sticky a article like this as a lot of people ask about this. Comments or suggestions would be welcome. If you want to provide links related to this to add in a links selection, that would be nice.
......


Hi, I am porting a homebrew YDICT (which is an English-Chinese Dict). I found that in the existing code, the second argument of PSP_MODULE_INFO had already been 0 (usermode). Does this mean I can skip the 4th step in your tutorial safely?

Thanks.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Fri Oct 19, 2007 3:07 pm    Post subject: Re: Porting a 1.50 firmware homebrew to 3.xx firmware Reply with quote

ppyyf wrote:
CpuWhiz wrote:
Someone should sticky a article like this as a lot of people ask about this. Comments or suggestions would be welcome. If you want to provide links related to this to add in a links selection, that would be nice.
......


Hi, I am porting a homebrew YDICT (which is an English-Chinese Dict). I found that in the existing code, the second argument of PSP_MODULE_INFO had already been 0 (usermode). Does this mean I can skip the 4th step in your tutorial safely?

Thanks.


Not necessarily. If it didn't have "BUILD_PRX = 1" in the makefile, it is being built and a static elf and won't be able to load external prxs. If it has that in the makefile, then maybe you can skip ahead.
Back to top
View user's profile Send private message AIM Address
Be3f



Joined: 15 Mar 2007
Posts: 59

PostPosted: Thu Jan 17, 2008 7:19 pm    Post subject: Reply with quote

If hb is compiled for the high fw, eg:
Code:
PSP_FW_VERSION = 371

-will it work same as kernel app on all 3.XX custom fws, as 3.40 OE?
_________________
00000110 00000110 00000110
Back to top
View user's profile Send private message Send e-mail
Be3f



Joined: 15 Mar 2007
Posts: 59

PostPosted: Thu Jan 17, 2008 7:47 pm    Post subject: Reply with quote

Be3f wrote:
If hb is compiled for the high fw, eg:
Code:
PSP_FW_VERSION = 371

-will it work same as kernel app on all 3.XX custom fws, as 3.40 OE?

Hmm... As i see, 3.XX hb may be compiled only in user mode, but you may do kernel calls via included kernel libs in KM PRX?
_________________
00000110 00000110 00000110
Back to top
View user's profile Send private message Send e-mail
adrahil



Joined: 16 Mar 2006
Posts: 277

PostPosted: Thu Jan 17, 2008 8:00 pm    Post subject: Reply with quote

Yeah.

The only REAL requirements are:
- EBOOT.PBP has to be in usermode (can be also an elf... but recommended t oadd BUILD_PRX=1 to makefile, along the EXTRA_TARGETS=EBOOT.PBP, and don't forget to expand stack)
- Don't call kernel stuff in usermode apps (and vice versa)

But apart that, you can make PRXs from kernel or usermode, as you wish :) Just don't forget to load them to the correct memory partition.
Back to top
View user's profile Send private message
Be3f



Joined: 15 Mar 2007
Posts: 59

PostPosted: Thu Jan 17, 2008 8:05 pm    Post subject: Reply with quote

Thanks! And 20480 Kb is the absolutely maximum for psp-fat, right?
_________________
00000110 00000110 00000110
Back to top
View user's profile Send private message Send e-mail
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Thu Jan 17, 2008 8:12 pm    Post subject: Reply with quote

I sucessfully used PSP_HEAP_SIZE_KB(21000) even on a Fat.... but that's pretty close to the limit, tried a bit more, and got errors then....

AFAIK this also applies to the Slim, since the additional memory is an additional mem partition and does not simple expand the "normal" memory we are used to use....
Back to top
View user's profile Send private message
adrahil



Joined: 16 Mar 2006
Posts: 277

PostPosted: Thu Jan 17, 2008 8:23 pm    Post subject: Reply with quote

There is a possibility to get more mem on the slim thanks to M33 firmwares :) But to maintain compatibility with Fat, it's better to keep to the limit.
Back to top
View user's profile Send private message
baffo



Joined: 15 Jan 2008
Posts: 3

PostPosted: Thu Jan 17, 2008 11:13 pm    Post subject: Reply with quote

I've read and I'm currently reading as much as I can find on prx related threads, and try to make things work on my sdk/psp with poor results, mainly because I've got these main big question without any clue, some points I found lead me to confusion:

1) I have to extract any kernel command in a separate c file, a completely dissociated c source with its own makefile (that build_prx=1 thing), that let me have a .prx file. Then I need another "main" c source that have to import those previous kernel calls. I'm trying this way but all I get is a psp crash.

2) when I add the build prx =1 in makefile I get both the pbp and the prx, working together and ready to be placed under game folder (afaik is impossible, with one source only)

3) both main makefile and prx's must have build_prx=1, or only the prx makefile

4) I'm a jerk and one can play directly the prx without an eboot (O__O sounds stupid, but I found a thread here telling to play a prx)

5) no prx needed, if I switch to user mode and add in my main.c makefile build_prx=1 I get my eboot.pbp ready to go (and the exports? doesn't make sense 4 me, again I found a thread here with an example made this way)

6) I'm very very jerk because prx has not to stay in the eboot folder but in SEPLUGINS (or wherever else) and be enabled from recovery menu (I tried but always get crashes)

7) someone wrote "you can try playing the .elf" is it possible???? anyway I don't want an "elf" executable...

I tend to believe I have to code my pretty main.c with its own makefile, including the needed prx-file include
after compile I expect to obtain just the runnable eboot. (without prx=1 in makefile, I want a pbp here?)
Then I have to begin a brand new C project, provide the needed kernel calls, add the prx=1 thing in makefile and expect
to obtain my module.prx, and some exports file.
Done this, I copy the pbp and the prx in a nice game/371 folder and play the eboot (sometimes I get also a further
"corrupted data" icon, don't know if it's normal). Looks pretty easy, but after gameboot my psp crashes. :P
Back to top
View user's profile Send private message
sakya



Joined: 28 Apr 2006
Posts: 190

PostPosted: Fri Jan 18, 2008 12:05 am    Post subject: Reply with quote

Hi! :)

You can put all your kernel command in a single prx
You have to compile the prx and the app separately.
Both prx and app needs BUILD_PRX = 1

Here there's a little sample:
http://www.sakya.it/downloads/testPer371.rar

To compile it:
Code:
cd prx
make
psp-build-exports -s mylib.exp
cd ..
make


Copy both the EBOOT and the prx in the same directory (x:\PSP\GAME3xx\test)

http://forums.ps2dev.org/viewtopic.php?t=9022
It's almost the same source you can find in this thread, but this is for kernel 3.71

The only difference with the 3.52 version is that I had to import the correct NIDS for kernel functions (changed by Sony in kernel 3.7)

Ciaooo
Sakya
Back to top
View user's profile Send private message Visit poster's website
adrahil



Joined: 16 Mar 2006
Posts: 277

PostPosted: Fri Jan 18, 2008 3:22 am    Post subject: Reply with quote

Quote:
The only difference with the 3.52 version is that I had to import the correct NIDS for kernel functions (changed by Sony in kernel 3.7)

And changed again with 3.80 :) The nid mapper does a good job ;)
Back to top
View user's profile Send private message
Be3f



Joined: 15 Mar 2007
Posts: 59

PostPosted: Fri Jan 18, 2008 3:36 am    Post subject: Reply with quote

Also, to build a 3.XX EBOOT, you need to edit pspdev/psp/sdk/lib/build.mak - delete strip_ here:
Code:

$(PSP_EBOOT_SND0) strip_$(FINAL_TARGET) $(PSP_EBOOT_PSAR)

(I may have an old SDK - November 2006...)
_________________
00000110 00000110 00000110
Back to top
View user's profile Send private message Send e-mail
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Fri Jan 18, 2008 6:40 am    Post subject: Reply with quote

Hellcat wrote:
I sucessfully used PSP_HEAP_SIZE_KB(21000) even on a Fat.... but that's pretty close to the limit, tried a bit more, and got errors then....

AFAIK this also applies to the Slim, since the additional memory is an additional mem partition and does not simple expand the "normal" memory we are used to use....


It's very simple to get all the Slim memory added to the normal partition - just add this to the makefile:

Code:
PSP_LARGE_MEMORY = 1


It does nothing on the Phat, but on the Slim, it adds all the extra memory to the normal user partition. Then inside the main C file, use:

Code:
PSP_HEAP_SIZE_MAX();


Those two changes will give you the maximum heap possible on both the Phat and Slim.
Back to top
View user's profile Send private message AIM Address
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