Table of contents

Introduction

This was not trivial task to me. As usual google is your friend and RTFM works. First we will set tftp which we use to download modified kernel for U-Boot. Second I will show how to setup bridged network for QEMU needs and finally we will perform some basic test of our setup. Let’s go.

Setup tftpd

First install:

Make sure that /srv/tftp is writable for your user. If directory doesn’t exist create it and give needed privileges. If you want to change some server options edit /etc/inetd.conf. Copy or link our kernel to tftp server directory.

Verify if everything works correctly:

Check if kernel file is in current directory. If yes than you tftp server is configured correctly, if not then google or ask me a question in comments section. Note: For Ubuntu follow instructions from here.

QEMU networking

Update: For Ubuntu users please read this section

I mixed this BKM and few other resources that I found in the net. Setting up network depend a lot on your configuration. I will briefly describe my situation. It is quite possible that this won’t fit yours.

I’ve eth0 with ip 10.0.2.15. What I want to do is create another interface tap0 and bridge br0 that will connect eth0 and tap0. To do this I need few things:

  • brctl is provided in Debian by bridge-utils

  • check if TUN module was installed

you should get y or m, if it is m than modprobe tun:

  • create tun device

  • update /etc/network/interfaces:

  • use /etc/qemu-ifup script to bring up your network:

Give executable permissions for this file:

Restart networking services locally:

This should prepare you environment for tftp booting in qemu.

Ubuntu issues

I had experienced few problems with my Ubuntu 12.04.

  • First thing was defect that cause looping u-boot during emulation in qemu-system-arm. I checked latest qemu and version delivered in distro repository but qemu wasn’t issue. I tried debug problem with gdb and qemu -s -S switches and find out that u-boot crashes at __udivsi3 instruction in serial_init. I tried to google this issue but found only one comment about this on Balau blog: {% blockquote [Grant Likely]%} For anyone trying to reproduce this, at least on a recent Ubuntu host, you may need to pass ?-cpu all? or ?-cpu cortex-a8? to qemu. The libgcc that gets linked to u-boot appears to be compiled with thumb2 instructions which are not implemented in the Versatile cpu. I don?t get any u-boot console output without this flag, and using gdb I can see that the cpu takes an exception during __udivsi3() called from serial_init(). {% endblockquote %} Problem is at least 2-years old and still occurs. Unfortunately Grant’s tricks didn’t help. I move to toolchain built by my own and problem was fixed. So the moral of the story is: DO NOT USE TOOLCHAIN PROVIDED BY UBUNTU at least in 12.04.

  • Second thing also involve a lot of debugging time and when I found workaround it was accidentally. I saw that using procedure correct for Debian on Ubuntu I was unable to obtain any packet inside U-Boot. Network traffic analysis show that U-Boot correctly send DHCP discovery and server reply with DHCP offer, but bootloader behaves like no packet was received. Static configuration also didn’t work. Finally I get to information how to capture traffic from inside of emulated setup (parameter -net dump,file=/path/to/file.pcap do the thing). Surprisingly for some reason adding dump param fix problem and U-Boot received DHCP Offer and ACK. I will try to narrow down this problem for further reading please take a look qemu and u-boot mailing list thread.

Verify all components of Virtual Development Platform

So right now we should have built kernel uImage, U-Boot image, configured qemu network and tftp server. With all this components we can verify if our kernel booting on emulated versatilepb.

Run your qemu with network using U-Boot image as a kernel.

NOTE: We want to use u-boot file instead of u-boot.bin. First is ELF binary image and second is raw binary. Raw binary image can be used with -bios parameter for qemu. If you try to give raw binary as a kernel parameter it will result with error:

NOTE 2: We have to specify versatilepb machine. If we forget it we will get error:

Right now we have u-boot booted. Let’s set ip addresses to boot uImage from our tftp server. For verification needs we don’t want to autoload downloaded image, so we disable this through environment variable.

Set addresses according to your configuration. For some reason I was unable to use u-boot dhcp feature. It assign me address that exist in the network.

We can take a close look on out downloaded image with iminfo command. tftpboot and iminfo should looks like that:

So, that what we want to see. Pretty new kernel 3.9.0-rc8 compiled as ARM image. We can try to boot it but we will end with kernel panic because lack of filesystem.

NOTE 3: If you want to see anything after booting this image with bootm you have to pass to kernel additional boot argument with serial device that should be used as a console. Before bootm set:

You should get something similar to below log:

This is expected result.

What next ?

We happily built basic virtual development, what we need right now is some initial filesystem.