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
@pyrho
Copy link

pyrho commented Oct 9, 2019

Thank you for this.
Is your sound OK? On my Pi4 (4gb, 512 gpu_mem) the snes & genesis emulation only run at around 45-50 FPS (I have 60 only in retroarch's menu). And this results in distorted sound.

Sometimes (seemingly random) it will go to 60FPS and the sound is then fine.

@ematysek
Copy link
Author

ematysek commented Oct 9, 2019

That's interesting, I do have some sound issues on n64 games where I'm not quite getting 60 FPS, but I haven't had any issues with NES/SNES/PS1 games running less than 60 FPS.
I am running a small overclock on my cpu/gpu but shouldn't make any significant difference.

@khimaros
Copy link

khimaros commented Oct 17, 2019

FYI, libavdevice-dev is also needed in order to build from Git HEAD.

@khimaros
Copy link

For PS1 module, the following worked for me:

git clone --depth 1 https://github.com/libretro/pcsx_rearmed.git
cd pcsx_rearmed
platform=rpi4 make -j4 -f Makefile.libretro
cp pcsx_rearmed_libretro.so ~/.config/retroarch/cores/

@parker-hemphill
Copy link

For the make commands you can do
make -j4
to use all the cores for doing your compile

@ChenZheChina
Copy link

ChenZheChina commented Feb 17, 2020

I followed the guide but it failed to compile the latest v1.8.4.

I have to do the following things to make it work:

  1. sudo apt-get install libx11-xcb-dev
  2. Edit Makefile and add a line: UDEV_LIBS += -lXxf86vm

Now it compiles with no error. I’ll update when I actually run and see if the compiled executable works.

Edit: I failed to compile both Beetle PSX and PCSX-ReARMed. However, another guide said that I can set the core updater URL to http://buildbot.libretro.com/nightly/linux/armhf/latest/ and it worked well! I downloaded latest nightly build of Beetle PSX (not HW) and it worked perfectly (60fps at most of the time) on Raspberry Pi 4 with DynaRec set to Max Performance and PGXP to OFF.

@elserba
Copy link

elserba commented Apr 24, 2020

Hello! I am totally noob with Linux, let's make this clear.
I have successfully compiled and I already have on my Raspberry Pi 4 B with Raspbian Retroarch, but I cannot update cores, I have version 1.8.5 but when updating the kernel information files it keeps flashing for hours, and if I want to "update cores" later installed "does nothing. What I can do? any help or advice?
Thanks for everything!

@DavidDraper
Copy link

Hi, noob here as well

I just got my Raspberry Pi 4 today and wanted to try my hand at putting retroarch on it. After following the tutorial, I get the following message after the make step:

LD retroarch
/usr/bin/ld: obj-unix/release/gfx/common/x11_common.o: in function x11_get_refresh_rate': x11_common.c:(.text+0x7b8): undefined reference to XF86VidModeGetModeLine'
/usr/bin/ld: obj-unix/release/gfx/common/x11_common.o: in function get_video_mode': x11_common.c:(.text+0x8b4): undefined reference to XF86VidModeGetAllModeLines'
/usr/bin/ld: obj-unix/release/gfx/common/x11_common.o: in function x11_enter_fullscreen': x11_common.c:(.text+0xb18): undefined reference to XF86VidModeSwitchToMode'
/usr/bin/ld: x11_common.c:(.text+0xb44): undefined reference to XF86VidModeSetViewPort' /usr/bin/ld: obj-unix/release/gfx/common/x11_common.o: in function x11_exit_fullscreen':
x11_common.c:(.text+0xb8c): undefined reference to XF86VidModeSwitchToMode' /usr/bin/ld: x11_common.c:(.text+0xba4): undefined reference to XF86VidModeSetViewPort'
collect2: error: ld returned 1 exit status
make: *** [Makefile:201: retroarch] Error 1

Any suggestions? Thanks in advance.

David

@elserba
Copy link

elserba commented May 16, 2020 via email

@ematysek
Copy link
Author

@DavidDraper is your rpi booted in visual mode? That's the only thing I can think of off the top of my head

@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