曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 13292|回复: 0
打印 上一主题 下一主题

QEMU 仿真器的安装与使用

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34387
跳转到指定楼层
楼主
发表于 2011-1-15 17:11:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
QEMU 的下载地址为:
http://wiki.qemu.org/Download
这里可以下载到源码和二进制安装文件,既有 Linux 版本也有 Windows 版本,因 QEMU 具有强烈的 Linux 倾向,所以建议下载源码然后在 Linux 上进行编译安装。
目前最新版本是 0.13,它支持 GCC-4.3.2 的编译。但是如果选择较老版本的 QEMU (如 0.9 版本),那么可能需要安装较老版本的 GCC,如 GCC-3.4 。

安装过程很简单,只需要 3 步:
$ configure
$ make
$ make install

安装好后,我们开始初步的使用它。由于 QEMU 可以模拟许多平台,比如 ARM,MIPS,X86 等。这里,让 QEMU 模拟 ARM 的环境。为了方便起见,仍然是从上面的下载连接下载 ARM 镜像文件包 -- arm-test-0.2.tar.gz 。,然后解压缩它:
$ tar xvzf arm-test-0.2.tar.gz
arm-test/
arm-test/arm_root.img
arm-test/README
arm-test/zImage.integrator
解压缩后,一共有 3 个文件,一个 REAME 文件;一个 zImage.integrator 文件,它是个内核文件;一个 arm_root.img,它是一个 initrd 根文件系统。

下面开始使用 QEMU 加载这个系统:
$ cd arm-test/
$ ../qemu-0.13.0/arm-softmmu/qemu-system-arm -kernel zImage.integrator -initrd arm_root.img -nographic -append "console=ttyAMA0"
Uncompressing Linux.......................................................................... done, booting the kernel.
Linux version 2.6.17-rc3 (paul@wren) (gcc version 4.1.0 (CodeSourcery ARM)) #53 Thu May 4 15:05:18 BST 2006
CPU: ARM926EJ-Sid(wb) [41069265] revision 5 (ARMv5TEJ)
Machine: ARM-IntegratorCP
Memory policy: ECC disabled, Data cache writeback
CPU0: D VIVT write-through cache
CPU0: I cache: 4096 bytes, associativity 4, 32 byte lines, 32 sets
CPU0: D cache: 65536 bytes, associativity 4, 32 byte lines, 512 sets
Built 1 zonelists
Kernel command line: console=ttyAMA0
PID hash table entries: 1024 (order: 10, 4096 bytes)
Console: colour dummy device 80x30
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
Memory: 128MB = 128MB total
Memory: 125184KB available (1928K code, 388K data, 104K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
checking if image is initramfs... it is
Freeing initrd memory: 2129K
NET: Registered protocol family 16
NetWinder Floating Point Emulator V0.97 (double precision)
Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
Initializing Cryptographic API
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
CLCD: Integrator/CP hardware, VGA display
Clock CLCDCLK: setting VCO reg params: S=1 R=39 V=35
Console: switching to colour frame buffer device 80x30
Serial: AMBA PL011 UART driver
mb:16: ttyAMA0 at MMIO 0x16000000 (irq = 1) is a AMBA/PL011
mb:17: ttyAMA1 at MMIO 0x17000000 (irq = 2) is a AMBA/PL011
RAMDISK driver initialized: 16 RAM disks of 8192K size 1024 blocksize
loop: loaded (max 8 devices)
nbd: registered device at major 43
smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <nico@cam.org>
eth0: SMC91C11xFD (rev 1) at c8814000 IRQ 27 [nowait]
eth0: Ethernet addr: 52:54:00:12:34:56
mice: PS/2 mouse device common for all mice
mmc0: MMCI rev 0 cfg 00 at 0x1c000000 irq 23,24
Green LED off
input: AT Raw Set 2 keyboard as /class/input/input0
input: ImExPS/2 Generic Explorer Mouse as /class/input/input1
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 4096 bind 2048)
TCP reno registered
IPv4 over IPv4 tunneling driver
GRE over IPv4 tunneling driver
TCP bic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
802.1Q VLAN Support v1.8 Ben Greear <greearb@candelatech.com>
All bugs added by David S. Miller <davem@redhat.com>
VFP support v0.3: implementor 41 architecture 1 part 10 variant 9 rev 0
eth0: link up
rdate: Unable to connect to remote host (10.0.2.2): Connection refused

This root FS contains most basic linux utilities (implemented with busybox)
and the Lynx web browser.

Kernel config is available through /proc/config.gz

Log in as root with no password.
qemu login: root

使用没有密码的 root 登录进去看看系统信息:
login[725]: root login  on `ttyAMA0'



BusyBox v1.1.2 (2006.05.04-15:30+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

# uname -r
2.6.17-rc3
# cat /proc/cpuinfo
Processor    : ARM926EJ-Sid(wb) rev 5 (v5l)
BogoMIPS    : 280.98
Features    : swp half thumb fastmult edsp java
CPU implementer    : 0x41
CPU architecture: 5TEJ
CPU variant    : 0x0
CPU part    : 0x926
CPU revision    : 5
Cache type    : write-through
Cache clean    : not required
Cache lockdown    : not supported
Cache format    : Harvard
I size        : 4096
I assoc        : 4
I line length    : 32
I sets        : 32
D size        : 65536
D assoc        : 4
D line length    : 32
D sets        : 512

Hardware    : ARM-IntegratorCP
Revision    : 0000
Serial        : 0000000000000000

相当简单的安装和使用。

下面介绍一下 QEMU 内核启动参数:
-kernel <kernel image> : -kernel 参数后面接内核映像文件名,如果不指定路径,则在当前目录下寻找。

-initrd <initial ram disk image> : 需要为内核加在的初始 RAM 磁盘,里面包含文件系统。

-nographic : 由于这里仿真的目标板没有图形设备,所以我们也没必要让 QEMU 仿真图形设备,所以这里使用此参数。

-append <parameters> : 一般的,我们在启动 linux 时,我们有时需要给内核传递一些参数,比如 init=/etc/init 指定内核启动后,最后将从运行位于 /etc 目录下的 init 文件 (该文件默认位于 /sbin/ 目录下)。这里,我们设置 console=ttyAMA0 表示内核使用 /dev/ttyAMA0 设备作为控制台,该设备由 QEMU 创建,这样目标板就有了一个作为终端的伪串行设备。

退出 QEMU 操作为:Ctrl + A ,然后按下 X 键。注意,它不会提醒你是否要退出,而是直接退出,所以操作时要小心。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2024-5-28 20:41 , Processed in 0.073137 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表