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