README-raspberrypi.txt
author Gabriel Jacobo <gabomdq@gmail.com>
Sun, 13 Oct 2013 17:15:43 -0300
changeset 7809 fd53b2b2a205
parent 7808 627f256b0e56
child 8007 f4264c673a8d
permissions -rw-r--r--
Prevent keystrokes from leaking through to the console when using evdev.

This uses the same method Weston and X use. Sadly, to be fully effective when
launching remotely, this needs root permissions.
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@7806
    65
gabomdq@7806
    66
The final step is compiling SDL itself.
gabomdq@7806
    67
gabomdq@7806
    68
    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
    69
    cd <SDL SOURCE>
gabomdq@7806
    70
    mkdir -p build;cd build
gabomdq@7806
    71
    ../configure --with-sysroot=$SYSROOT --host=arm-raspberry-linux-gnueabihf --prefix=$PWD/rpi-sdl2-installed --disable-pulseaudio --disable-esd
gabomdq@7808
    72
    make
gabomdq@7808
    73
    make install
gabomdq@7806
    74
gabomdq@7808
    75
To be able to deploy this to /usr/local in the Raspbian system you need to fix up a few paths:
gabomdq@7808
    76
    
gabomdq@7808
    77
    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
    78
    
gabomdq@7806
    79
================================================================================
gabomdq@7806
    80
 Apps don't work or poor video/audio performance
gabomdq@7806
    81
================================================================================
gabomdq@7806
    82
gabomdq@7806
    83
If you get sound problems, buffer underruns, etc, run "sudo rpi-update" to 
gabomdq@7806
    84
update the RPi's firmware. Note that doing so will fix these problems, but it
gabomdq@7806
    85
will also render the CMA - Dynamic Memory Split functionality useless.
gabomdq@7806
    86
gabomdq@7806
    87
Also, by default the Raspbian distro configures the GPU RAM at 64MB, this is too
gabomdq@7806
    88
low in general, specially if a 1080p TV is hooked up.
gabomdq@7806
    89
gabomdq@7806
    90
See here how to configure this setting: http://elinux.org/RPiconfig
gabomdq@7806
    91
gabomdq@7806
    92
Using a fixed gpu_mem=128 is the best option (specially if you updated the 
gabomdq@7806
    93
firmware, using CMA probably won't work, at least it's the current case).
gabomdq@7806
    94
gabomdq@7806
    95
================================================================================
gabomdq@7778
    96
 No input
gabomdq@7778
    97
================================================================================
gabomdq@7778
    98
gabomdq@7778
    99
Make sure you belong to the "input" group.
gabomdq@7778
   100
gabomdq@7778
   101
    sudo usermod -aG input `whoami`
gabomdq@7778
   102
gabomdq@7778
   103
================================================================================
gabomdq@7753
   104
 No HDMI Audio
gabomdq@7753
   105
================================================================================
gabomdq@7753
   106
gabomdq@7753
   107
If you notice that ALSA works but there's no audio over HDMI, try adding:
gabomdq@7753
   108
    
gabomdq@7753
   109
    hdmi_drive=2
gabomdq@7753
   110
    
gabomdq@7753
   111
to your config.txt file and reboot.
gabomdq@7753
   112
gabomdq@7753
   113
Reference: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=5062
gabomdq@7753
   114
gabomdq@7753
   115
================================================================================
gabomdq@7778
   116
 Text Input API support
gabomdq@7778
   117
================================================================================
gabomdq@7778
   118
gabomdq@7778
   119
The Text Input API is supported, with translation of scan codes done via the
gabomdq@7778
   120
kernel symbol tables. For this to work, SDL needs access to a valid console.
gabomdq@7778
   121
If you notice there's no SDL_TEXTINPUT message being emmited, double check that
gabomdq@7778
   122
your app has read access to one of the following:
gabomdq@7778
   123
    
gabomdq@7778
   124
* /proc/self/fd/0
gabomdq@7778
   125
* /dev/tty
gabomdq@7778
   126
* /dev/tty[0...6]
gabomdq@7778
   127
* /dev/vc/0
gabomdq@7778
   128
* /dev/console
gabomdq@7778
   129
gabomdq@7778
   130
This is usually not a problem if you run from the physical terminal (as opposed
gabomdq@7778
   131
to running from a pseudo terminal, such as via SSH). If running from a PTS, a 
gabomdq@7778
   132
quick workaround is to run your app as root or add yourself to the tty group,
gabomdq@7778
   133
then re login to the system.
gabomdq@7778
   134
gabomdq@7778
   135
   sudo usermod -aG tty `whoami`
gabomdq@7778
   136
    
gabomdq@7778
   137
The keyboard layout used by SDL is the same as the one the kernel uses.
gabomdq@7778
   138
To configure the layout on Raspbian:
gabomdq@7778
   139
    
gabomdq@7778
   140
    sudo dpkg-reconfigure keyboard-configuration
gabomdq@7778
   141
    
gabomdq@7778
   142
To configure the locale, which controls which keys are interpreted as letters,
gabomdq@7778
   143
this determining the CAPS LOCK behavior:
gabomdq@7778
   144
gabomdq@7778
   145
    sudo dpkg-reconfigure locales
gabomdq@7778
   146
gabomdq@7778
   147
================================================================================
gabomdq@7753
   148
 Notes
gabomdq@7753
   149
================================================================================
gabomdq@7753
   150
gabomdq@7809
   151
* When launching apps remotely (via SSH), SDL can prevent local keystrokes from
gabomdq@7809
   152
  leaking into the console only if it has root privileges. Launching apps locally
gabomdq@7809
   153
  does not suffer from this issue.
gabomdq@7809
   154
  
gabomdq@7806
   155