Installing Duckstation on the Jetson Nano

If you purchased a Jetson Nano single-board computer without knowing very much about AI or machine learning like I did, you've probably got it sitting on a shelf right now doing very little. Unlike most other ARM SBCs, the Jetson Nano actually has pretty good graphics rendering due to it more or less being a Nintendo Switch with half the processing power meaning that it's a bit of a waste to relegate it to running headless servers or file sharing as is the norm with the RasPi after one gets bored with it. Some people like to turn these into GameCube emulation stations, as the graphics processor in them is capable of running some ROMs at okayish framerates. I couldn't get Dolphin to compile though (the same problem applies there too and may be applied to it as well), so I moved my attention to the PlayStation emulator Duckstation. You can probably just install Retroarch to get the same functionality, except that the dev gets upset if you do that, and you miss out on compiling it with various options tailored to your liking. Do note that this may accidentally hose your system or do other unexpected things that break other functionality and I am not responsible for whatever you incur.

First off, make sure you have a working standard Ubuntu image on at least a 32GB microSD card that has been set up for graphical display. I don't know if any of this will work for headless Nanos. I found that on the newest SD card image released by NVidia, the text was too small on the desktop for me to read, so I decided to SSH in and do all of this in a tmux instance.

The first hurdle with compiling Duckstation is that the compiler shipped with the Ubuntu 18.04 image that Nvidia has released for the Nano is too old to compile it. There's a rumour that any day now they're going to release an updated image, but in the meantime (March '22) you'll have to go through the process of updating the GNU C Compiler yourself.

Thanks to this thread on AskUbuntu we can see it's a fairly straightforward process.

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt install gcc-9
sudo apt install g++-9
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt install gcc-9
sudo apt install g++-9

This will install GCC version 9 on your Jetson Nano. I opted for GCC 9 just in case 10 or 11 was too new for CUDA or something, but those may also work just fine. You're not done with GCC yet though. If you attempt to run gcc -v now, it'll still tell you it's version 7. You'll have to set the alternatives manually, while making version 9 (or 10 if you opted for that) the default for both the gcc and g++ commands. You can probably skip this and just manually specify the compiler to cmake if you'd like to do that instead.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 20

The next step is to install all the packages that Duckstation needs. Go onto the wiki and install each package that it asks for, or just copy and paste this in.

sudo apt install cmake libsdl2-dev libxrandr-dev pkg-config qtbase5-dev qtbase5-private-dev qtbase5-dev-tools qttools5-dev libevdev-dev git libwayland-dev libwayland-egl-backend-dev extra-cmake-modules libcurl4-gnutls-dev libgbm-dev libdrm-dev ninja-build 
sudo apt install cmake libsdl2-dev libxrandr-dev pkg-config qtbase5-dev qtbase5-private-dev qtbase5-dev-tools qttools5-dev libevdev-dev git libwayland-dev libwayland-egl-backend-dev extra-cmake-modules libcurl4-gnutls-dev libgbm-dev libdrm-dev ninja-build 

Once these are all installed, it's time to check out and compile Duckstation. The instructions on both Github and the wiki are absolutely dismal and won't produce a working result at all for any GNU/Linux system if you follow them as they are. The commands below check out the master branch rather than dev and switch off a few useless features such as achievements and shitcord integration. I ended up turning off the Qt GUI as well because it wouldn't build when I attempted with it on. If you're interested in other compilation options, read CMakeLists.txt.

git clone https://github.com/stenzek/duckstation.git
cd duckstation
mkdir build-release
cd build-release
cmake -Bbuild-release -DCMAKE_BUILD_TYPE=Release -DENABLE_CHEEVOS=OFF -DENABLE_DISCORD_PRESENCE=OFF -GNinja ../
ninja -j4
git clone https://github.com/stenzek/duckstation.git
cd duckstation
mkdir build-release
cd build-release
cmake -Bbuild-release -DCMAKE_BUILD_TYPE=Release -DENABLE_CHEEVOS=OFF -DENABLE_DISCORD_PRESENCE=OFF -GNinja ../
ninja -j4

Ninja builds in parallel anyway meaning that the -j switch isn't really needed, however the Jetson has fairly limited RAM, especially the 2GB model which I have. If the compilation stops due to running out of RAM, you should change -j4 to -j2. You can monitor your RAM usage in htop, or better yet, jtop to see if you're hitting the limit. It'll take a while, so you may want to go for a walk, or attend to your garden as it builds.

Once it's done, you'll have a bin folder with your completed build. run it with ./duckstation-nogui and it should launch. Upload your BIOS files to your Nano and perhaps an ISO or two, and see if they load. I tested Rollcage and it ran perfectly even with 5x resolution turned on. For some reason I found myself without HDMI audio and had to run pactl set-sink-volume alsa_output.platform-70030000.hda.hdmi-stereo 100% to get any sound.