There comes a time when printf statements just aren't enough. When you get hopelessly stuck on a coding problem and just can't understand why your code isn't behaving as you expect, it's time to start using some more advanced tools. This document will attempt to help get you started with PSPLink debugging with a minimum of pain. Although PSPLink comes with an excellent manual, it can be intimidating to beginning and intermediate coders. This first post will be updated in the future to keep it current and add tips and tricks.
Note: PSPLink is intended for C/C++ programs. It is also limited to 1.0 and 1.5 firmwares because it requires kernel mode access. This document assumes you're using Cygwin and Windows and that you will use USB to control PSPLink.
- Make sure your toolchain script is current.
In your cygwin home directory download the latest toolchain using the following command:
Code:svn co svn://svn.ps2dev.org/psp/trunk/psptoolchain
- Make sure your sdk is current.
Navigate to the psptoolchain directory and get the newest version of the sdk:
Code:cd psptoolchain ./toolchain -p
- Download and install PSPLink.
Go back to your home directory and download PSPLink:
Now build it:Code:cd ~ svn co svn://svn.ps2dev.org/psp/trunk/psplink
Copy the PSPLink files to your psp in the PSP/GAME directory. You have three choices. Look in psplink/release and copy the contents of 1.0, 1.5 or v1.5_nocorrupt (to hide the corrupt icon).Code:cd psplink make release
In the PSP/GAME/psplink directory edit the file psplink.ini to change the setup options. Set the options as follows:
Don't start PSPLink just yet.Code:# Example psplink configuration file. # usbmass=[0 1] Enable USB mass storage. Set to 1 to enable automatically usbmass=1 # usbhost=[0 1] Enable USB host file system. Set to 1 to enable automatically usbhost=1 # pluser=[0 1] Enable the PSPLink user module pluser=1 # resetonexit=[0 1] Specify wheher to reset psplink when sceKernelExitGame # is called resetonexit=1 # sioshell=[0 1] Specify whether to start up the sio shell sioshell=0 # kprintf=[0 1] Specify that SIO should be used for kprintf only, setting sioshell # to 1 overrides this setting. kprintf=1 # wifi=[0..N] Specify wifi should be enabled, the number is the # configuration to use if > 0 wifi=0 # wifishell=[0 1] Specify whether to start up the wifi shell wifishell=0 # usbshell=[0 1] Specify whether to start up the usb shell usbshell=1 # usbgdb=[0 1] Specify whether to use USB gdb or wifi gdb usbgdb=1 # conshell=[0 1] Specify whether to start up the console shell conshell=0 # consinterfere[0 1] Specifiy whether the consoleshell may interfere with # programs in execution consinterfere=0 # the commands that is run when buttons are pressed in the console shell conscrosscmd=ld ms0:/sprite.elf conssquarecmd=thlist constrianglecmd=modlist conscirclecmd= consselectcmd=meminfo consstartcmd=ls consdowncmd=scrshot ms0:/scshot.bmp consleftcmd=usbmoff consrightcmd=usbmon consupcmd=cop0 # prompt=... Set the psplink shell prompt # There are some escape characters, mainly %d to print the current dir prompt="%d> " # path=... Set the psplink shell path # Each path is separated by a semi-colon, you can specify up to around 128 characters # path=ms0:/apps;ms0:/ # pcterm=[0 1] Indicates whether we are using pcterm as a client or normal # tools pcterm=0 # baud=[4800..115200] Set the SIO baud rate (should only use as a last resort) # baud=115200 # modload=path Load a module on start up, repeat as necessary for more modules # Example: load the modules for networking # modload=flash0:/kd/ifhandle.prx # modload=flash0:/kd/pspnet.prx # modload=flash0:/kd/pspnet_inet.prx # modload=flash0:/kd/pspnet_apctl.prx # modload=flash0:/kd/pspnet_resolver.prx
- Set up the USB driver.
Download the usbhostfs device driver for windows from sourceforge. The most current binary release at this time is libusb-win32-device-bin-20051120.tar.gz . Extract it to psplink/release/pc. From the new directory this creates, copy lib/gcc/libusb.a to psplink/release/pc/usbhostfs_pc. Also copy include/usb.h to the same directory.
Now it's time to start PSPLink on the PSP. Windows will recognize it as a new USB device and wants to install drivers. Ignore the new driver window and run inf-wizard.exe from the bin directory. At the device selection screen find and select "PSP Type B". You can leave the device configurations on the next page at the default. It will next ask you where you want your new drivers files written. You can put them in the same bin directory. Now go back to the Windows driver installation window and tell Windows you want to specify the driver search directory. Select the bin directory and complete the installation.
Now you can build the PC USB communications task in Cygwin:
To make things easier later, copy the new usbhostfs_pc.exe file to your Cygwin home directory.Code:cd psplink/release/pc/usbhostfs_pc make
You now have the ability to control your PSP from your PC and run PSP programs from your PC hard drive. But first we need to run the PC cmmunications server and then login to the PSP.
In your Cygwin home directory run the usbhostfs_pc.exe program. If PSPLink is running it will now tell you it is "Connected to device". Open another Cygwin shell and run telnet:
This opens a connection to your own PC on port 10000, which is where the usbhostfs_pc server is listening for connections. You are now logged into your PSP! You are looking at the "host0:" device, which is actually on your PC.Code:telnet localhost 10000
Now let's try running PSP homebrew from the memory stick:
You'll see a list of the homebrew installed on your PSP. Enter one of your game/utility folders and type ./EBOOT.PBP to run the eboot. The game/utility will run normally. When you quit the eboot, PSPLink will reset but remain active. Notice that now you are back in the host0: directory. Every time PSPLink resets this will happen.Code:cd ms0:/psp/game ls
So how do we get started doing something useful to make coding quicker/easier? The first step is reassigning the host0: drive. Switch back to the usbhostfs_pc wnidow and type "drives". You'll see that you have 8 devices to work with, but since PSPLink will always come back to host0:, it makes sense to temporarily assign it to your development directory to speed up development. For illustration I'll use the Cygwin username "john" and he's working on a simple test program called "test" in the "test" directory. In the usbhostfs_pc window type "mount 0 /home/john/test". Now type "drives" again and you'll see that you have reassigned host0:. In the telnet window type "cd host0:" and "ls" and verify that you're in the right place.
Now for some rapid development. Open a third Cygwin window and change to your test directory. You have a working demo but you want to tweak it. So build it now with the make command. When the make is finished, switch to the telnet window and type "./test.elf" to run the elf executable version of your program. It will then run on the PSP and you can see what it looks like. Exit the program and your PSP resets, but since you assigned host0: you'll still be in your test directory. So make atweak, run make again, and repeat as neccessary until it works the way you like. Isn't this faster and easier than copying your kxploit directories to the PSP every time you make a change?
Now that you have the PSPLink environment set up and working, it would be a good time to look at the PSPLink manual in the psplink directory (psplink_manual.pdf). PSPLink can do much more than what has been covered so far. Even if you understand very little of the manual you may see some useful commands you'd like to try.
So are we debugging yet? Not really. The next installment will continue in this first post with instructions on installing and using the psp-gdb debugger.