[Home]RaspbianXenomaiBuild

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

Creating a minimal Raspbian based LinuxCNC image for Raspberry Pi

1. Prerequisites
2. Build Xenomai kernel
2.1. Install cross compiler
2.2. Download source files and patches
2.3. Apply patches
2.4. Compile kernel
3. Create minimal Raspbian image
3.1. Install required packages
3.2. Build image using debootstrap
3.3. Configure Raspbian
4. Build LinuxCNC
5. Create SD card image
6. Post-install
7. Testing
8. Pre-built image
9. References

1. 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.

2. 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.

2.1. Install cross compiler

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

2.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

2.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)

2.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/ .

3. Create minimal Raspbian image

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

3.1. Install required packages

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

3.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>

3.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+

4. 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

5. 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>'

6. Post-install

	sudo dpkg-reconfigure locales
	sudo dpkg-reconfigure tzdata

7. Testing

	ssh -X -l rpi <ip address>
	sudo sh -c 'echo 3500 > /proc/xenomai/latency'
	/usr/xenomai/bin/latency
	latency-test 100us 1ms

8. 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

9. 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


LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited March 24, 2014 12:45 pm by Reneb (diff)
Search:
Published under a Creative Commons License