Wednesday, 5 June 2013

Minix on Linaro QEMU

Previously, I had written several posts about running Minix on the BeagleBone Black (Parts: 1, 2, 3). While running an operating system on real hardware is usually preferable to running inside an emulator, sometimes you want to try something out quickly without waiting 10 minutes for an image to get written to an SD card or maybe you don't have a specific piece of hardware in hand. This is where an emulator comes in handy. Luckily, there is a not-for-profit engineering organization at Linaro.org that helps out the open source ARM community. They've got a customized version of QEMU which does a decent job of emulating the BeagleBoard-xM. This guide will step you through building Linaro QEMU, building Minix, and booting the system.

The first step is to get the source code for the Linaro version of QEMU, build it, and install it. The commands below can be executed as a normal user and install QEMU to the 'qemu' directory under your home directory. You may have to adjust the path to python for your operating system. If you are missing any required libraries or tools, the configure script will let you know. The instructions suggest a specific revision to ensure that you get the best results with Minix. Don't ignore that suggestion.

cd $HOME
git clone git://git.linaro.org/qemu/qemu-linaro.git
cd qemu-linaro
git checkout 72f7eb07b611766298fe2dc140533a0a6256b054
./configure --target-list=arm-softmmu \
--prefix=$HOME/qemu \
--python=/usr/bin/python2.7

make
make install
Once you have the emulator software installed, you need to create an SD card image file containing the Minix base system. These commands will walk you through checking out my code, configuring the build, and building the whole system. Again, if you need any libraries or tools, the arm_sdimage.sh script will let you know about it.

cd $HOME
git clone git://github.com/tcort/minix-i2c.git
cd minix-i2c
git checkout i2c
echo "BASE_URL=http://www.minix3.org/arm/beagleboard-xm" > .settings
echo "FLAG=-DDM37XX" >> .settings
echo "CONSOLE=tty02" >> .settings
./releasetools/arm_sdimage.sh

Now, if everything was successful, you should have the emulator installed and a complete Minix operating system image ready to boot. The next step is to fire up the emulator with it pointed at the SD card image file.

cd $HOME/minix-i2c && $HOME/qemu/bin/qemu-system-arm \
-M beaglexm -drive \
if=sd,cache=writeback,file=minix_arm_sd.img  \
-clock unix -serial stdio -device usb-kbd \
-device usb-mouse -usb
That should boot up Minix and present you with a login prompt. The default login is "root" with no password. That will give you a shell where you can issue commands. As the project progresses, I'll be making posts explaining how to get started with i2c on Minix. I will also write about running Minix on an actual BealgeBoard-xM.

When you're done, you can issue the `halt` command. Minix will stop itself and print a message saying that it's okay to turn off the computer. At this point, you can press Ctrl+C to terminate qemu.

5 comments:

  1. What OS/tool-chain are you using? I'm using Ubuntu/gcc, and got the following error while cross compiling MINIX3. Note that the faulting array is only of size 128:

    typedef union {
    __int64_t __mbstateL; /* for alignment */
    char __mbstate8[128];
    } __mbstate_t;


    # create libc/ucontextoffsets.h
    cat /home/chu7/temp/minix-i2c/lib/libc/arch/arm/sys-minix/ucontextoffsets.cf | /home/chu7/temp/minix-i2c/../obj.evbearm-el/tooldir.Linux-3.8.0-22-generic-i686/bin/nbgenassym -- /home/chu7/temp/minix-i2c/../obj.evbearm-el/tooldir.Linux-3.8.0-22-generic-i686/bin/arm-elf32-minix-gcc -O2 -std=gnu99 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-sign-compare -Wno-traditional -Wreturn-type -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -Wextra -Wno-unused-parameter -Wno-sign-compare -Wold-style-definition -Wsign-compare -Wformat=2 -Wno-format-zero-length -DDM37XX --sysroot=/home/chu7/temp/minix-i2c/../obj.evbearm-el/destdir.evbearm-el -D_LIBC -DNLS -I/home/chu7/temp/minix-i2c/lib/libc/include -I/home/chu7/temp/minix-i2c/lib/libc -I. -DSOFTFLOAT -I/home/chu7/temp/minix-i2c/lib/libc/arch/arm/softfloat -I/home/chu7/temp/minix-i2c/lib/libc/softfloat -DSOFTFLOAT_FOR_GCC -I/home/chu7/temp/minix-i2c/sys -D__HAVE_ASM_ATOMIC_CAS_UP -I/home/chu7/temp/minix-i2c/lib/libc/../../common/lib/libc/quad -I/home/chu7/temp/minix-i2c/lib/libc/../../common/lib/libc/string -I/home/chu7/temp/minix-i2c/lib/libc/../../common/lib/libc/arch/arm/string -D__DBINTERFACE_PRIVATE -I/home/chu7/temp/minix-i2c/libexec/ld.elf_so -I/home/chu7/temp/minix-i2c/lib/libc/dlfcn -I/home/chu7/temp/minix-i2c/lib/libc/gdtoa -DNO_FENV_H -I/home/chu7/temp/minix-i2c/lib/libc/arch/arm/gdtoa -DWITH_RUNE -I/home/chu7/temp/minix-i2c/lib/libc -DPOSIX_MISTAKE -DCOMPAT__RES -DNEED_PSELECT -DWIDE_DOUBLE -DALL_STATE -DUSG_COMPAT -fno-builtin -Wall -Wno-sign-compare >MP && mv -f MP ucontextoffsets.h
    In file included from /home/chu7/temp/minix-i2c/sys/sys/types.h:51:0,
    from /home/chu7/temp/minix-i2c/../obj.evbearm-el/destdir.evbearm-el/usr/include/machine/multiboot.h:262,
    from /home/chu7/temp/minix-i2c/../obj.evbearm-el/destdir.evbearm-el/usr/include/minix/type.h:3,
    from /tmp/genassym.13671/assym.c:6:
    /home/chu7/temp/minix-i2c/sys/sys/ansi.h:62:7: error: size of array '__mbstate8' is too large

    ReplyDelete
  2. For the toolchain, I'm using Gentoo with glibc-2.15, gcc-4.6.3, and binutils-2.22 on an amd64 system.

    It looks like you're building on an x86 system. Unfortunately, cross building Minix/arm images from 32-bit systems isn't supported yet. Some patches are in the works, but more work remains on this front. Sorry I forgot to include a warning in the original post.

    ReplyDelete
  3. Will give it a try. Thanks for the pointer!

    ReplyDelete
  4. Hi Thomas,

    I am porting low level code to run on beagleboard and I thought to use board emulator qemu and use bootloader U-Boot. You are using u-boot.img from http://www.minix3.org/arm/beagleboard-xm/ as a bootloader in your project. Any chance you know who and how built this u-boot image?

    And another question. How confident you are in qemu emulation of this specific board? I mean CPU emulation is not enough, you are working with IO bus and you need exactly the same bus emulation as well. Can qemu provide such emulation?

    Thanks for sharing info and good luck with your project!
    Igor

    ReplyDelete
    Replies
    1. Hi Igor,

      I don't know the specific person who built it, but it was most likely one of the developers at VU ( http://www.vu,nl/ ). There are a few ways to get in contact with them to ask about the u-boot image. You could try the #minix and/or #minix-dev IRC channels on irc.freenode.net. Another place to ask is the Minix google group: http://groups.google.com/group/minix3

      I don't know exactly how well Linaro's QEMU emulates the BeagleBoard-xM because I haven't spent a lot of time with it yet. From the small experience that I have had with it, it seems to be okay but I've only really scratched the surface (at present my code just reads the I2C hardware revision from the I2C_REV register).

      Thomas

      Delete