Skip to content

Instantly share code, notes, and snippets.

@xerpi
Last active March 23, 2024 17:29
  • Star 23 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save xerpi/5c60ce951caf263fcafffb48562fe50f to your computer and use it in GitHub Desktop.
PSVita Linux build instructions

0) Optional: Solder UART0 pins

  1. Check here for the pinout. You will also need a 1.8V level shifter.

1) Install an ARMv7 cross-compiler

  1. Go to https://toolchains.bootlin.com
  2. Select arch: armv7-eabihf
  3. Select libc: glibc
  4. Download bleeding-edge
  5. Uncompress it (for example to /opt)
  6. Add the bin/directory of the toolchain to $PATH
    • In my case: export PATH=$PATH:/opt/armv7-eabihf--glibc--bleeding-edge-2023.08-1/bin

2) Build Buildroot

  1. git clone git://git.buildroot.net/buildroot && cd buildroot
  2. Download and copy this Buildroot .config to .config
  3. If using a toolchain path different than /opt/armv7-eabihf--glibc--bleeding-edge-2023.08-1:
    • make menuconfig
    • Navigate to Toolchain --->
    • Properly set the Toolchain path, save and exit
  4. Create a rootfs-overlay directory. Everything you put inside will be part of the rootfs.
  5. make -j
  6. This will generate output/images/rootfs.cpio.xz

3) Build Linux

  1. git clone https://github.com/xerpi/linux_vita.git
  2. cd linux_vita && cp ../buildroot/output/images/rootfs.cpio.xz ./
  3. make ARCH=arm vita_defconfig
  4. make ARCH=arm CROSS_COMPILE=arm-linux- -j
  5. make ARCH=arm CROSS_COMPILE=arm-linux- vita1000.dtb vita2000.dtb pstv.dtb
  6. This will generate arch/arm/boot/zImage and arch/arm/boot/dts/{vita1000.dtb,vita2000.dtb,pstv.dtb}

4) Install vitasdk

5) Build vita-baremetal-loader

  1. git clone https://github.com/xerpi/vita-baremetal-loader.git
  2. cd vita-baremetal-loader && make
  3. This will generate baremetal-loader.skprx

6) Install libbaremetal

  1. git clone https://github.com/xerpi/vita-libbaremetal.git
  2. cd vita-libbaremetal/libbaremetal && make install

7) Build vita-baremetal-linux-loader

  1. git clone https://github.com/xerpi/vita-baremetal-linux-loader.git
  2. cd vita-baremetal-linux-loader && make
  3. This will generate vita-baremetal-linux-loader.bin

8) Build and install the Plugin Loader VPK or vitacompanion

Two main methods: (a) a VPK that loads a kernel plugin, or (b) my fork of vitacompanion that has an custom command to load skprxes.

a. Plugin Loader VPK method:

  1. git clone https://bitbucket.org/xerpi/vita_plugin_loader.git
  2. cd vita_plugin_loader && mkdir build && cd build && cmake .. && make
  3. Install plugin_loader.vpk

b. vitacompanion method:

  1. Build and install vitacompanion
  2. To launch an skprx run:
    echo "load_skprx ux0:/myplugin.skprx" | nc $PSVITAIP 1338

9) Boot Linux

  1. Copy baremetal-loader.skprx to ux0:data/tai/kplugin.skprx
    • Configurable in vita_plugin_loader/main.c:13
  2. Copy vita-baremetal-linux-loader.bin to ux0:/baremetal/payload.bin
    • Configurable in vita-baremetal-loader/config.h
  3. Copy linux_vita/arch/arm/boot/zImage to ux0:/linux/zImage (uma0 if using sd2vita)
  4. Copy linux_vita/arch/arm/boot/dts/{vita1000.dtb,vita2000.dtb,pstv.dtb} to ux0:/linux/ (uma0 if using sd2vita)
  5. Launch the Plugin Loader VPK

More information

Deprecated steps

4) Build vita-linux-loader (DEPRECATED: use vita-baremetal-linux-loader instead)

  1. Install vitasdk
  2. git clone git@github.com:xerpi/vita-linux-loader.git
  3. cd vita-linux-loader && make
  4. This will generate linuxloader.skprx
@FoolsHonor
Copy link

FoolsHonor commented Mar 24, 2023

Hiya, ive followed all the steps, however the only thing ive noticed is after ive copied rootfs.cpio.xz to vita_linux but when i run the make command (make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j) and i get this error " make[1]: *** No rule to make target 'rootfs.cpio.zst', needed by 'usr/initramfs_inc_data'. Stop." Ive tried everything i can think off. If anyone can lend a hand it would be much appreciated! (everything else built well even the vita-1000.dtb just the zImage did not want to)

@xerpi
Copy link
Author

xerpi commented Mar 24, 2023

Hiya, ive followed all the steps, however the only thing ive noticed is after ive copied rootfs.cpio.xz to vita_linux but when i run the make command (make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j) and i get this error " make[1]: *** No rule to make target 'rootfs.cpio.zst', needed by 'usr/initramfs_inc_data'. Stop." Ive tried everything i can think off. If anyone can lend a hand it would be much appreciated!

Either change buildroot to generate a .zst, or change linux kconfig to read a .xz.

@FoolsHonor
Copy link

FoolsHonor commented Mar 24, 2023

Hey I downgraded to 3.60 on viita deploy to make it easier But idk how to stop the kplugin error when I create the vpk

just follow the above comment about adding 363, it worked for me even though it could not boot into linux after loading the plugin

@FoolsHonor
Copy link

FoolsHonor commented Mar 24, 2023

Hiya, ive followed all the steps, however the only thing ive noticed is after ive copied rootfs.cpio.xz to vita_linux but when i run the make command (make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j) and i get this error " make[1]: *** No rule to make target 'rootfs.cpio.zst', needed by 'usr/initramfs_inc_data'. Stop." Ive tried everything i can think off. If anyone can lend a hand it would be much appreciated!

Either change buildroot to generate a .zst, or change linux kconfig to read a .xz.

what method would you recommend ?
is it possible to convert .xz to .zst ?

@FoolsHonor
Copy link

ok so I uncompressed the .xz and recompressed to .zst however now plugin loader hangs on jumping to linux, is there any verbose mode or something?

@xerpi
Copy link
Author

xerpi commented Mar 25, 2023

Hiya, ive followed all the steps, however the only thing ive noticed is after ive copied rootfs.cpio.xz to vita_linux but when i run the make command (make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j) and i get this error " make[1]: *** No rule to make target 'rootfs.cpio.zst', needed by 'usr/initramfs_inc_data'. Stop." Ive tried everything i can think off. If anyone can lend a hand it would be much appreciated!

Either change buildroot to generate a .zst, or change linux kconfig to read a .xz.

what method would you recommend ? is it possible to convert .xz to .zst ?

make ARCH=arm menuconfig on the Linux source code opens a menu to change those kind of options.

@FoolsHonor
Copy link

firstly thank you for all your support and help,
after running make ARCH=arm menuconfig, General setup -> [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support (rootfs.cpio.zst) Initramfs source file(s) then renaming file to .xz, the boot still hangs at the booting into linux. Im going to poke around and find out why but if you have any suggestions they would be much appreciated!

@felamos
Copy link

felamos commented Mar 28, 2023

firstly thank you for all your support and help, after running make ARCH=arm menuconfig, General setup -> [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support (rootfs.cpio.zst) Initramfs source file(s) then renaming file to .xz, the boot still hangs at the booting into linux. Im going to poke around and find out why but if you have any suggestions they would be much appreciated!

I had the same issue, instead of converting .xz to .zst change the config file. You will notice size difference.

@felamos
Copy link

felamos commented Mar 28, 2023

Interesting to run the Linux, may need to modify or create a module for a keyboard to work or try to access it over ssh somehow.

@FoolsHonor
Copy link

FoolsHonor commented Mar 28, 2023

firstly thank you for all your support and help, after running make ARCH=arm menuconfig, General setup -> [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support (rootfs.cpio.zst) Initramfs source file(s) then renaming file to .xz, the boot still hangs at the booting into linux. Im going to poke around and find out why but if you have any suggestions they would be much appreciated!

I had the same issue, instead of converting .xz to .zst change the config file. You will notice size difference.

edit the buildroot config or the linux_vita config?

@felamos
Copy link

felamos commented Mar 28, 2023

firstly thank you for all your support and help, after running make ARCH=arm menuconfig, General setup -> [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support (rootfs.cpio.zst) Initramfs source file(s) then renaming file to .xz, the boot still hangs at the booting into linux. Im going to poke around and find out why but if you have any suggestions they would be much appreciated!

I had the same issue, instead of converting .xz to .zst change the config file. You will notice size difference.

edit the buildroot config or the linux_vita config?

make ARCH=arm menuconfig on the cloned repo, explore around you will eventually find it.

@FoolsHonor
Copy link

FoolsHonor commented Mar 29, 2023

Ok so did some digging and experimenting but still cant get passed the jumping to linux.

  • buildroot, ARCH=arm menuconfig
  • Filesystem images ---> Compression method (xz) to Compression method (zstd)
  • buildroot, make -j1
  • cp rootfs.cpio.zst ../linux_vita/
  • linux_vita, make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j1

my zimage output has the size of 12860KiB, can anyone verify if the issue is the zimage or if its something else?
https://github.com/FoolsHonor/trying-to-get-vita-linux-running

@felamos
Copy link

felamos commented Mar 29, 2023

Ok so did some digging and experimenting but still cant get passed the jumping to linux.

* buildroot, ARCH=arm menuconfig

* Filesystem images  ---> Compression method (xz)  to Compression method (zstd)

* buildroot, make -j1

* cp rootfs.cpio.zst ../linux_vita/

* linux_vita, make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j1

my zimage output has the size of 12860KiB, can anyone verify if the issue is the zimage or if its something else? https://github.com/FoolsHonor/trying-to-get-vita-linux-running

I think its might be zst. Your zimage size looks good but I would say instead of changing xz to zstd, do the opposite but on the linux vita repo. Change to xz from zst.

@FoolsHonor
Copy link

so found out part of the issue was filezilla, move Zimage in a compressed format eg .zip worked.
now booted to this screen bellow any tips to ssh or run the vita linux demo?

https://github.com/FoolsHonor/trying-to-get-vita-linux-running

2023-03-29-10-30-50-372

@felamos
Copy link

felamos commented Mar 29, 2023

so found out part of the issue was filezilla, move Zimage in a compressed format eg .zip worked. now booted to this screen bellow any tips to ssh or run the vita linux demo?

https://github.com/FoolsHonor/trying-to-get-vita-linux-running

if it connects to the internet, maybe compile it in a way that the SSH is listening on all interfaces and allows root to login with password. You also may need to set a password. It does say network is ok but I am also debugging this part.

@FoolsHonor
Copy link

FoolsHonor commented Mar 29, 2023

Thanks for getting me up to date! will do some more research
is there any matrix chat for ease of communication?
if not here is a quick server: #PSVitaLinux:matrix.org

@FoolsHonor
Copy link

ok so has anyone found a way to chroot, not ssh, into the vita?

@felamos
Copy link

felamos commented Apr 1, 2023

ok so has anyone found a way to chroot, not ssh, into the vita?

Why do you want to chroot? were you able to connect to linux via SSH? I think you are always root, if not configure buildroot with set of passwords. You can try to chroot if you are able to somehow access the file system via a different computer.

@Empyreal96
Copy link

Empyreal96 commented Aug 2, 2023

Has anyone got this working with SD2Vita?
When I reboot into baremetal it tells me no memory card inserted and I can't continue to load the kernel image

@xerpi
Copy link
Author

xerpi commented Aug 3, 2023

Has anyone got this working with SD2Vita? When I reboot into baremetal it tells me no memory card inserted and I can't continue to load the kernel image

Currently, the "Baremetal Linux loader" loads from MSIF so only loading from Memory Card is supported.

I think the old Linux loader could be used instead for now: https://github.com/xerpi/vita-linux-loader

@Empyreal96
Copy link

Empyreal96 commented Aug 4, 2023

Has anyone got this working with SD2Vita? When I reboot into baremetal it tells me no memory card inserted and I can't continue to load the kernel image

Currently, the Linux loader loads from MSIF so only Memory Card are supported.

I think the old Linux loader could be used instead for now: https://github.com/xerpi/vita-linux-loader

Thanks, I recently switched to this loader and recompiled the plugin with the _stub includes, but I'm getting error 0x8002D003 while loading the plugin.. someone said it's relating to the linked includes missing the _stub versions so I'm trying to somehow see what is causing this

@koko1ooo
Copy link

Has anyone got this working with SD2Vita? When I reboot into baremetal it tells me no memory card inserted and I can't continue to load the kernel image

Currently, the Linux loader loads from MSIF so only Memory Card are supported.
I think the old Linux loader could be used instead for now: https://github.com/xerpi/vita-linux-loader

Thanks, I recently switched to this loader and recompiled the plugin with the _stub includes, but I'm getting error 0x8002D003 while loading the plugin.. someone said it's relating to the linked includes missing the _stub versions so I'm trying to somehow see what is causing this

I just did a port to the 6.5 kernel. Including a self-built toolchain with crosstool-ng and the latest buildroot. I am now trying to install the WLAN driver.

Isn't the 0x8002D003 error that unsafe homebrews are not allowed? I could be wrong about that

@AGitVictim
Copy link

I just did a port to the 6.5 kernel. Including a self-built toolchain with crosstool-ng and the latest buildroot. I am now trying to install the WLAN driver.

Is it available?

@xerpi
Copy link
Author

xerpi commented Sep 27, 2023

I have updated https://github.com/xerpi/vita-baremetal-loader to also generate a skprx for FW ≥ 3.63 automatically.
I have also updated this guide to the latest bootlin toolchain and written about the vitacompanion method to load skprxes easily.

@xerpi
Copy link
Author

xerpi commented Sep 27, 2023

I have rebased the Vita port to the latest upstream Linux commit (6.6.0-rc3): https://github.com/xerpi/linux_vita/tree/rebase-6.6.0-rc3
When booting, sometimes it hangs at:

Uncompressing Linux... done, booting the kernel.

And sometimes it gets a bit further:

Uncompressing Linux... done, booting the kernel.
Booting Linux on physical CPU 0x0
Linux version 6.6.0-rc3-00045-g87e131f82459 (xerpi@xps15-linux) (arm-linux-gcc.br_real (Buildroot 2021.11-8547-g7e65a1a) 13.2.0, GNU ld (GNU Binutils) 2.41) #3 SMP Thu Sep 28 00:29:59 CEST 2023
CPU: ARMv7 Processor [412fc09a] revision 10 (ARMv7), cr=10c5787d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
OF: fdt: Machine model: PlayStation Vita
OF: fdt: Ignoring memory range 0x40200000 - 0x41000000
printk: bootconsole [earlycon0] enabled
Memory policy: Data cache writealloc
BUG: not creating mapping for 0x00000000 at 0x7f000000 in user region

I suspect it's a problem related to the linux loader leaving stale data in the L2 data cache.

@GGLinnk
Copy link

GGLinnk commented Oct 13, 2023

There is a missing folder in buildroot (Chapter 2) : It's rootfs-overlay
make doesn't seems to make it. Creating it manually allows to get rid of the error I encountered with rsync.

I suggest adding the creation of this folder into the guide or find a fix. Maybe the configuration file is incorrect ?

The error :

>>>   Copying overlay rootfs-overlay
rsync: [sender] change_dir "/home/gglinnk/buildroot/rootfs-overlay" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1338) [sender=3.2.7]
make[1]: *** [Makefile:749: target-finalize] Error 23
make: *** [Makefile:82: _all] Error 2

@xerpi
Copy link
Author

xerpi commented Oct 14, 2023

There is a missing folder in buildroot (Chapter 2) : It's rootfs-overlay make doesn't seems to make it. Creating it manually allows to get rid of the error I encountered with rsync.

I suggest adding the creation of this folder into the guide or find a fix. Maybe the configuration file is incorrect ?

The error :

>>>   Copying overlay rootfs-overlay
rsync: [sender] change_dir "/home/gglinnk/buildroot/rootfs-overlay" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1338) [sender=3.2.7]
make[1]: *** [Makefile:749: target-finalize] Error 23
make: *** [Makefile:82: _all] Error 2

Thanks for pointing that out. I have updated the instructions.

@Cinder4198
Copy link

It took me far too long to realize that there is an entire comment thread under the guide.
Anyways what does it mean I boot up plugin loader, it shows this for a split second

Plugin Loader by xerpi
Module loaded with ID: 0x4002006D
Press Start to continue.

then reboots to a blank screen?

Using a slim on 3.65, and I made sure to use the 363 skprx file.

@DvaMishkiLapa
Copy link

It took me far too long to realize that there is an entire comment thread under the guide. Anyways what does it mean I boot up plugin loader, it shows this for a split second

@Cinder4198
It's funny, but I got here completely by accident. Looks like my experiments from a year ago will help you out. The comments from here confused me for a long time, until I got into the source code of the Xerpi toolkit and made it more intuitive.

I made a fork of my experiments where I also updated the README.md, it seems to be clearer. I have it running on 3.65, I've tried to cover all the subtleties I've seen, especially for the different PS Vita firmware.

I'll also give a link to my merge attempt with the newer kernel. Of course, I failed miserably, especially since I can't get debugging.
I have also placed the finished files in the plugin and loader repositories.

My failed kernel - https://github.com/DvaMishkiLapa/linux_vita
Original Xerpi kernel image - https://github.com/xerpi/linux_vita/releases/tag/5.9.0-rc5
Loader modification - https://github.com/DvaMishkiLapa/vita_plugin_linux_loader
Plugins - https://github.com/DvaMishkiLapa/vita-baremetal-loader

@DvaMishkiLapa
Copy link

@xerpi
Probably should have shown you this, there might be something useful in there. You seem to be doing about the same thing in vita-baremetal-loader as I am. I'd be glad if this helps you in any way or improves the important repository ^^.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment