Programming the Odroid-Go Ultra using SDL2
[Friday, 30th December 2022]

The Odroid-Go Ultra is a handheld game system released by Hardkernel , a Korean maker of single-board computers. It is basically a very powerful ARMv8 computer with Ubuntu 20.04.4 Linux (Aarch64) as the OS and EmulationStation as the frontend plus many different emulators.

Many people might be inclined to regard the OGU purely as a portable game emulation device. I see it in a slightly different way because it reminds me of the GP32 made by Gamepark (also a Korean company) in the early-mid 2000s. I have very fond memories of the GP32 because there was a nice little homebrew programming scene which I was part of. I'd love to see a similar scene to emerge for the Odroid-Go Ultra.

SDL2 as an SDK would be an obvious and accessible choice. Luckily, it has been ported by the Odroid forum member JonnyonFlame . I picked up his port and created an easy-to-use SDL2 SDK package for the OGU. It can be used to compile SDL2 applications on the device itself as well as to cross-compile them on an Ubuntu Linux PC.

You can find the SDL2-ogu project repository on GitHub:

https://www.github.com/chn-dev/SDL2-ogu/

Or just download the pre-compiled package:

SDL2-ogu_2.0.22_20221230.tar.gz (3.03MB)

Here's the project website: SDL2-ogu


If you're new to the Odroid-Go Ultra, I hope the following small guide helps you to set up a (cross-)development environment.

Connecting to the OGU from your PC and Basic Setup


The OGU has no built-in Wi-Fi, but it does have a USB Type-A connector. You can connect a compatible USB Wi-Fi or Ethernet adapter. Personally, I got a Netgear AC600 (A6100) Wi-Fi adapter and a uni USB-Ethernet adapter . They both worked right out of the box with my OGU.

Once the OGU is connected to the network, it is reachable via its hostname "gou". You can connect to it using ssh and SFTP. The username and password is "odroid".

The OGU comes preinstalled with everything you need for programming, except cmake and git. Luckily, since it is an Ubuntu machine, you can just install them from the Internet using apt:

sudo apt-get install cmake
sudo apt-get install git



(Optional) Setting up NFS


The OGU comes with 16GB of internal eMMC flash memory where the Ubuntu system is installed. When you login via ssh or sftp and work from there on the system, you're actually using this internal flash memory.

You might feel uncomfortable about putting wear on internal, non-replaceable flash memory all the time. So you might want to work on a network drive using NFS instead. There's a good manual describing how to configure NFS on the server and the client, in general terms.

As an example, here's what I did to share a directory on my Ubuntu PC (hostname: "lxle2004", user name: "chn") with the OGU.

On the Ubuntu PC:


I'm actually using an LXLE (which is a flavour of Ubuntu) virtual machine on my desktop PC with a bridged network adapter, so it is directly reachable from my OGU in the same network. On that virtual machine, I installed the NFS server package:

sudo apt-get install nfs-kernel-server



Next, I created the directory /home/chn/ogu (my user name is 'chn') to share with the OGU:

mkdir /home/chn/ogu



Then I added the following line to /etc/exports as root (sudo):

/home/chn/ogu gou(rw,sync,crossmnt,root_squash)



This means that the directory /home/chn/ogu is shared with the computer having the hostname 'gou'.

Finally, I restarted the NFS service:

sudo systemctl restart nfs-kernel-server



On the OGU:


Create the directory /home/odroid/nfs where the remote directory can be mounted:

mkdir /home/odroid/nfs



Add the following line to /etc/fstab as root (sudo):

lxle2004:/home/chn/ogu /home/odroid/nfs nfs defaults,rw,user,exec,noauto 0 0



Then mount the remote directory:

mount /home/odroid/nfs



(Optional) Compiling SDL2 for the OGU - on the OGU



You can find the build_SDL2-ogu.sh script in my GitHub repository .

Here's how to use it on the OGU:

git clone https://github.com/chn-dev/SDL2-ogu
cd SDL2-ogu
./build_SDL2-ogu.sh



If everything went fine, the script will have created the SDL2-ogu package with the file name "SDL2-ogu_2.0.22_yyyyMMdd.tar.gz", whereby "yyyyMMdd" denotes the date at the time of its creation.

Using the SDL2-ogu Package



Copy the SDL2-ogu package (for example: "SDL2-ogu_2.0.22_20221230.tar.gz") anywhere on your OGU (the NFS share would be a good place) and extract it:

tar xzvf SDL2-ogu_2.0.22_20221229.tar.gz



After that, you can build the included "helloworld" example project like this:

cd SDL2-ogu/projects/helloworld
cmake . -B helloworld -DCMAKE_MODULE_PATH=../.. -DCMAKE_TOOLCHAIN_FILE=../../aarch64.cmake



The "-DCMAKE_MODULE_PATH" specifies the path where the FindSDL2.cmake file is located, and the "-DCMAKE_TOOLCHAIN_FILE" parameter specifies the location of the aarch64.cmake toolchain file so that the correct (cross-)compiler is used. Both files are included in the SDL2-ogu package.

The Makefile is written to the directory SDL2-ogu/projects/helloworld/helloworld/Makefile, so you can build the project using:

make -C helloworld



If everything goes well, the "helloworld" binary is written to SDL2-ogu/projects/helloworld/helloworld/helloworld".

Before you start it, it is highly recommended to stop emulationstation on the OGU:

sudo systemctl stop emulationstation



Otherwise, its screen output would interfere with the screen output of the helloworld program.

It is also necessary to set some environment variables so that SDL2 uses the correct LCD screen orientation:

export SDL_MALI_ORIENTATION=1
export SDL_MALI_ROTATION=0



Then cd to the helloworld binary's directory and start it:

cd helloworld
./helloworld



That's it! You should see cute bear wearing headphones on the screen while some music is playing. You can rotate the picture using the shoulder buttons, move it using the D-Pad and zoom it using the A and B buttons. Pressing the Y button exits the application.

There's also a helloworld.sh script which sets the environment variables, goes to the helloworld directory and starts the helloworld binary. We will see in a minute why I created it.

Cross-Compiling for the OGU



If you're using an Ubuntu Linux PC, you can use the SDL2-ogu package as-is to cross-compile for the OGU. The steps for compilation are the same as when compiling directly on the device itself (see above). However, the cross-compiler for the arm64 architecture needs to be installed first:

sudo apt-get install crossbuild-essential-arm64



Deploying Your Binaries on a MicroSD Card



By default, the SDL2 library is linked statically. This means that you could theoretically copy that binary to the OGU's MicroSD card and it would be able to run from there. There are no dependencies which are unavailable on a stock OGU.

However, the OGU's default frontend is EmulationStation, and as such, it looks for any supported video game system's ROM files in the "/roms" subdirectory. For example SNES ROMs are in "/roms/snes" and Genesis ROMs in "/roms/megadrive". There is no support for native binaries.

Luckily, we can change that.

As root, add the following lines to the file /etc/emulationstation/es_systems.cfg:

        <system>
                <name>native</name>
                <fullname>native</fullname>
                <path>/volumes/sdcard.1/roms/native/</path>
                <extension>.sh</extension>
                <command>%ROM%</command>
                <platform>native</platform>
                <theme>native</theme>
        </system>



You can then copy the files of the example helloworld project to the MicroSD card like this:

/roms/native/helloworld.sh
/roms/native/helloworld/helloworld
/roms/native/helloworld/nearly_there.mod
/roms/native/helloworld/pic.bmp



After applying these changes and rebooting the OGU, EmulationStation should show you a new menu entry called "native" with one subitem called "helloworld". This allows you to start the helloworld SDL2 program.

I think this would be the most universal way to distribute native binaries for the Odroid-Go Ultra.

Final Words



In case of questions or comments, you can contact me via Mastodon or Email.