RaspbianXenomaiBuild - rmu75/linuxcnc-wiki GitHub Wiki


date: '2016-08-03T03:59:32' title: RaspbianXenomaiBuild

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | This wiki page is inaccurate and outdated. Instead of modifying this wiki page, create github pull requests for the official documentation on building LinuxCNC. You can read the current version of the compilation instructions here: http://linuxcnc.org/docs/master/html/code/building-linuxcnc.html LinuxCNC master branch now includes support for Xenomai realtime, configure --with-realtime=uspace |

Creating a minimal Raspbian based LinuxCNC image for Raspberry Pi

toc

1. Note

The steps presented here are outdated. The latest info can be found here https://code.google.com/p/picnc/wiki/CreateRaspbianLinuxCNC

2. Prerequisites

This build is based on the assumption that the host is running on a Debian based system or its derivatives. This procedure was created and tested on a Debian Wheezy host.

3. Build Xenomai kernel

The following steps were performed on a host computer. The kernel can also be built natively, in this case skip the installation of the cross compiler.

3.1. Install cross compiler

3.2. Download source files and patches

3.3. Apply patches

  • Apply 3.2.27 patch patch -p0 < patch/rpi-3.2.27-xenomai.patch

  • Apply Xenomai 2.6.1 patch xenomai-2.6.1/scripts/prepare-kernel.sh --arch=arm --linux=linux-rpi-3.2.27 --adeos=xenomai-2.6.1/ksrc/arch/arm/patches/ipipe-core-3.2.21-arm-1.patch

  • Apply Raspberry Pi Xenomai patch (cd linux-rpi-3.2.27; patch -p1 < ../patch/rpi-linux-3.2.21-xenomai-2.6.1.patch)

3.4. Compile kernel

  • Create build directory mkdir linux-rpi-3.2.27/build

  • Configure kernel cd linux-rpi-3.2.27 make mrproper make ARCH=arm O=build menuconfig

  • Or download and use a minimal configuration file wget http://dl.dropbox.com/u/17024524/linuxcnc/config.rpi-3.2.27-xenomai%2B -O linux-rpi-3.2.27/build/.config cd linux-rpi-3.2.27 make mrproper make ARCH=arm O=build oldconfig

  • Compile make ARCH=arm O=build CROSS_COMPILE=../../tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-

  • Install modules make ARCH=arm O=build INSTALL_MOD_PATH=dist modules_install

  • Install headers make ARCH=arm O=build INSTALL_HDR_PATH=dist headers_install find build/dist/include ( -name .install -o -name ..install.cmd ) -delete The linux-rpi-3.2.27/build/dist directory contains the kernel headers and modules while the kernel image is at linux-rpi-3.2.27/build/arch/arm/boot/ .

4. Create minimal Raspbian image

The Raspbian image is created using debootstrap and QEMU. These steps can also be performed on a Raspberry Pi.

4.1. Install required packages

  • On host PC sudo apt-get install qemu qemu-user qemu-user-static binfmt-support debootstrap

  • Or on RPi sudo apt-get install debootstrap

4.2. Build image using debootstrap

Select an appropriate Raspbian mirror at http://www.raspbian.org/RaspbianMirrors

  • On host PC cd <working dir> sudo debootstrap --foreign --no-check-gpg --include=ca-certificates --arch=armhf wheezy rootfs <Raspbian mirror>

    • Edit /etc/qemu-binfmt.conf, add the following line: EXTRA_OPTS="-L/usr/lib/arm-linux-gnueabihf"

      sudo cp $(which qemu-arm-static) rootfs/usr/bin
      sudo chroot rootfs/ /debootstrap/debootstrap --second-stage --verbose
      
    • add the raspbian mirror used to /etc/apt/sources.list sudo sh -c 'echo deb <Raspbian mirror> wheezy main > rootfs/etc/apt/sources.list'

  • Or on RPI cd <working dir> sudo debootstrap --no-check-gpg --include=ca-certificates wheezy rootfs <Raspbian mirror>

4.3. Configure Raspbian

  • Edit /etc/hostname sudo sh -c 'echo rpi-linuxcnc >rootfs/etc/hostname'

  • Edit /etc/hosts sudo sh -c 'echo -e 127.0.0.1\trpi-linuxcnc >> rootfs/etc/hosts'

  • Edit network interface sudo sh -c 'cat> rootfs/etc/network/interfaces << EOF auto lo iface lo inet loopback

      auto eth0
      iface eth0 inet dhcp
      EOF
      '
    
  • Edit /etc/fstab sudo sh -c 'cat> rootfs/etc/fstab << EOF proc /proc proc defaults 0 0 /dev/mmcblk0p1 /boot vfat defaults 0 0 EOF '

  • Create /etc/resolv.conf sudo cp /etc/resolv.conf rootfs/etc

  • Chroot sudo chroot rootfs /bin/bash

  • Set locale to ignore warnings LC_ALL=C LANGUAGE=C LANG=C

  • Install required packages apt-get update apt-get install --no-install-recommends locales sudo xauth bc openssh-server ntp gettext autoconf
    libpth-dev gcc g++ make git libncurses5-dev libreadline-gplv2-dev tcl8.5-dev tk8.5-dev bwidget
    blt libxaw7-dev libglu1-mesa-dev libgl1-mesa-dev libgtk2.0-dev python python-dev python-support
    python-tk python-lxml libboost-python-dev yapps2-runtime libtk-img python-imaging python-imaging-tk
    libgl1-mesa-swx11 python-xlib python-gtkglext1 python-configobj python-glade2 python-numpy build-essential

  • Cleanup Apt cache apt-get clean

  • Create xenomai group addgroup xenomai addgroup root xenomai

  • Create new user adduser rpi usermod -a -G xenomai,sudo,staff,kmem rpi

  • Configure udev rules cat >/etc/udev/rules.d/xenomai.rules<<EOF # allow RW access to /dev/mem KERNEL=="mem", MODE="0660", GROUP="kmem" # real-time heap device (Xenomai:rtheap) KERNEL=="rtheap", MODE="0660", GROUP=="xenomai" # real-time pipe devices (Xenomai:rtpipe) KERNEL=="rtp[0-9]*", MODE="0660", GROUP="xenomai" EOF

  • Exit chroot exit

  • Install Xenomai kernel modules and headers sudo cp -a linux-rpi-3.2.27/build/dist/lib/modules rootfs/lib/ sudo cp -a linux-rpi-3.2.27/build/dist/include/* rootfs/usr/include sudo cp linux-rpi-3.2.27/build/.config rootfs/boot/config-3.2.27-xenomai+

5. Build LinuxCNC

Compiling is done under the chroot environment. These steps are the same for both host PC and RPi.

  • Copy sources sudo cp -a xenomai-2.6.1 rootfs/usr/src git clone -b rtos-integration-preview3 --depth 1 git://git.mah.priv.at/emc2-dev.git sudo cp -a emc2-dev rootfs/usr/src/

  • Chroot sudo chroot rootfs

  • Ignore locale warnings LC_ALL=C LANGUAGE=C LANG=C

  • Compile and install Xenomai cd /usr/src/xenomai-2.6.1 ./configure make DESTDIR=$(pwd)/rpi install tar cf - -C rpi usr/xenomai/{bin,lib,sbin,include} | tar xvf - -C / echo /usr/xenomai/lib/ > /etc/ld.so.conf.d/xenomai.conf ldconfig -v

  • Cleanup Xenomai make clean rm -r rpi

  • Compile and install LinuxCNC cd ../emc2-dev/src ./autogen.sh ./configure --prefix=/usr/local --with-platform=raspberry --disable-build-documentation --with-kernel=/boot/config-3.2.27-xenomai+ make make install

  • Cleanup LinuxCNC make clean

  • Exit chroot exit

  • Cleanup QEMU sudo rm rootfs/usr/bin/qemu-arm-static

6. Create SD card image

This section will create a 2GB SD image This section creates a 2GB SD image file

  • Create sparse file cd <working dir> dd if=/dev/zero of=rpi-lcnc.img count=0 bs=1 seek=2021654528

  • Create partitions sudo sh -c 'cat <<EOF | sfdisk --force rpi-lcnc.img unit: sectors

      1 : start=     2048, size=   204800, Id= c
      2 : start=   206848, size=  3741696, Id=83
      EOF
      '
    
  • Format partitions sudo losetup /dev/loop0 rpi-lcnc.img -o $((2048512)) sudo mkfs.vfat -F 32 -n BOOT /dev/loop0 sudo losetup -d /dev/loop0 sudo losetup /dev/loop0 rpi-lcnc.img -o $((206848512)) sudo mkfs.ext4 -L ROOT /dev/loop0 sudo losetup -d /dev/loop0

  • Mount partitions mkdir -p mnt/{boot,root} sudo mount -o loop,offset=$((2048512)) rpi-lcnc.img mnt/boot sudo mount -o loop,offset=$((206848512)) rpi-lcnc.img mnt/root

  • Populate ROOT sudo rsync -a rootfs/ mnt/root/ sudo cp -a firmware/hardfp/opt/vc mnt/root/opt/

  • Populate BOOT sudo mv rootfs/boot/* mnt/boot/ sudo cp firmware/boot/{*bin,*dat,*elf} mnt/boot/ sudo cp linux-rpi-3.2.27/build/arch/arm/boot/Image mnt/boot/kernel.img sudo sh -c 'cat >mnt/boot/config.txt<<EOF kernel=kernel.img arm_freq=800 core_freq=250 sdram_freq=400 over_voltage=0 gpu_mem=16 EOF ' sudo sh -c 'cat >mnt/boot/cmdline.txt<<EOF xeno_nucleus.xenomai_gid=1000 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait EOF '

  • Unmount partitions sudo umount mnt/{boot,root}

  • Compress image bzip2 -9 rpi-lcnc.img

  • Install image sudo sh -c 'bzcat rpi-lcnc.img.bz2 > /dev/<sdcard>'

7. Post-install

  • Configure locale sudo dpkg-reconfigure locales

  • Configure timezone sudo dpkg-reconfigure tzdata

8. Testing

  • SSH to RPi ssh -X -l rpi <ip address>

  • Xenomai latency test sudo sh -c 'echo 3500 > /proc/xenomai/latency' /usr/xenomai/bin/latency

  • LinuxCNC latency test latency-test 100us 1ms

9. Pre-built image

Note: The first boot will take a while since the SSH keys are being generated

  •  This pre-built image does not have libgl1-mesa-swx11 installed (this package is needed by Axis)*
    
  • Download

         [xenomai.img](/rmu75/linuxcnc-wiki/wiki/xenomai.img)(http://87.106.51.120/downloads/xenomai.img)
    
         or
    
      <http://filecloud.io/_0vew6zmj>
    
      Username: *rpi*
      Password: *linuxcnc*
    

10. References

http://wiki.debian.org/Debootstrap

http://www.blaess.fr/christophe/2012/08/27/xenomai-sur-raspberry-pi/

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=41&t=12368

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=14122

http://wrttn.in/59e640

11. As a script

A mostly working shell script that performs these same steps is now available at https://github.com/schue/xenopicnc