|
| 1 | +Raspberry Pi |
| 2 | +============ |
| 3 | + |
| 4 | +Requirements: |
| 5 | + |
| 6 | +Raspberry Pi OS (other Linux distros may work as well). |
| 7 | + |
| 8 | +In modern times, the Raspberry Pi works mostly like any other Linux device: |
| 9 | +for video, you can use X11, Wayland, or KMSDRM. For audio, you can use ALSA, |
| 10 | +PulseAudio, or PipeWire, etc. OpenGL, OpenGL ES, and Vulkan are known to work. |
| 11 | + |
| 12 | +There is a video backend in SDL called "rpi" that uses a deprecated Broadcom |
| 13 | +interface (named "dispmanx") to draw directly to the console without X11. |
| 14 | +Newer Raspberry Pi OS releases don't support this (and work fine with our |
| 15 | +"kmsdrm" backend for the same purposes, a standard Linux interface). Don't |
| 16 | +panic if you can't use this backend, or CMake says it can't find libraries it |
| 17 | +needs for this. |
| 18 | + |
| 19 | +SDL has, in past times, worked on the original Raspberry Pi and the RPi 2, but |
| 20 | +these devices are no longer targets we actively test; if they broke, please |
| 21 | +report bugs or send patches! |
| 22 | + |
| 23 | +The Raspberry Pi 3 and later (in 32-bit and 64-bit mode) are still known to |
| 24 | +work well at the time of this writing. The Raspberry Pi Zero and Zero 2 are |
| 25 | +also known to work well. |
| 26 | + |
| 27 | + |
| 28 | +## Documentation Out Of Date |
| 29 | + |
| 30 | +The rest of this document is likely out of date; a lot has changed in recent |
| 31 | +years in both SDL and the Raspberry Pi universe, and this document has not |
| 32 | +been updated to reflect those details. Take the rest of this information with |
| 33 | +a grain of salt! |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +NEON |
| 38 | +---- |
| 39 | + |
| 40 | +If your Pi has NEON support, make sure you add -mfpu=neon to your CFLAGS so |
| 41 | +that SDL will select some otherwise-disabled highly-optimized code. The |
| 42 | +original Pi and Pi Zero units don't have NEON; everything from the Pi2/PiZero2 |
| 43 | +and later do. |
| 44 | + |
| 45 | + |
| 46 | +Cross compiling from x86 Linux |
| 47 | +------------------------------ |
| 48 | + |
| 49 | +To cross compile SDL for Raspbian from your desktop machine, you'll need a |
| 50 | +Raspbian system root and the cross compilation tools. We'll assume these tools |
| 51 | +will be placed in /opt/rpi-tools |
| 52 | + |
| 53 | + sudo git clone --depth 1 https://github.com/raspberrypi/tools /opt/rpi-tools |
| 54 | + |
| 55 | +You'll also need a Raspbian binary image. |
| 56 | +Get it from: http://downloads.raspberrypi.org/raspbian_latest |
| 57 | +After unzipping, you'll get file with a name like: "<date>-wheezy-raspbian.img" |
| 58 | +Let's assume the sysroot will be built in /opt/rpi-sysroot. |
| 59 | + |
| 60 | + export SYSROOT=/opt/rpi-sysroot |
| 61 | + sudo kpartx -a -v <path_to_raspbian_image>.img |
| 62 | + sudo mount -o loop /dev/mapper/loop0p2 /mnt |
| 63 | + sudo cp -r /mnt $SYSROOT |
| 64 | + sudo apt-get install qemu binfmt-support qemu-user-static |
| 65 | + sudo cp /usr/bin/qemu-arm-static $SYSROOT/usr/bin |
| 66 | + sudo mount --bind /dev $SYSROOT/dev |
| 67 | + sudo mount --bind /proc $SYSROOT/proc |
| 68 | + sudo mount --bind /sys $SYSROOT/sys |
| 69 | + |
| 70 | +Now, before chrooting into the ARM sysroot, you'll need to apply a workaround, |
| 71 | +edit $SYSROOT/etc/ld.so.preload and comment out all lines in it. |
| 72 | + |
| 73 | + sudo chroot $SYSROOT |
| 74 | + apt-get install libudev-dev libasound2-dev libdbus-1-dev libraspberrypi0 libraspberrypi-bin libraspberrypi-dev libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxi-dev libxss-dev |
| 75 | + exit |
| 76 | + sudo umount $SYSROOT/dev |
| 77 | + sudo umount $SYSROOT/proc |
| 78 | + sudo umount $SYSROOT/sys |
| 79 | + sudo umount /mnt |
| 80 | + |
| 81 | +There's one more fix required, as the libdl.so symlink uses an absolute path |
| 82 | +which doesn't quite work in our setup. |
| 83 | + |
| 84 | + sudo rm -rf $SYSROOT/usr/lib/arm-linux-gnueabihf/libdl.so |
| 85 | + sudo ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 $SYSROOT/usr/lib/arm-linux-gnueabihf/libdl.so |
| 86 | + |
| 87 | +The final step is compiling SDL itself. |
| 88 | + |
| 89 | + export CC="/opt/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc --sysroot=$SYSROOT -I$SYSROOT/opt/vc/include -I$SYSROOT/usr/include -I$SYSROOT/opt/vc/include/interface/vcos/pthreads -I$SYSROOT/opt/vc/include/interface/vmcs_host/linux" |
| 90 | + cd <SDL SOURCE> |
| 91 | + mkdir -p build;cd build |
| 92 | + LDFLAGS="-L$SYSROOT/opt/vc/lib" ../configure --with-sysroot=$SYSROOT --host=arm-raspberry-linux-gnueabihf --prefix=$PWD/rpi-sdl3-installed --disable-pulseaudio --disable-esd |
| 93 | + make |
| 94 | + make install |
| 95 | + |
| 96 | +To be able to deploy this to /usr/local in the Raspbian system you need to fix up a few paths: |
| 97 | + |
| 98 | + perl -w -pi -e "s#$PWD/rpi-sdl3-installed#/usr/local#g;" ./rpi-sdl3-installed/lib/libSDL3.la ./rpi-sdl3-installed/lib/pkgconfig/sdl3.pc |
| 99 | + |
| 100 | +Apps don't work or poor video/audio performance |
| 101 | +----------------------------------------------- |
| 102 | + |
| 103 | +If you get sound problems, buffer underruns, etc, run "sudo rpi-update" to |
| 104 | +update the RPi's firmware. Note that doing so will fix these problems, but it |
| 105 | +will also render the CMA - Dynamic Memory Split functionality useless. |
| 106 | + |
| 107 | +Also, by default the Raspbian distro configures the GPU RAM at 64MB, this is too |
| 108 | +low in general, specially if a 1080p TV is hooked up. |
| 109 | + |
| 110 | +See here how to configure this setting: http://elinux.org/RPiconfig |
| 111 | + |
| 112 | +Using a fixed gpu_mem=128 is the best option (specially if you updated the |
| 113 | +firmware, using CMA probably won't work, at least it's the current case). |
| 114 | + |
| 115 | +No input |
| 116 | +-------- |
| 117 | + |
| 118 | +Make sure you belong to the "input" group. |
| 119 | + |
| 120 | + sudo usermod -aG input `whoami` |
| 121 | + |
| 122 | +No HDMI Audio |
| 123 | +------------- |
| 124 | + |
| 125 | +If you notice that ALSA works but there's no audio over HDMI, try adding: |
| 126 | + |
| 127 | + hdmi_drive=2 |
| 128 | + |
| 129 | +to your config.txt file and reboot. |
| 130 | + |
| 131 | +Reference: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=5062 |
| 132 | + |
| 133 | +Text Input API support |
| 134 | +---------------------- |
| 135 | + |
| 136 | +The Text Input API is supported, with translation of scan codes done via the |
| 137 | +kernel symbol tables. For this to work, SDL needs access to a valid console. |
| 138 | +If you notice there's no SDL_EVENT_TEXT_INPUT message being emitted, double check that |
| 139 | +your app has read access to one of the following: |
| 140 | + |
| 141 | +* /proc/self/fd/0 |
| 142 | +* /dev/tty |
| 143 | +* /dev/tty[0...6] |
| 144 | +* /dev/vc/0 |
| 145 | +* /dev/console |
| 146 | + |
| 147 | +This is usually not a problem if you run from the physical terminal (as opposed |
| 148 | +to running from a pseudo terminal, such as via SSH). If running from a PTS, a |
| 149 | +quick workaround is to run your app as root or add yourself to the tty group, |
| 150 | +then re-login to the system. |
| 151 | + |
| 152 | + sudo usermod -aG tty `whoami` |
| 153 | + |
| 154 | +The keyboard layout used by SDL is the same as the one the kernel uses. |
| 155 | +To configure the layout on Raspbian: |
| 156 | + |
| 157 | + sudo dpkg-reconfigure keyboard-configuration |
| 158 | + |
| 159 | +To configure the locale, which controls which keys are interpreted as letters, |
| 160 | +this determining the CAPS LOCK behavior: |
| 161 | + |
| 162 | + sudo dpkg-reconfigure locales |
| 163 | + |
| 164 | + |
| 165 | +OpenGL problems |
| 166 | +--------------- |
| 167 | + |
| 168 | +If you have desktop OpenGL headers installed at build time in your RPi or cross |
| 169 | +compilation environment, support for it will be built in. However, the chipset |
| 170 | +does not actually have support for it, which causes issues in certain SDL apps |
| 171 | +since the presence of OpenGL support supersedes the ES/ES2 variants. |
| 172 | +The workaround is to disable OpenGL at configuration time: |
| 173 | + |
| 174 | + ./configure --disable-video-opengl |
| 175 | + |
| 176 | +Or if the application uses the Render functions, you can use the SDL_RENDER_DRIVER |
| 177 | +environment variable: |
| 178 | + |
| 179 | + export SDL_RENDER_DRIVER=opengles2 |
| 180 | + |
| 181 | +Notes |
| 182 | +----- |
| 183 | + |
| 184 | +* When launching apps remotely (via SSH), SDL can prevent local keystrokes from |
| 185 | + leaking into the console only if it has root privileges. Launching apps locally |
| 186 | + does not suffer from this issue. |
| 187 | + |
| 188 | + |
0 commit comments