[Home]RaspbianXenomaiBuild

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

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

1. Note
2. Prerequisites
3. Build Xenomai kernel
3.1. Install cross compiler
3.2. Download source files and patches
3.3. Apply patches
3.4. Compile kernel
4. Create minimal Raspbian image
4.1. Install required packages
4.2. Build image using debootstrap
4.3. Configure Raspbian
5. Build LinuxCNC
6. Create SD card image
7. Post-install
8. Testing
9. Pre-built image
10. References
11. As a script

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

	cd <working dir>
	wget https://github.com/raspberrypi/tools/archive/master.tar.gz
	tar xzf master.tar.gz

3.2. Download source files and patches

	git clone -b rpi-3.2.27 --depth 1 git://github.com/raspberrypi/linux.git linux-rpi-3.2.27
	git clone https://github.com/raspberrypi/firmware.git
	wget http://download.gna.org/xenomai/stable/xenomai-2.6.1.tar.bz2
	tar xjf xenomai-2.6.1.tar.bz2
	mkdir patch
	wget http://www.cim.mcgill.ca/~ian/rpi-linux-3.2.21-xenomai-2.6.1.patch -P patch
	wget http://dl.dropbox.com/u/17024524/linuxcnc/rpi-3.2.27-xenomai.patch -P patch

3.3. Apply patches

	patch -p0 < patch/rpi-3.2.27-xenomai.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
	(cd linux-rpi-3.2.27; patch -p1 < ../patch/rpi-linux-3.2.21-xenomai-2.6.1.patch)

3.4. Compile kernel

	mkdir linux-rpi-3.2.27/build
	cd linux-rpi-3.2.27
	make mrproper
	make ARCH=arm O=build menuconfig
	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
	make ARCH=arm O=build CROSS_COMPILE=../../tools-master/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-
	make ARCH=arm O=build INSTALL_MOD_PATH=dist modules_install
	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

	sudo apt-get install qemu qemu-user qemu-user-static binfmt-support debootstrap
	sudo apt-get install debootstrap

4.2. Build image using debootstrap

Select an appropriate Raspbian mirror at http://www.raspbian.org/RaspbianMirrors
	cd <working dir>
	sudo debootstrap --foreign --no-check-gpg --include=ca-certificates --arch=armhf wheezy rootfs <Raspbian mirror>
		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
	sudo sh -c 'echo deb <Raspbian mirror> wheezy main > rootfs/etc/apt/sources.list'
	cd <working dir>
	sudo debootstrap --no-check-gpg --include=ca-certificates wheezy rootfs <Raspbian mirror>

4.3. Configure Raspbian

	sudo sh -c 'echo rpi-linuxcnc >rootfs/etc/hostname'
	sudo sh -c 'echo -e 127.0.0.1\\trpi-linuxcnc >> rootfs/etc/hosts'
	sudo sh -c 'cat> rootfs/etc/network/interfaces << EOF
	auto lo
	iface lo inet loopback

	auto eth0
	iface eth0 inet dhcp
	EOF
	'
	sudo sh -c 'cat> rootfs/etc/fstab << EOF
	proc /proc proc defaults 0 0
	/dev/mmcblk0p1 /boot vfat defaults 0 0
	EOF
	'
	sudo cp /etc/resolv.conf rootfs/etc
	sudo chroot rootfs /bin/bash
	LC_ALL=C
	LANGUAGE=C
	LANG=C
	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 
	apt-get clean
	addgroup xenomai
	addgroup root xenomai
	adduser rpi
	usermod -a -G xenomai,sudo,staff,kmem rpi
	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
	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.
	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/
	sudo chroot rootfs
	LC_ALL=C
	LANGUAGE=C
	LANG=C
	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
	make clean
	rm -r rpi
	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
	make clean
	exit
	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
	cd <working dir>
	dd if=/dev/zero of=rpi-lcnc.img count=0 bs=1 seek=2021654528
	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
	'
	sudo losetup /dev/loop0 rpi-lcnc.img -o $((2048*512))
	sudo mkfs.vfat -F 32 -n BOOT /dev/loop0
	sudo losetup -d /dev/loop0
	sudo losetup /dev/loop0 rpi-lcnc.img -o $((206848*512))
	sudo mkfs.ext4 -L ROOT /dev/loop0
	sudo losetup -d /dev/loop0
	mkdir -p mnt/{boot,root}
	sudo mount -o loop,offset=$((2048*512)) rpi-lcnc.img mnt/boot
	sudo mount -o loop,offset=$((206848*512)) rpi-lcnc.img mnt/root
	sudo rsync -a rootfs/ mnt/root/
	sudo cp -a firmware/hardfp/opt/vc mnt/root/opt/
	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
	'	
	sudo umount mnt/{boot,root}
	bzip2 -9 rpi-lcnc.img
	sudo sh -c 'bzcat rpi-lcnc.img.bz2 > /dev/<sdcard>'

7. Post-install

	sudo dpkg-reconfigure locales
	sudo dpkg-reconfigure tzdata

8. Testing

	ssh -X -l rpi <ip address>
	sudo sh -c 'echo 3500 > /proc/xenomai/latency'
	/usr/xenomai/bin/latency
	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)

       [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

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited August 3, 2016 1:59 am by JeffEpler (diff)
Search:
Published under a Creative Commons License