Maximus32
Developer
Introduction
For a long time there have been 2 libc libraries for ps2 development: newlib and ps2sdk/ee/libc. They have lots of duplicate functionality and duplicate header files, but with different implementations. The newlib one is more standard (posix) compliant, but the ps2 port has always been incomplete and broken. While the ps2sdk one is not broken, but it's not feature complete and not very posix compliant.
To fix this issue I decided to complete the newlib port. This seems to be the best way forward, since having a good libc library also means we can compile software not written for the ps2. Normally this would require "porting" to get these programs working with all ps2 specific header files and functions. But with a good libc library, a lot of porting is no longer needed. As a good example of this I've been working together with fjtrujy to get more emulators (cores) running in the ps2 port of RetroArch. A previously difficult to compile core with lots of errors (snes9x) now compiles AND RUNS without any porting.
Currently the port is not only feature complete, but also more complete than both libc libraries together ever have been. With an accurate nanosleep function. A time function (GMT/UTC only for now). And open/read/write/close automatically mapping to fioOpen/fileXioOpen/etc... Also all directory browsing with opendit/readdir/closedir works, as well as requisting file information using stat.
The good thing is standard applications work very good, making possible many other programs on the ps2. The downside is that ps2 applications are made to work with non-standard headers and functions, so some ps2 specific projects need to be 'ported' to posix. And another problem I run into is bugs, lots of bugs. Not just in the newlib port itself, but also in other ps2 projects. These bugs where not causing crashes before, but with the newlib port they somehow are. For instance freeing the same piece of memory twice, or freeing a static piece of memory didn't cause a crash before, but it does now! I've already fixed a few of these issues, but I can't get OPL to function properly becouse of it. Delaying the introduction of the newlib port, since I think OPL compatibility is important.
I'm hoping you can help in improving the newlib port, and fix the problems with OPL.
For more info on the OPL issue, I've created an issue here:
https://gitlab.com/ps2max/ps2sdk/issues/6
To get started with the newlib port you'll need to use my development environment, which is loosly based on the development environment used for developing android. Once you get to know it you'll love it. Here goes...
Getting the sources and compiling for the first time
Extra requirements for when you already have a ps2dev environment:
First we need to get the old toolchain up and running:
mkdir ps2dev
cd ps2dev
repo init -u https://gitlab.com/ps2max/ps2dev-repo -b ps2max
repo sync -j4
. envsetup.sh
./build-all.sh
NOTE1: add "--depth=1" to the "repo init" command if you're not interested in the git history. This will make cloning all git repositories significantly faster.
NOTE2: add "-c --no-tags" to the repo sync command to get only the current branch without tags. This will make cloning all git repositories significantly faster.
NOTE3: The ". envsetup.sh" sets all environment variables in the current terminal session. You should ALWAYS execute this command first after opening a new terminal. This is also what makes it possible to use multiple toolchains on the same pc. Those familiar to android development will see a lot of similarities
.
NOTE4: If you watched closely you'll have seen some project being built with cmake (the green lines with the percentages). These git projects build without any changes to the sources. Not even a Makefile is added or changed to compile these libraries.
When ready this should result in not only the toolchain, but also all libraries, tools and some ps2 applications like OPL. Let's see if OPL works:
cd apps/open-ps2-loader
make clean all # already performed by ./build-all.sh but lets do this anyway
make run # will send opl.elf to your ps2 using ps2client
make sim # will try to start opl.elf using PCSX2
Now that we have the basics working we can continue to the newlib port. Open a second terminal session:
mkdir ps2dev-newlib
cd ps2dev-newlib
repo init -u https://gitlab.com/ps2max/ps2dev-repo -b move-libc-to-newlib
repo sync -j4
. envsetup.sh
./build-all.sh
You'll now have all my latest newlib work compiled. Try again if OPL works in the same way as described above. HINT: do not use a HIRES resolution, and do not load any artwork (jpg).
Working with repo and the toolchain(s)
Updating to the latest changes is simple, assuming you don't have any local changes:
repo sync # will fetch all the latest sources
./build-all.sh # will rebuild everything, so only use when needed
Making changes and using the power of repo has the benefit of still being able to "repo sync" after making changes:
repo start my-fantastic-changes --all # create a branch in ALL git repositories, yes, do it!
# make some changes... in whatever git project...
git add X
git commit -m "Fantastic!"
Now to see in what projects you made your changes:
repo branch # view ALL branches in ALL projects YOU made
repo status # view ALL uncommitted changes in ALL projects
repo info -o # view the commits you made in ALL projects ahead of upstream, I love this command
If you want to sync your branch to whatever changes are made 'upstream':
repo sync # will fetch all the latest sources, and !REBASE! your work on top of it
./build-all.sh # will rebuild everything, so only use when needed
Good luck testing the newlib toolchain. If there's anything I can improve let me know. If you find any bugs you can report them in this thread or https://gitlab.com/ps2max/ps2sdk/issues. If you fix something you can also send a pull request https://gitlab.com/ps2max. If I don't respond, leave me a message here, becouse I'm not sure if all notification settings are setup correcly on gitlab
.
For a long time there have been 2 libc libraries for ps2 development: newlib and ps2sdk/ee/libc. They have lots of duplicate functionality and duplicate header files, but with different implementations. The newlib one is more standard (posix) compliant, but the ps2 port has always been incomplete and broken. While the ps2sdk one is not broken, but it's not feature complete and not very posix compliant.
To fix this issue I decided to complete the newlib port. This seems to be the best way forward, since having a good libc library also means we can compile software not written for the ps2. Normally this would require "porting" to get these programs working with all ps2 specific header files and functions. But with a good libc library, a lot of porting is no longer needed. As a good example of this I've been working together with fjtrujy to get more emulators (cores) running in the ps2 port of RetroArch. A previously difficult to compile core with lots of errors (snes9x) now compiles AND RUNS without any porting.
Currently the port is not only feature complete, but also more complete than both libc libraries together ever have been. With an accurate nanosleep function. A time function (GMT/UTC only for now). And open/read/write/close automatically mapping to fioOpen/fileXioOpen/etc... Also all directory browsing with opendit/readdir/closedir works, as well as requisting file information using stat.
The good thing is standard applications work very good, making possible many other programs on the ps2. The downside is that ps2 applications are made to work with non-standard headers and functions, so some ps2 specific projects need to be 'ported' to posix. And another problem I run into is bugs, lots of bugs. Not just in the newlib port itself, but also in other ps2 projects. These bugs where not causing crashes before, but with the newlib port they somehow are. For instance freeing the same piece of memory twice, or freeing a static piece of memory didn't cause a crash before, but it does now! I've already fixed a few of these issues, but I can't get OPL to function properly becouse of it. Delaying the introduction of the newlib port, since I think OPL compatibility is important.
I'm hoping you can help in improving the newlib port, and fix the problems with OPL.
For more info on the OPL issue, I've created an issue here:
https://gitlab.com/ps2max/ps2sdk/issues/6
To get started with the newlib port you'll need to use my development environment, which is loosly based on the development environment used for developing android. Once you get to know it you'll love it. Here goes...
Getting the sources and compiling for the first time
Extra requirements for when you already have a ps2dev environment:
- packages: repo, cmake
- remove all your $PS2DEV,$PS2SDK,etc,etc... environment variables
- preferably remove or rename your /usr/local/ps2dev folder, just to be sure you're not still using it
First we need to get the old toolchain up and running:
mkdir ps2dev
cd ps2dev
repo init -u https://gitlab.com/ps2max/ps2dev-repo -b ps2max
repo sync -j4
. envsetup.sh
./build-all.sh
NOTE1: add "--depth=1" to the "repo init" command if you're not interested in the git history. This will make cloning all git repositories significantly faster.
NOTE2: add "-c --no-tags" to the repo sync command to get only the current branch without tags. This will make cloning all git repositories significantly faster.
NOTE3: The ". envsetup.sh" sets all environment variables in the current terminal session. You should ALWAYS execute this command first after opening a new terminal. This is also what makes it possible to use multiple toolchains on the same pc. Those familiar to android development will see a lot of similarities
NOTE4: If you watched closely you'll have seen some project being built with cmake (the green lines with the percentages). These git projects build without any changes to the sources. Not even a Makefile is added or changed to compile these libraries.
When ready this should result in not only the toolchain, but also all libraries, tools and some ps2 applications like OPL. Let's see if OPL works:
cd apps/open-ps2-loader
make clean all # already performed by ./build-all.sh but lets do this anyway
make run # will send opl.elf to your ps2 using ps2client
make sim # will try to start opl.elf using PCSX2
Now that we have the basics working we can continue to the newlib port. Open a second terminal session:
mkdir ps2dev-newlib
cd ps2dev-newlib
repo init -u https://gitlab.com/ps2max/ps2dev-repo -b move-libc-to-newlib
repo sync -j4
. envsetup.sh
./build-all.sh
You'll now have all my latest newlib work compiled. Try again if OPL works in the same way as described above. HINT: do not use a HIRES resolution, and do not load any artwork (jpg).
Working with repo and the toolchain(s)
Updating to the latest changes is simple, assuming you don't have any local changes:
repo sync # will fetch all the latest sources
./build-all.sh # will rebuild everything, so only use when needed
Making changes and using the power of repo has the benefit of still being able to "repo sync" after making changes:
repo start my-fantastic-changes --all # create a branch in ALL git repositories, yes, do it!
# make some changes... in whatever git project...
git add X
git commit -m "Fantastic!"
Now to see in what projects you made your changes:
repo branch # view ALL branches in ALL projects YOU made
repo status # view ALL uncommitted changes in ALL projects
repo info -o # view the commits you made in ALL projects ahead of upstream, I love this command
If you want to sync your branch to whatever changes are made 'upstream':
repo sync # will fetch all the latest sources, and !REBASE! your work on top of it
./build-all.sh # will rebuild everything, so only use when needed
Good luck testing the newlib toolchain. If there's anything I can improve let me know. If you find any bugs you can report them in this thread or https://gitlab.com/ps2max/ps2sdk/issues. If you fix something you can also send a pull request https://gitlab.com/ps2max. If I don't respond, leave me a message here, becouse I'm not sure if all notification settings are setup correcly on gitlab
Last edited by a moderator: