README-raspberrypi.txt 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. ================================================================================
  2. SDL2 for Raspberry Pi
  3. ================================================================================
  4. Requirements:
  5. Raspbian (other Linux distros may work as well).
  6. ================================================================================
  7. Features
  8. ================================================================================
  9. * Works without X11
  10. * Hardware accelerated OpenGL ES 2.x
  11. * Sound via ALSA
  12. * Input (mouse/keyboard/joystick) via EVDEV
  13. * Hotplugging of input devices via UDEV
  14. ================================================================================
  15. Raspbian Build Dependencies
  16. ================================================================================
  17. sudo apt-get install libudev-dev libasound2-dev libdbus-1-dev
  18. You also need the VideoCore binary stuff that ships in /opt/vc for EGL and
  19. OpenGL ES 2.x, it usually comes pre installed, but in any case:
  20. sudo apt-get install libraspberrypi0 libraspberrypi-bin libraspberrypi-dev
  21. ================================================================================
  22. Cross compiling from x86 Linux
  23. ================================================================================
  24. To cross compile SDL for Raspbian from your desktop machine, you'll need a
  25. Raspbian system root and the cross compilation tools. We'll assume these tools
  26. will be placed in /opt/rpi-tools
  27. sudo git clone --depth 1 https://github.com/raspberrypi/tools /opt/rpi-tools
  28. You'll also need a Rasbian binary image.
  29. Get it from: http://downloads.raspberrypi.org/raspbian_latest
  30. After unzipping, you'll get file with a name like: <date>-wheezy-raspbian.img
  31. Let's assume the sysroot will be built in /opt/rpi-sysroot.
  32. export SYSROOT=/opt/rpi-sysroot
  33. sudo kpartx -a -v <path_to_raspbian_image>.img
  34. sudo mount -o loop /dev/mapper/loop0p2 /mnt
  35. sudo cp -r /mnt $SYSROOT
  36. sudo apt-get install qemu binfmt-support qemu-user-static
  37. sudo cp /usr/bin/qemu-arm-static $SYSROOT/usr/bin
  38. sudo mount --bind /dev $SYSROOT/dev
  39. sudo mount --bind /proc $SYSROOT/proc
  40. sudo mount --bind /sys $SYSROOT/sys
  41. Now, before chrooting into the ARM sysroot, you'll need to apply a workaround,
  42. edit $SYSROOT/etc/ld.so.preload and comment out all lines in it.
  43. sudo chroot $SYSROOT
  44. 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 libxinerama-dev libxxf86vm-dev libxss-dev
  45. exit
  46. sudo umount $SYSROOT/dev
  47. sudo umount $SYSROOT/proc
  48. sudo umount $SYSROOT/sys
  49. sudo umount /mnt
  50. There's one more fix required, as the libdl.so symlink uses an absolute path
  51. which doesn't quite work in our setup.
  52. sudo rm -rf $SYSROOT/usr/lib/arm-linux-gnueabihf/libdl.so
  53. sudo ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 $SYSROOT/usr/lib/arm-linux-gnueabihf/libdl.so
  54. The final step is compiling SDL itself.
  55. 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"
  56. cd <SDL SOURCE>
  57. mkdir -p build;cd build
  58. ../configure --with-sysroot=$SYSROOT --host=arm-raspberry-linux-gnueabihf --prefix=$PWD/rpi-sdl2-installed --disable-pulseaudio --disable-esd
  59. make
  60. make install
  61. To be able to deploy this to /usr/local in the Raspbian system you need to fix up a few paths:
  62. perl -w -pi -e "s#$PWD/rpi-sdl2-installed#/usr/local#g;" ./rpi-sdl2-installed/lib/libSDL2.la ./rpi-sdl2-installed/lib/pkgconfig/sdl2.pc ./rpi-sdl2-installed/bin/sdl2-config
  63. ================================================================================
  64. Apps don't work or poor video/audio performance
  65. ================================================================================
  66. If you get sound problems, buffer underruns, etc, run "sudo rpi-update" to
  67. update the RPi's firmware. Note that doing so will fix these problems, but it
  68. will also render the CMA - Dynamic Memory Split functionality useless.
  69. Also, by default the Raspbian distro configures the GPU RAM at 64MB, this is too
  70. low in general, specially if a 1080p TV is hooked up.
  71. See here how to configure this setting: http://elinux.org/RPiconfig
  72. Using a fixed gpu_mem=128 is the best option (specially if you updated the
  73. firmware, using CMA probably won't work, at least it's the current case).
  74. ================================================================================
  75. No input
  76. ================================================================================
  77. Make sure you belong to the "input" group.
  78. sudo usermod -aG input `whoami`
  79. ================================================================================
  80. No HDMI Audio
  81. ================================================================================
  82. If you notice that ALSA works but there's no audio over HDMI, try adding:
  83. hdmi_drive=2
  84. to your config.txt file and reboot.
  85. Reference: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=5062
  86. ================================================================================
  87. Text Input API support
  88. ================================================================================
  89. The Text Input API is supported, with translation of scan codes done via the
  90. kernel symbol tables. For this to work, SDL needs access to a valid console.
  91. If you notice there's no SDL_TEXTINPUT message being emitted, double check that
  92. your app has read access to one of the following:
  93. * /proc/self/fd/0
  94. * /dev/tty
  95. * /dev/tty[0...6]
  96. * /dev/vc/0
  97. * /dev/console
  98. This is usually not a problem if you run from the physical terminal (as opposed
  99. to running from a pseudo terminal, such as via SSH). If running from a PTS, a
  100. quick workaround is to run your app as root or add yourself to the tty group,
  101. then re login to the system.
  102. sudo usermod -aG tty `whoami`
  103. The keyboard layout used by SDL is the same as the one the kernel uses.
  104. To configure the layout on Raspbian:
  105. sudo dpkg-reconfigure keyboard-configuration
  106. To configure the locale, which controls which keys are interpreted as letters,
  107. this determining the CAPS LOCK behavior:
  108. sudo dpkg-reconfigure locales
  109. ================================================================================
  110. Notes
  111. ================================================================================
  112. * When launching apps remotely (via SSH), SDL can prevent local keystrokes from
  113. leaking into the console only if it has root privileges. Launching apps locally
  114. does not suffer from this issue.