ubuntu下使用qemu-system-arm模拟arm环境
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu下使用qemu-system-arm模拟arm环境相关的知识,希望对你有一定的参考价值。
转载请注明原文出处,http://www.cnblogs.com/flyingcloude/p/6992396.html
最近由于学习需要,开始搭建嵌入式开发环境,但苦于硬件平台还没有弄好,故先在ubuntu环境下进行模拟。
以下方法将在ubuntu10.10主机上,利用qemu-system-arm安装一个arm11的操作系统。系统采用nfs方式挂载文件系统,可以用来模拟arm11的运行环境。
安装qemu-system-arm
(qemu的使用情况在http://www.cnblogs.com/flyingcloude/archive/2012/10/18/2730052.html介绍过了)
sudo add-apt-repository ppa:linaro-maintainers/tools sudo apt-get update sudo apt-get install qemu-system
安装好后,可以执行以下命令查看版本
qemu-system-arm --version
编译arm11内核
1、创建文件夹~/arm/kernel,并切换工作目录
mkdir ~/arm mkdir ~/arm/kernel cd ~/arm/kernel
2、下载EABI的TAR包
wget https://sourcery.mentor.com/sgpp/lite/arm/portal/package8734/public/arm-none-eabi/arm-2011.03-42-arm-none-eabi-i686-pc-linux-gnu.tar.bz2 tar xjvf arm-2011.03-42-arm-none-eabi-i686-pc-linux-gnu.tar.bz2
3、下载、解压,为内核打上armv6支持的补丁
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.0.4.tar.bz2 tar -xvf linux-3.0.4.tar.bz2 wget http://thoronir.net/raspi-dev/linux-arm.patch patch -p1 -d linux-3.0.4/ < linux-arm.patch
4、设置内核编译选项
先安装ncurses
sudo apt-get install libncurses5-dev
cd linux-3.0.4 make ARCH=arm versatile_defconfig make ARCH=arm menuconfig
General Setup —>Cross-compiler tool prefix (We need to enter the path of the toolchain followed by ‘/bin/arm-none-eabi-’)
在我的电脑上是/usr/local/arm-2011.03/bin/arm-none-eabi-
System Type —> [*] Support ARM V6 processor [*] ARM errata: Invalidation of the Instruction Cache operation can fail
Kernel Features —> [*] Use ARM EABI to compile the kernel [*] Allow old ABI binaries to run with this kernel
Bus Support —> [*] PCI Support
Device Drivers —>SCSI Device Support —> [*] SCSI Device Support [*] SCSI Disk Support [*] SCSI CDROM support [*] SCSI low-lever drivers —> [*] SYM53C8XX Version 2 SCSI support Device Drivers —>Generic Driver Options—> [*] Maintain a devtmpfs filesystem to mount at /dev [*] Automount devtmpfs at /dev, after the kernel mounted the root Device Drivers —>Input device support—> [*] Event interface Device Drivers —> [*] Real Time Clock ->
File systems —>Pseudo filesystems—> [*] Virtual memory file system support (former shm fs)
5、编译内核
make ARCH=arm
制作文件系统
1、新建文件系统目标并下载文件
cd ~/arm mkdir debian_armel_squeeze sudo debootstrap --foreign --arch armel squeeze debian_armel_squeeze http://ftp.tw.debian.org/debian
如果debootstrap没有安装的话,先进行安装
sudo apt-get install debootstrap
2、安装内核模块
cd linux-3.0.4 sudo make ARCH=arm INSTALL_MOD_PATH=../debian_armel_squeeze modules_install
3、复制zImage
cd ~/arm cp kernel/linux-3.0.4/arch/arm/boot/zImage .
配置NFS服务
1、如果没有安装NFS,先安装NFS软件包
sudo apt-get install nfs-kernel-server nfs-common
2、添加服务路径、在配置文件中加入一行
/home/ubuntu/arm/debian_armel_squeeze *(rw,sync,no_root_squash)
3、保存并重启nfs服务
sudo service nfs-kernel-server restart
网络配置
配置网络后,主机ubuntu和虚拟的arm11系统就在同一网段,以bridge方式连接.如果您的计算机是在路由器下面,配置网络完成之后,虚拟机arm11系统和ubuntu均能访问外网.
1、打开TUN/TAP选项
1、查看选项是否已经打开
grep CONFIG_TUN= /boot/config-2.6.35-32-generic
2、查看/dev/net/tun是否存在,如果不存在,可以创建它
mknod /dev/net/tun c 10 200
2、安装桥接工具
sudo apt-get install bridge-utils
3、初始化arm11系统
1、初始化网络
sudo brctl addbr br0 sudo ifconfig eth0 0.0.0.0 promisc up sudo brctl addif br0 eth0 sudo dhclient br0 sudo iptables -F FORWARD
2、启动arm11系统
cd ~/arm dd if=/dev/zero of=rootfs.ext2 count=6M mkfs.ext2 rootfs.ext2 mkdir mnt sudo mount -o loop rootfs.ext2 mnt sudo cp debian_armel_squeeze/* mnt -a sudo umount mnt
sudo qemu-system-arm -M versatilepb -cpu arm1176 -m 256 -hda rootfs.ext2 -kernel zImage -append "root=/dev/sda rw init=/bin/bash" -serial stdio
系统启动成功后,出现shell界面,运行以下命令
mount /proc /proc -t /proc ./debootstrap/debootstrap --second-stage
设置主机名和密码
printf "auto eth0\\niface eth0 inet dhcp\\n" >> etc/network/interfaces echo "arm-debian" > /etc/hostname passwd
到此,系统已经完成,停止qemu重新启动系统
sudo qemu-system-arm -M versatilepb -cpu arm1176 -m 256 -hda rootfs.ext2 -kernel zImage -append "root=/dev/sda" -serial stdio
参考:http://www.cnx-software.com/2011/10/18/raspberry-pi-emulator-in-ubuntu-with-qemu/
转载请注明原文出处,http://www.cnblogs.com/flyingcloude/p/6992396.html
以上是关于ubuntu下使用qemu-system-arm模拟arm环境的主要内容,如果未能解决你的问题,请参考以下文章
libvirt qemu-system-arm,错误:XML错误:没有可用的PCI总线