README-raspberrypi.txt
author David Ludwig <dludwig@pobox.com>
Wed, 25 Dec 2013 21:39:48 -0500
changeset 8563 c0e68f3b6bbb
parent 8007 f4264c673a8d
child 8127 7d1ae292393b
permissions -rw-r--r--
WinRT: compiled the d3d11 renderer's shaders into SDL itself

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