Friday, December 17, 2010

QEMU/ARM hands-on (FOSS.IN) (Saleem Ansari)

This was the most interesting and useful session that I had in entire FOSS.IN. Above site will give details. However, I guess, there are some issues with instructions. For example, the kernel link is broken. But, it will work if you remove the .af from the url. Also, the image did not load the rootfs. I tried ext2fs instead of cpio and gzip and that loaded the image. Also, rcS is not present at the site. I wrote that from memory. Again, I seem to have missed something there. It fails with the message that "could not open initial console". I guess /dev/ttyX stuff might be missing. Will try to fix that later and post back here once I do that. Anyway, this was a enlightening talk and it now gives me enough confidence to try my own rootfs on different architecture. Many thanks to the presenter.

I fixed this stuff. For those who are interested, I am listing the important changes
0. The correct link for kernel is:
0.1 May be this was not needed. But, I did create a symlink from busybox to /init. Also, it only worked when I did a static build of busybox
1. Some device inodes were missing. Created /dev/{null,console,tty,tty0,tty1,tty2,tty3,tty4,tty5}
2. Created /etc/init.d/rcS and made it executable
mount -t proc proc /proc
mount -t sysfs sys /sys
/sbin/mdev -s
3. Most important of all, EABI support needs to be turned on in kernel. Else, nothing will work. Turn it on before compiling the kernel
4. The filesystem cannot be cpio. May be it can still work with a kernel config change. However, I tried with ext2fs and it worked perfectly well
4.1 To create a ext2fs,
dd if=/dev/zero of=root.fs bs=1M count=4
(As a side note, if you refer to the commands given in the above link, you will see bs=1. That is very slow)

mkfs -t ext2 root.fs
(Press 'y' for the question about root.fs not being a real device)

mkdir rootfs
mount -o loop root.fs rootfs
(Mount your new filesystem somewhere so that you can copy the contents to it)

(go to where your rootfs is)

tar c * | tar x -C /path/to/rootfs
(copy the contents to new your new filesystem)

umount /path/to/rootfs
(Now you can start using your root.fs just like rootfs.cpio.gz as described in the link at the top of this post and continue from mkimage part)
Thats all! you will have a bootable setup. I am thinking of creating a small script that will automate all these. Will post it here if I ever do that.
Update: I did make a script. Unfortunately, I was in office and our security policy does not allow me to upload that. Its like magic, u run it, have a coffee and when you come back,  you will see qemu running your own small Linux image :)

No comments: