Skip to content

Instantly share code, notes, and snippets.

@ematysek
Last active December 25, 2022 12:43
Show Gist options
  • Save ematysek/fc01a47c7d34f0ca4dad41226c53ff6e to your computer and use it in GitHub Desktop.
Save ematysek/fc01a47c7d34f0ca4dad41226c53ff6e to your computer and use it in GitHub Desktop.

Setting up RetroArch on Raspberry Pi 4 and building emulator cores

Guide for myself and others to get RetroArch running on the new Raspberry Pi 4 while projects like RetroPie get an image out for the rpi4.
Disclaimer: I am not an expert and this may not be the most optimal build possible, but it works.

Inspiration taken from:

1. Environment Setup

sudo raspi-config
Advanced Options -> GL Driver ->  G2 OpenGL desktop driver...
  • Update everything and restart - skip if you know this is done already
sudo apt update
sudo apt upgrade
shutdown -r now

2. Compile RetroArch

Install some needed packages - check the gist I linked for an explanation

sudo apt install build-essential libasound2-dev libudev-dev libgles2-mesa-dev libx11-xcb-dev libxxf86vm-dev

Download RetroArch source code - This guide will use the .tar.gz
https://github.com/libretro/RetroArch/releases

wget https://github.com/libretro/RetroArch/archive/v1.9.0.tar.gz
tar -xf v1.9.0.tar.gz
cd RetroArch-1.9.0

To fix undefined reference to XF86VidMode... errors change this line in Makefile:

#OLD line 24
LIBS :=
#New
LIBS := -lXxf86vm -lpthread

Configure with additional options to work with rpi4

CFLAGS='-mfpu=neon -mtune=cortex-a72 -march=armv8-a' ./configure --disable-opengl1 --enable-neon --enable-opengles3 --enable-opengles --disable-videocore

If no errors, build

make
sudo make install

3. Run/configure RetroArch

Launch RetroArch fullscreen

retroarch -f

Go ahead and update assets within RetroArch

Online Updater -> Update Assets

The gist for rpi 3b+ will tell you to update the retroarch.cfg file with a url, but those cores did not work for me so this guide will walk through building them.

4. Building Cores

All cores likely have multiple options to choose from but this will just go over what I've done so far.
Compiled core files end in .so and are kept in ~/.config/retroarch/cores/

Create directory to build our cores

cd ~
mkdir cores
cd cores

NES

libretro-fceumm

This could probably use optimized CFLAGS but it works as is

git clone --depth 1 https://github.com/libretro/libretro-fceumm.git
cd libretro-fceumm
make -j4

Move fceumm_libretro.so to cores dir

SNES

snes9x2010

This could probably use optimized CFLAGS but it works as is

git clone --depth 1 https://github.com/libretro/snes9x2010.git
cd snes9x2010
make -j4

N64

mupen64plus-libretro

This core is no longer being updated so you should use mupen64plus-libretro-next, but keeping this here just in case.

git clone --depth 1 https://github.com/libretro/mupen64plus-libretro.git
cd mupen64plus-libretro
platform=rpi4 make -j4

mupen64plus-libretro-next

git clone https://github.com/libretro/mupen64plus-libretro-nx.git
cd mupen64plus-libretro-nx
platform=rpi4 make -j4

PS1

git clone --depth 1 https://github.com/libretro/pcsx_rearmed.git
cd pcsx_rearmed
platform=rpi4 make -j4
@elserba
Copy link

elserba commented May 16, 2020 via email

@vol-2
Copy link

vol-2 commented Jun 27, 2020

Have you been able to get MT-32 going in Dosbox SVN?
I've got everything going great, but that's the last bit I can't figure out.
more details of what I'm doing here if you're interested: libretro/dosbox-svn#63

EDIT: FYI, I solved my issue. Apparently Dosbox-SVN is an older, basically legacy core for older devices. Dosbox-Core works perfectly for MT-32 support.

Thanks,

@khimaros
Copy link

For those looking for RPi4 Retroarch support, there are now official Retropie images:

https://retropie.org.uk/2020/04/retropie-4-6-released-with-raspberry-pi-4-support/

@denilsonsa
Copy link

denilsonsa commented Jul 1, 2020

Besides what this comment says, we also need:

sudo apt install libxxf86vm-dev

@ematysek
Copy link
Author

ematysek commented Jul 4, 2020

@denilsonsa I have added that to the gist as well, thanks

@ematysek
Copy link
Author

ematysek commented Jul 4, 2020

@khimaros True if you are looking to use your rpi mainly for emulation that is a good choice.

@vol-2
Copy link

vol-2 commented Jul 4, 2020

@khimaros @ematysek Vanilla RA is much easier to configure than Retropie. Especially if you are using a CRT, there is no contest as you need to be able to control the resolution in the menus. At this point, RA is better than even Lakka in terms of support for cores on armf in general. Retropie is basically for people who won't/can't get RA running correctly or who prefer emulation station.

@volfyd
Copy link

volfyd commented Aug 13, 2020

If you use these CFLAGS and CXXFLAGS and configure options, you'll end up with something closer to the build that Lakka is doing. It might be more optimized:

CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -mabi=aapcs-linux -Wno-psabi -Wa,-mno-warn-deprecated -mfloat-abi=hard -mfpu=neon-fp-armv8 -fomit-frame-pointer -Wall -pipe -Os" CXXFLAGS=$CFLAGS ./configure \
--disable-vg \
--disable-sdl \
--disable-sdl2 \
--disable-ssl \
--enable-opengles \
--enable-opengles3 \
--enable-opengl_core \
--enable-kms \
--disable-videocore \
--enable-plain_drm \
--enable-neon \
--enable-zlib \
--enable-freetype \
--enable-translate \
--enable-cdrom

Also, I opened up the squashfs from the latest Lakka release for Raspberry Pi 4, and the 2048 core and SNES 2010 core both worked fine in a retroarch I compiled myself.

@i8890321
Copy link

Hi, i am on the same boat, pi4 with raspberry OS,
Have you tried compile flycast ? the dreamcast emulator
Also any change on the dolphin ? the gamecube emulator?

I followed your guide and successfully compiled the Mupen64plus and mupen64plus-next , thanks

@alessioscand
Copy link

Hello and happy holidays.
I'd like to build the latest version Final Burn NEO, core optimized for Raspberry Pi 3:
https://github.com/libretro/FBNeo

May I ask for some help? thank you very much! :)

Copy link

ghost commented Jan 2, 2021

Hi - much respect and thanks for maintaining this guide.

I'd like to report the retroarch (1.7.3+dfsg1-1) binary installed from the Raspberry Pi OS (12-2-2020 release) package manager appears to run fine (at least for SNES) using a corresponding bsnes package also available on the package manager, on the Rpi 400.

In the retroarch config menu, the Audio Driver needed to be set to alsa to enable sound - otherwise, this appears to work out-of-the-box for me.

@mjeshurun
Copy link

mjeshurun commented Jan 21, 2021

Thank you for this wonderful tutorial. I'm a Raspberry Pi/Linux noob, and I found it to be very helpful 🙏
Could someone, please, share the commands I should enter in terminal to build the PSP and PS2 emulators cores?
I wish I knew how to do it myself, but I'm too new to Raspberry Pi and Linux to know.
I'm using Raspberry Pi 4 4GB running Raspberry Pi OS with desktop.

@ematysek
Copy link
Author

@Unounited
Retroarch pre-compiled cores were not available when this was written.
x86 compiled code will not work on an ARM processor, you should download the relevant ARM compiled cores.

@Unounited
Copy link

Unounited commented Jun 1, 2021

My bad, I should have tested the x86 cores before I posted them. And they did not work, so I guess someone might have all the cores for retroarch that work on arm

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