Chinaunix首页 | 论坛 | 博客
  • 博客访问: 25607
  • 博文数量: 13
  • 博客积分: 305
  • 博客等级: 二等列兵
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-30 18:55
文章分类

全部博文(13)

文章存档

2012年(13)

我的朋友

分类: LINUX

2012-06-19 22:38:17

创建工作目录
mkdir -p ~/QEMU/Source


安装QEMU
//Ubuntu 12.04
sudo apt-get install qemu-system



下载源码
cd ~/QEMU/Source

//Sourcery G++
wget

//Linux
wget

//BusyBox
wget

//u-boot
wget ftp://ftp.denx.de/pub/u-boot/u-boot-2010.06.tar.bz2

//QEMU
wget



源码安装QEMU
sudo apt-get install zlib1g-dev
sudo apt-get install libglib2.0-dev
sudo apt-get install libsdl1.2-dev

cd ~/QEMU
tar xjvf Source/qemu-1.1.0-1.tar.bz2
mv qemu-1.1.0/ qemu
cd qemu
sudo ./configure --enable-sdl --disable-kvm --enable-debug --target-list=arm-softmmu --prefix=/usr/local
sudo make
sudo make install




安装ToolChain
cd ~/QEMU
sudo tar xjvf Source/arm-2011.03-41-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 -C /opt

cat << EOF > build.env
export ARCH=arm
export CROSS_COMPILE=arm-none-linux-gnueabi-
export PATH=\$PATH:/opt/arm-2011.09/bin
EOF




------------------这个可以不关心-----------------------------
//有些目标机需要安装/sysroot
cd ~
mkdir 00Software
cd 00Software
cp -r /opt/arm-2011.03/arm-none-linux-gnueabi/libc .
mv libc sysroot
//如果不需要armv4t和thumb2,可以删除以节省空间
cd sysroot
rm -r armv4t
rm -r thumb2
------------------这个可以不关心-----------------------------


编译u-boot
cd ~/QEMU
tar xjvf Source/u-boot-2010.06.tar.bz2
mv u-boot-2010.06/ u-boot

source build.env

cd u-boot
make versatilepb_config
make all

cp u-boot.bin ~/QEMU/


//QEMU仿真
qemu-system-arm -M versatilepb -nographic -kernel u-boot.bin

(hit “Ctrl-a” and then “x” to exit QEMU)



解压Linux
cd ~/QEMU
tar xjvf Source/linux-2.6.38.6.tar.bz2
mv linux-2.6.38.6 linux

source build.env

cd linux
make versatile_defconfig
make menuconfig

Kernel Features ---> Use the ARM EABI to compile the kernel
Kernel Features ---> Allow old ABI binaries to run with this kernel (EXPERIMENTAL)
Device Drivers ----> Block devices ---> (1)     Default number of RAM disks
Device Drivers ----> Block devices ---> (16384)  Default RAM disk size (kbytes)
File systems ------> Second extended fs support

make zImage
cp arch/arm/boot/zImage ~/QEMU/

内核测试
cd ~/QEMU
mkdir initramfs
cd initramfs
cat << EOF > init.c
#include
#include
int main(void)
{
    printf("hello arm\n");
    while(1);
    return 0;
}
EOF

//生成initramfs。
arm-none-linux-gnueabi-gcc -static -o init init.c
rm init.c
find . | cpio -o -H newc | gzip > ~/QEMU/initrd

//加载内核
cd ~/QEMU
qemu-system-arm -M versatilepb -kernel zImage -initrd initrd -m 256M


制作busybox
cd ~/QEMU
source build.env

tar xjvf Source/busybox-1.18.4.tar.bz2
mv busybox-1.18.4 busybox

cd busybox

make defconfig
make menuconfig

Busybox Settings --> Build Options --> Build BusyBox as a static binary (no shared libs)

make
make install


制作rootfs(initramfs)
cd ~/QEMU
mkdir rootfs
cd rootfs/

cp -av ~/QEMU/busybox/_install/* .
mkdir -p dev/pts proc root sys mnt tmp etc/init.d

sudo mknod dev/console c 5 1
sudo mknod dev/null c 1 3
sudo mknod dev/zero c 5 1
sudo mknod dev/ttyAMA0 c 204 64

cat << EOF > etc/group
root:x:0:
EOF

//只有root用户
cat << EOF > etc/passwd
root::0:0:root:/root:/bin/sh
EOF

cat << EOF > etc/fstab
proc /proc proc defaults 0 0
devpts /dev/pts devpts mode=0622 0 0
syspts /sys sysfs defaults
#tmpfs /tmp tmpfs defaults 0 0
EOF

cat << EOF > etc/init.d/rcS
#This is the firstscript called by init process
mount -a
#/sbin/mdev -s
hostname qemu
#/bin/sh
EOF

cat << EOF > etc/inittab
::sysinit:/etc/init.d/rcS
::respawn:/sbin/getty -L ttyAMA0 115200 xterm
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a
EOF

chmod +x etc/init.d/rcS

find . | cpio -o -H newc | gzip > ~/QEMU/rootfs.img.gz


//添加一个脚本mkrootfs.sh,通过". mkrootfs.sh"执行
cat << EOF > mkrootfs.sh
#!/bin/bash
find . | cpio -o -H newc | gzip > ~/QEMU/rootfs.img.gz
EOF



制作rootfs(initrd, ext2)
//大小要与linux ramdisk配置的一致
cd ~/QEMU
dd if=/dev/zero of=rootfs.img bs=1k count=16384
mkfs.ext2 -F rootfs.img
sudo mount -o loop rootfs.img /mnt


sudo cp -avr rootfs/* /mnt/

sudo umount /mnt
gzip -9vc rootfs.img > ~/QEMU/rootfs.img.gz


运行QEMU
qemu-system-arm -M versatilepb -s -m 256M -serial stdio -kernel zImage -initrd rootfs.img.gz -append "root=/dev/ram rw rdinit=/linuxrc mem=256M console=ttyAMA0"


//添加执行脚本startQEMU.sh,通过". startQEMU.sh"执行
cat << EOF > startQEMU.sh
#!/bin/bash
qemu-system-arm -M versatilepb -s -m 256M -serial stdio -kernel zImage -initrd rootfs.img.gz -append "root=/dev/ram rw rdinit=/linuxrc mem=256M console=ttyAMA0"
EOF



阅读(1197) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~