Showing posts with label QEMU. Show all posts
Showing posts with label QEMU. Show all posts

Saturday, April 25, 2015

Cross-Compiling for the Raspberry Pi: distributed compilation

So far I've been trying different cross-compiling techniques: QEmu, Scratchbox and Raspberry Pi tools. But I should say, they didn't work for me. Just try to build something as big as GStreamer and you will get what I'm saying.

The new approach that I'm heavily using right now is distributed compilation. It allows you by just launching the make command, having your remote PC working instead of your Pi, and a few seconds later having your program/library compiled just as if everything happened on the Pi itself.

1. Configure slaves: install distcc and configure it. Figure out how many processors you have available on the machine(s) and how many of those you would like to share. Start slave as follows (or configure it as a daemon):
$ distccd --user nobody --jobs 8 --allow 192.168.1.133 --verbose --log-stderr
2. Configure Raspbian master: install distcc and configure it. Edit /etc/distcc/hosts and comment out the line with +zeroconf. Add space-delimited list of slaves on your network.

3. Compile it! Edit PATH so it uses distcc instead of the local compiler:
$ export PATH=/usr/lib/distcc:$PATH
$ which gcc
Start compilation process.

UPDATE: very important thing that I forgot to mention. Before running distcc on your slave machine you will need to install Raspberry Pi tools and update PATH as follows:
$ export PATH=$RPI_TOOLS/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:$PATH

Wednesday, January 15, 2014

Virtual Raspbian on QEMU in Ubuntu


How to run virtual Raspbian on QEMU in Ubuntu:

1. Compile QEMU for ARM (1176).

$ sudo apt-get install git zlib1g-dev libsdl1.2-dev libpixman-1-dev
$ cd tmp
$ git clone git://git.qemu-project.org/qemu.git && cd qemu
$ ./configure --target-list="arm-softmmu arm-linux-user" --enable-sdl --prefix=/usr/local
$ make
$ sudo make install
2. Prepare QEMU environment and raspbian image.
$ mkdir ~/qemu-vms/ && cd ~/qemu-vms/
Download Raspbian Wheezy from http://www.raspberrypi.org/downloads and Linux kernel for QEMU from http://xecdesign.com/downloads/linux-qemu/kernel-qemu.
$ file ~/qemu-vms/2014-01-07-wheezy-raspbian.img
~/qemu-vms/2014-01-07-wheezy-raspbian.img: x86 boot sector; partition 1: ID=0xc, starthead 130, startsector 8192, 114688 sectors; partition 2: ID=0x83, starthead 165, startsector 122880, 5662720 sectors, code offset 0xb8
Take the partition 2 'startsector' value an multiply by 512, and use this figure as the offset value in the mount command below:
$ sudo mount ~/qemu-vms/2014-01-07-wheezy-raspbian.img -o offset=$((122880*512)) /mnt
Comment out the line in the /mnt/etc/ld.so.preload file and unmount:
$ sudo emacs -nw /mnt/etc/ld.so.preload
$ sudo umount /mnt
3. Run simulation.
$ qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1" -hda ~/qemu-vms/2014-01-07-wheezy-raspbian.img -redir tcp:5022::22
QEMU gives you a root shell, run:
$ fsck /dev/sda2
$ shutdown -r now
UPDATE: how to open ssh connection (see -redir option):
$ ssh -p 5022 pi@localhost
UPDATE: how expand free space:

1. Create /etc/udev/rules.d/90-qemu.rules with the following content and shutdown the system:
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"
2. Resize the image:
$ qemu-img resize /qemu-vms/2014-01-07-wheezy-raspbian.img +4G
3. Boot up your emulator again and do:

$ sudo ln -snf mmcblk0p2 /dev/root
$ sudo raspi-config

Choose the first option to resize your disk, and it will tell you to reboot.

UPDATE: update keyboard mappings if necessary:

$ sudo dpkg-reconfigure keyboard-configuration