Go Back  
Reply
 
Thread Tools
Old 05-16-2010   #1
Disane
Member
 
Join Date: Jul 2008
Location: Austria
Posts: 121
Likes: 18
Liked 85 Times in 29 Posts
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Coding on the PS3, Setting up the GNU tool-chain in CodeLite 2.

Coding on the PS3.
Setting up the GNU tool-chain in CodeLite 2.




Hi everyone!

As you may know I've been away for a while trying to find a working IDE (Integrated Development Environment) for the PS3-Linux. That performs as good as any other lightweight IDE on Windows-PC. Since the PS3 has such fewer memory only a handful of IDEs are capable of running on the PS3 with good performance. Under performance I mean the time it takes to open up a window, browse the options menu, loading time, response time, etc. Apart from speed I also wanted to find an IDE which can be fully modified to work with GNU Tool-chain Sony designed and made available on the PS3-Linux and other Cell Platforms.

So far I tried 3 IDEs which were Code::Blocks (is a bit slower than CodeLite and less configurable, also very unresponsive) Eclipse (which takes a lot of time to load up, unresponsive and it requires a lot of extra configuration, its a horrible choice to install on the PS3) and finally CodeLite 2 (this is not an advertisement of course, CodeLite 2 is very easy to use and easy to configure to work with the GNU compilers). I used Ubuntu 9.10 but I think CodeLite 2 would work on any Linux that supports PowerPC64 architecture (which the PS3 supports).

Let's start with a FAQ, shall we:

"Why did you write this tutorial? Why should I bother reading it?"


Sony took out OtherOS a month ago and forced people to upgrade their systems. People had to upgrade to be able to use their PS3s for games and to access PSN. Now, I know some of you are stuck on ver. 3.15 and waiting for the glorious days of homebrew to come. If you're the person I'm talking about then this tutorial is for you. This tutorial gives you a bit of insight on how homebrew can be made on the PS3 (PS3 homebrew mad with the PS3, now which other console allowed that in the past?). The experience and knowledge you gain here can also benefit you when we can finally run unsigned code on GameOS.

"What kind of applications can we write on the PS3?"

We can write any kind of application on the PS3-Linux even games (Which Sony really doesn't like to hear, no wonder they've taken out Linux before anyone could make a graphics accelerator for the PS3-Linux.) or user applications. Many tools and libraries were ported on PowerPC64 in the recent time (the 64 bit architectures are taking over, we can't really do anything about this ). There's also a chance that we can run our code on the XMB (VSH) side of the PS3 some day. You can't really start homebrew development too early . A tutorial came out a few days ago on how to run XBMC on the PS3. But it runs damn slow. Well you could be the one who could utilize the SPUs to gain some speed and make it run faster. You never know unless you try

"But you can install the cell simulator on the PC why would you bother with coding on the PS3?"

Well, this is all true, you can install the Cell System Simulator and work on that. But it requires Linux installed on your PC. Also in some cases the user doesn't have the luxury to have another computer at home or when he's/she's traveling a lot and can only carry one computer (or a console in our case). There are some other benefits you can gain by coding directly on your PS3. You don't have to configure a system simulator, you can directly run and debug your code on the target platform and see how the hardware reacts.

Alright, let's see what do we need in order to get started:

- a PS3 with Linux installed (as I mentioned I used Ubuntu ver. 9.10 codename Karmic)
- able to access the Internet on your PS3-Linux
- mouse and keyboard (the PS3 supports all kinds of keyboards and mice)
- Cell SDK (I'll show you how to install it and configure your development environment so don't panic),WxWidgets 2.8+,libcurl (which you can get by installing "gnome-core-devel build-essential", again don't panic I'll reveal the process to you).
- the source code of Codelite 2.5.2 (build 4031), which you can find here: http://sourceforge.net/projects/code...ar.gz/download
- and my tutorial of course

Let's jump with both feet:

I assume you have completed the first 3 requirements I mentioned above. The steps we are going to take below are going to take a while (not because we are going to do so many things, it's because the System is very slow ) you could read some C/C++ tutorials or the Cell-Programming-Primer while your waiting for some of the tasks to complete or do anything else if your already familiar with C/C++ and the Cell/BE.

1. Opening the Terminal: Applications -> Accessories -> Terminal. If you want to, you can customize your Terminal to make it more appealing to you, cause we are going to spend most of our time using this. For example: I managed to make a matrix theme which reminded me on the 90's DOS using full screen can also help you feel more comfortable.

2. So let's start by installing the Cell SDK:

sudo apt-get install cell-sdk

In here, we need to type in our user password to allow the installation. Let's accept the installation with 'y' and then wait for the system to download and install the packages for us.

3. in order to install SPU-Binutils type in the following:

sudo apt-get install spu-binutils

Again, allow everything so we can proceed with the installation.

4. We also need to install the GTK+, WxWidgets libraries and the rest of the libraries we need in order to compile CodeLite 2. So here's how we proceed:

sudo apt-get install gnome-core-devel build-essential

5. Let's check the compilers we have installed and the ones we already had. Start with GCC (GNU C compiler):

gcc -v

This way we can check the version number of our compiler and some other information (where it accesses our Include and Library files.)
For example it gave me the following after I exexuted the CLI code above:

Using built-in specs.
Target: powerpc-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-softfloat --enable-secureplt --enable-targets=powerpc-linux,powerpc64-linux --with-cpu=default32 --disable-werror --with-long-double-128 --enable-checking=release --build=powerpc-linux-gnu --host=powerpc-linux-gnu --target=powerpc-linux-gnu
Thread model: posix
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)


We also might want to check the following compilers:

g++ -v
ppu-gcc -v
ppu-g++ -v
spu-gcc -v
spu-g++ -v


gcc and g++ are used for compiling PowerPC 32 bit C/C++ code, while ppu-gcc and ppu-g++ are used for compiling PowerPC 64 bit C/C++ code. We also have our SPU (Synergistic Processor Unit) compilers spu-gcc and spu-g++.

6. Now, that we have the SDK installed and we checked if every thing's fine with the compilers let's move on to setting up our development environment. I ran into some problems which gave me this error:

libstdc++.so.6: cannot open file: no such file

when I was trying to compile PPC64 code. We can easily fix this by typing in the following CLI code:

export LD_LIBRARY_PATH=/usr/lib/gcc/ppu/4.1.1

The problem is that this will only solve our problem for one occasion and we need to retype it again when we reboot the system. We can fix this by modifying our bash profile:

sudo nano ~/.bash_profile

We find ourselves in the NANO text editor (if you don't like it then you can use gedit or any other text editor you like). The document we opened will probably be empty and we only need to add the following line (if not then just add the text to the bottom of the existing lines):


export LD_LIBRARY_PATH=/usr/lib/gcc/ppu/4.1.1



Our text should look something like this in NANO (remember not to delete any text that was already in the file, this picture shows only an example):



After we've entered the text, let's check if every thing's fine and then press CTRL+O key combination to save the file and then press Enter to accept the changes. After that press CTRL+X to exit from NANO.

There's another file we need to modify in order to get what we want. Type in:

sudo nano ~/.bashrc

To open up .bashrc. This file wont be empty for sure. So just press the Down button until you reach the bottom of the entries and add the following line:

export LD_LIBRARY_PATH=/usr/lib/gcc/ppu/4.1.1




Save and exit NANO the same way as you did above. Now we can compile PPC64 code in our Terminal anytime we want.

Mounting SPUFS:

This is a problem I ran into when I was trying to compile SPU code. The error it produces when compiling code with spu-gcc or spu-g++ looks something like this:

spu_create(): Function not implemented
spe_context_create: Bad address


Fixing this problem is easy though. Let's check what's mounted so far with the following CLI code:

mount

If we don't get something similar:

none on /spu type spufs (rw,gid=1000)

Then that means that the SPUFS is not mounted and we need to fix this. Start by editing the fstab:

sudo gedit /etc/fstab

or

sudo nano /etc/fstab

Then we add the following lines below the already existing ones:

# Cell specific for the PS3:
none /spu spufs gid=spu 0 0


Save the modified file and exit from your chosen text editor.
Let's mount the SPUFS:

mount /spu

and check if its mounted:

mount

or

mount -a

7. Our Seventh step will be downloading, compiling and installing CodeLite 2. There's also an older version of CodeLite 1 somewhere on the Ubuntu Software Base. I couldn't find the never version which was already compiled so I decided to compile it on my PS3 (it took a while, and it will take a while for you as well). If anyone can make a proper package and upload it on Ubuntu's software base then please do so and pm me so I can update this tutorial:

Let's use some kind of Web Browser (I recommend FireFox although it eats up too much memory but that's my opinion.) and navigate to http://sourceforge.net/projects/code...ar.gz/download


Let's download our file to /home/user_name/Downloads (where user_name is your user name). In order to extract the source files let's type in the following lines into the Terminal:

cd ~/Downloads/
tar xzvf codelite-2.5.2.4031.tar.gz
cd codelite-2.5.2.4031/


8. Configuring and compiling then registering our application is the next step:

./configure

This will run the shell scrip which produces the make files we need to execute in order to install the application. Once this is done type in:

make

This is a screenshot I made with VNC while compiling CodeLite 2:


This is going to take a while but once It's been done we can type in:

sudo checkinstall

or if it fails then just type in:

sudo make install


CodeLite 2 is finally installed.

Starting up CodeLite 2 and configuring it.

Let's start by starting up CodeLite 2. If everything gone well then you should have it's icon on your desktop. You can also find the shortcut in Applications-> Programming -> CodeLite.

After the welcome screen appears we find our selves in the Workspace Setup screen. Here we need to type in the name of the workspace and it's location and also show the IDE where are the Include and Library files are located. These are located in:

/usr/include/
/usr/lib/


After we have input the important information let's just accept everything and wait for CodeLite to finish configuring it self (this can also take a while).

After the configuration is finished we find our selves at the CodeLite 2 home page:



This is not the manual for CodeLite so I won't go trough all the menus, options and settings here. I'm only going to show you how to set it up in order to compile and run PPC64 and SPU code.

Setting up the GNU tool-chain for the Cell/BE in CodeLite:


Navigate to Settings -> Build Settings. Click on the New button to create a new compiler and type in ppu-g++ (without the quotes). Then again click on New and then type in the following name: spu-g++. Here's some visual help on how to setup our newly created compilers:



Here we setup the compilers we want CodeLite to call when we are compiling our source codes.



Here we setup the output files and their extension and also show the Global Paths to our Include and Library files.

We need to do the same to our spu-g++ only this time instead of ppu-g++ we need to type in spu-g++.

Other settings like Compiler Options and Linker Options we can leave empty for now we won't be using them in this tutorial. But if you want to set them up then use the gnu-g++ compiler's settings as a reference. spu-g++ and ppu-g++ compilers are both part of the GNU tool-chain so their options are mostly the same.

Creating a PPU Hello World application.

Now that we have configured the IDE to support our compilers let's check if they're working properly. First thing we want to do is create a folder for our hello_ppu project. We can do this by using the following CLI code in the Terminal:

cd ~/.codelite/
mkdir hello_ppu


or we can skip this step and create it when we are creating our new project. Let's see how it's done:

Workspace -> Create New Project. We should get something like this below:



Let's see step by step what needs to be done:

Categories -> Console
Templates -> Simple Executable (g++)
Compiler type -> ppu-g++

(dont forget to create a folder for your project in ~/.codelite/ if you haven't done that already)
Project Name -> hello_ppu (our executable will have the same name).
Click OK.

You might want to close the window below the code field use the CTRL+ALT+O key combinations. If you look at the Workspace View window on the left side of your CodeLite window you will see a blue hello_ppu folder inside that folder you can find the src folder and inside that src folder you can find main.cpp. Double click on this file to open it up. You should see the following C source code:


#include <stdio.h>

int main(int argc, char **argv)
{
printf("hello world\n");
return 0;
}


Click on Build -> Build and Run Project (or use the shortcut keys CTRL+F9) in order to compile the source code for our simple hello world program. If you get the following text (error):

libstdc++.so.6: cannot open file: no such file

then go to Settings -> Enviroment Variables and insert the following line below or above the already existing one(s):

LD_LIBRARY_PATH=/usr/lib/gcc/ppu/4.1.1



then try running your code again (CTRL+F5).



Creating a SPU Hello World application.

Let's close our current workspace by clicking on Workspace -> Close Workspace. Let's create a new project Workspace -> Create New Project.
Our settings are as follows:
Categories -> Console
Templates -> Simple Executable (g++)
compiler type -> spu-g++
(we should also create a new folder for our hello_spu project in ~/.codelite/)
also don't forget to give a name for our project, name it hello_spu.
Click OK.

Open up main.cpp and modify the code to the following:

#include <stdio.h>

int main(unsigned long long spe, unsigned long long argp, unsigned long long envp)
{
printf("hello world\n");
return 0;
}


Now, we can compile and run our code (CTRL+F9) and we get the same window we had when we executed our code on the PPU. If we had left the code as it was then the compiler would've not produce any executable, which isn't good. We need to understand that SPU code is a little bit different then PPU code, you can't just execute it like any code. The PPU needs to find a suitable SPU to load the code into. But how do we know which SPU was selected by the PPU? Let's print it out the number of our SPU using the spe variable. Modify the code to look more like this:

#include <stdio.h>

int main(unsigned long long spe, unsigned long long argp, unsigned long long envp)
{
printf("SPU number: %d says Hello!\n",spe);

return 0;
}


If we compile our code then we run into an error again... :

main.cpp:5: undefined reference to `__nldbl_printf'

(no wonder why this tutorial was wrote, imagine your self fighting with these bugs alone )
We can get rid of this problem for the time being by asking the IDE to compile this code differently and by not using the make file (you can also make a different make command for it but I just couldn't figure it out how, if someone finds out how to do it, then pm me so i can update this tutorial). So click on Workspace -> Open Active Project Settings or use the shortcut key combination: ALT+F7. Click on the Custom Build tab and then check the Enable Custom Build box. Then double click on the white space next to Build. The following line goes here:

spu-g++ -v main.cpp -o ./$(IntermediateDirectory)/$(ProjectName)

To check if you did everything OK, here's a screenshot:



Then click OK and compile and run your code:



Again, if anyone finds a suitable method to compile this code with make then pm me. This code compiles fine if you use CLI.

Loading SPU code using PPU code.

Close your previous project and create a new one. Let's use the settings we did in the first project (hello_ppu). Create a new folder for our project in ~/.codelite and name it load_hello_spu. Don't forget to name your project as well.Click OK. The following code comes from the Cell-Programming-Primer document which is a very nice source to start programming for the Cell/BE. I recommend it to anyone who would like to develop applications for the Cell/BE. So, our main.cpp will look like this:

#include <stdio.h>
#include <stdlib.h>
#include <libspe2.h>

int main(int argc, char **argv)
{
int ret;
spe_context_ptr_t spe;
spe_program_handle_t *prog;
unsigned int entry;
spe_stop_info_t stop_info;
prog = spe_image_open("hello_spu");

if (!prog){
perror("spe_image_open");
exit(1);
}

spe = spe_context_create(0, NULL);
if (!spe) {
perror("spe_context_create");
exit(1);
}

ret = spe_program_load(spe, prog);
if (ret) {
perror("spe_program_load");
exit(1);
}

entry = SPE_DEFAULT_ENTRY;
ret = spe_context_run(spe, &entry, 0, NULL, NULL, &stop_info);

if (ret < 0) {
perror("spe_context_run");
exit(1);
}

ret = spe_context_destroy(spe);
if (ret) {
perror("spe_context_destroy");
exit(1);
}

ret = spe_image_close(prog);
&nbsp; if (ret) {
perror("spe_image_close");
&nbsp;&nbsp; exit(1);
}

return 0;
}


The code above is a simple SPU code loader which doesn't use isolation to load your unsigned code . Click on the Workspace -> Open Active Project Settings then click on the Linker tab. Our Library Path should point to /usr/lib/ and the Library we need to add is libspe2.a. Click OK.

If we happen to compile and run our code then we are going to bump into the following error:

spe_image_open: No such file or directory

To get rid of this problem we need to copy the SPU code into the same directory where the loader's binary is. We can open up the file browser and quickly drag hello_spu from ~/.codelite/hello_spu/Debug into ~/.codelite/load_hello_spu/Debug. If we don't want to wait for the file browser to open up and navigate to these folders then let's use CLI code instead in our Terminal:

cd ~/.codelite/hello_spu/Debug
cp hello_spu ~/.codelite/load_hello_spu/Debug/


Compile and run the load_hello_spu code in CodeLite to get the following results:



If you look at the result, you should see that SPU 0 was chosen to load the SPU code. Interesting, isn't it? In isolation mode you can't tell which SPU goes into isolation mode which isn't good. But we will get back to that in another tutorial perhaps...

(by Disane)
(special thanks to: covenant_ and ooPo for helping me out with this tutorial)

Last edited by Disane; 04-13-2011 at 03:12 AM.
Disane is offline   Reply With Quote
Old 05-16-2010   #2
Adr990
Member
null
 
Adr990's Avatar
 
Join Date: Feb 2010
Posts: 46
Likes: 29
Liked 2 Times in 2 Posts
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Thanks for writing this tutorial!

But I got stuck at step 8:
8. Configuring and compiling then registering our application is the next step:

./configure
When I enter ./configure once I'm in the codelite-2.5.2.4031 folder I get the follow error:
"No functional wx-config script was found in your PATH
Is the wxWidgets development package installed?"

So far I've done everything correct I believe, no errors or so..

What can I do to fix this?

Thanks in advance!
Adr990
Adr990 is offline   Reply With Quote
Old 05-17-2010   #3
Disane
Member
 
Join Date: Jul 2008
Location: Austria
Posts: 121
Likes: 18
Liked 85 Times in 29 Posts
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
alright the WxWidgets library is in the gnome-core-devel build-essentials if im correct. If this was already installed then try
wx-headers
Disane is offline   Reply With Quote
Likes: (1)
Old 05-17-2010   #4
Adr990
Member
null
 
Adr990's Avatar
 
Join Date: Feb 2010
Posts: 46
Likes: 29
Liked 2 Times in 2 Posts
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Originally Posted by Disane View Post
alright the WxWidgets library is in the gnome-core-devel build-essentials if im correct. If this was already installed then try
wx-headers
Thank you! This fixed it.
I must have over-read that part in the tutorial, sorry.

Thanks again, and keep up the good job.
Adr990 is offline   Reply With Quote
Old 05-17-2010   #5
Disane
Member
 
Join Date: Jul 2008
Location: Austria
Posts: 121
Likes: 18
Liked 85 Times in 29 Posts
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Originally Posted by Adr990 View Post
Thank you! This fixed it.
I must have over-read that part in the tutorial, sorry.

Thanks again, and keep up the good job.
Let me know, if you have finished the tutorial succesfully and if you bumped into any problems on the way.
Disane is offline   Reply With Quote
Old 05-18-2010   #6
stronghed
Apprentice
 
Join Date: Feb 2008
Posts: 7
Likes: 0
Liked 1 Time in 1 Post
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Is there anyway I can install debug firmware on my ps3 slim, I am currently on sony retail firmware version 3.15
stronghed is offline   Reply With Quote
Old 05-18-2010   #7
GregoryRasputin
 
GregoryRasputin's Avatar
 
Join Date: Jan 2008
Posts: 14,665
Likes: 8,398
Liked 14,891 Times in 5,704 Posts
Mentioned: 1381 Post(s)
Tagged: 3 Thread(s)
Originally Posted by stronghed View Post
Is there anyway I can install debug firmware on my ps3 slim, I am currently on sony retail firmware version 3.15
No there isnt.
GregoryRasputin is offline   Reply With Quote
Old 05-19-2010   #8
Pockets69
Senior Member
 
Pockets69's Avatar
 
Join Date: Jan 2008
Location: Lisbon, Portugal
Posts: 6,682
Likes: 2,087
Liked 2,451 Times in 1,390 Posts
Mentioned: 139 Post(s)
Tagged: 0 Thread(s)
Something that will give me a reason to turn my ps3 on again, thanks for the great tutorial Disane!
BTW any new about your work with geohot? that you would like to share?

take care bud
__________________

<eussNL> judge: ´so why did you torrent 5 million AVI of women moaning´
<eussNL> <TizzyT> i dont judge if it sounds good i listen
Pockets69 is offline   Reply With Quote
Old 05-21-2010   #9
Disane
Member
 
Join Date: Jul 2008
Location: Austria
Posts: 121
Likes: 18
Liked 85 Times in 29 Posts
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Just started working on a new tutorial. You can consider it as the "sequel" to this tutorial.
Stay tuned for more homebrew development tutorials on the PS3...

Last edited by Disane; 06-27-2010 at 05:48 PM.
Disane is offline   Reply With Quote
Likes: (4)
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



PS3Hax.net is Copyright © 2010-2013.
Use of this site is governed by our Terms of Use and Privacy Policy. All Trademarks and images are owned by their respected owners.
Posts and links are subject to each author on this forum and are no way affiliated with the operations and/or opinions of ps3hax.net
All times are GMT -5. The time now is 11:43 PM.