qemu 交叉编译arm内核,制作文件系统及启动内核笔记

来源:互联网 发布:淘宝上zara是真的吗 编辑:程序博客网 时间:2024/04/19 05:20

Reference:
http://en.gentoo-wiki.com/wiki/QEmu
http://www.linuxeden.com/html/develop/20100820/104409.html
http://balau82.wordpress.com/2010/03/27/busybox-for-arm-on-qemu/

I use qmeu-system-arm to emulate versatilepb , so I need crosscompile tool for
arm.
========================================================
1,down load cross compile tool :gnueabi.
#wget http://www.codesourcery.com/sgpp/lite/arm/portal/package6490/public/arm-none-linux-gnueabi/arm-2010q1-202-arm-none-linux-gnueabi.bin
# chmod +x arm-2010q1-202-arm-none-linux-gnueabi.bin
# ./arm-2010q1-202-arm-none-linux-gnueabi.bin
then export your cross compile install path to PATH.such as adding the
following lines into /etc/profile
export PATH=/mnt/sdb1/eabi/code/bin:$PATH

last do:
source /etc/profile
========================================================

2, compile kernel
2.1 download kenenr org.
2.1 compile it.
#make ARCH=arm versatile_defconfig
#make ARCH=arm menuconfig
Select EABI support in Kernel Featurer
#make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- all


=========================================================================================================================================

3,use busybox to make filesystem.

3.1$ wget http://busybox.net/downloads/busybox-1.17.1.tar.bz2
3.2$ tar xjf busybox-1.17.1.tar.bz2
3.3$ cd busybox-1.17.1
3.4$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- defconfig
3.5$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- install

Then there will be a minimal root filesytem in busybox/_install which does not
include share library.

Since command ps and mount need /proc and /sys, so you should make proc and
sys work.
$cd busybox/_install
$mkdir proc sys dev etc etc/init.d
$vim etc/init.d/rcS
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s
$ chmod +x _install/etc/init.d/rcS
We can now create a root filesystem image using the cpio tool, and in order to
compact the filesystem even more, we can run gzip on it to create a compressed
image:
$ cd busybox/_install
$ find . | cpio -o --format=newc > ../rootfs.img
$ cd ..
$ gzip -c rootfs.img > rootfs.img.gz

4, boot your virbutal machine.
$qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img.gz -append "root=/dev/ram rdinit=/sbin/init"

The cross compile tool and busybox I put them under tools.

NOTE:you should first compile your program in host machine , then add them
into the filesystem, redo the filesystem, then boot the machine,you can see
you program on virtual machine.

If you want use gdb to debug you program. see:
http://www.linuxeden.com/html/develop/20100820/104409.html
http://balau82.wordpress.com/2010/08/17/debugging-arm-programs-inside-qemu/#about

上面是我刚开始做的时候写的一些笔记。

我对文件系统做了细微的调整,主要是在dev下新建了几个节点。

#ls -l

crw-r--r-- 1 root root   5,  1  6月  8 09:53 console

brw-r--r-- 1 root root  31,  0  6月  8 09:53 mtdblock0

brw-r--r-- 1 root root  31,  1  6月  8 09:53 mtdblock1

brw-r--r-- 1 root root  31,  2  6月  8 09:53 mtdblock2

crw-r--r-- 1 root root   1,  3  6月  8 09:53 null

drwxr-xr-x 2 root root    4096  6月  9 09:10 pts

crw-r--r-- 1 root root 204, 64  6月  8 09:53 ttySAC0

 

然后在rcs里面改成以下设置;

#!/bin/sh

mount -t proc none /proc

mount -t sysfs none /sys

mount -t devpts  none /dev/pts

/sbin/mdev -s

其他的都一样。这样就内核和文件系统都做好了。

原创粉丝点击