准备工作:
1)qemu,这个不需要交叉编译,一下假设你已经安装了qemu,建议安装后阅读qemu的readme
http://www.qemu.org/qemu-doc.html
qemu的网络功能比较复杂,这里有一个howto
http://www.h7.dion.ne.jp/~qemu-win/HowToNetwork-en.html
注意qemu模拟arm系统的时候支持有限的几个开发板,这里选ARM Integrator/CP board
ARM System emulator
Use the executable ‘qemu-system-arm’ to simulate a ARM machine. The ARM Integrator/CP board
is emulated with the following devices:
* - ARM926E, ARM1026E, ARM946E, ARM1136 or Cortex-A8 CPU
* - Two PL011 UARTs
* - SMC 91c111 Ethernet adapter
* - PL110 LCD controller
* - PL050 KMI with PS/2 keyboard and mouse.
* - PL181 MultiMedia Card Interface with SD card.
2)交叉编译工具,可以自己弄一个,也可以用工具/crosstool/crosstool-ng/builtroot/scratchbox,这里用编译好的Sourcery G++ Lite 2009q3-67
Sourcery G++ For ARM有三个不同的平台:
ARM EABI:适合裸机,bootloader:Newlib C Library
RTOS systems or "bare metal" systems where no operating system is present. These toolchains should not be used to build Linux kernels or applications.
ARM GNU/LINUX:kernel and applications:GNU C Library
Systems running "full" Linux, i.e., Linux on CPUs with an MMU. Use Sourcery G++ to build both the Linux kernel and applications.
ARM UCLINUX:uClinux kernel and applications:uClibc C Library
Systems running uClinux, i.e. Linux on CPUs without an MMU. Use Sourcery G++ to build both the uClinux kernel and applications.
注意以上只有ARM UCLINUX是uclib,需要uclib的交叉编译工具同志只好自立更生自己构建一个了。
3)下载linux-2.6.30源码
4)下载busybox-1.15.2源码
/*************************************************************************************************************************************************************************/
开始动手
1)编译kernel
先修改makefile
ARCH ?= arm
CROSS_COMPILE ?=arm-none-linux-gnueabi-
$make mrproper
$make integrator_defconfig
$make gconfig
1.General setup里面选Initial RAM filesystem
2.System type里面ARM system type选Integrator
3.Integrator Options选Support Integrator/CP platform
4.Processor Type 选上Support ARM926T processor
5.Kernel Features选Use the ARM EABI to compile the kernel
6.Floating point emulation里面必须至少选一个
7.Device Driver里面Character devices/Serial drivers选上
ARM AMBA PL011 serial port support
Support for console on AMBA serial port
8.Graphics support/Support for frame buffer devices要选上
Graphics support/Console display driver support里面要去掉VGA text console,选上
Framebuffer Console support
9.File systems/Network File Systems/Network client support/选上version3/version4
选上Root file system on NFS ROOT_NFS
10.Networking support NET/Networking options/TCP/IP networking INET
IP: kernel level autoconfiguration IP_PNP
11.Device Drivers/Network device support NETDEVICES
Universal TUN/TAP device driver support TUN
12.Ethernet (10 or 100Mbit) NET_ETHERNET
SMC 91C9x/91C1xxx support SMC91X选上,不然...
保存config后
$make all
得到arch/arm/boot/zImage
2)制作rootfs
修改busybox的makefile
ARCH ?= arm
CROSS_COMPILE ?=arm-none-linux-gnueabi-
$make menuconfig
enable:busybox settings->>build options->>build busybox as a static binary(no share libs)
enable:busybox settings->>installation options->>dont use /usr
enable:Networking Utilities->>Support RPC services
$make
$make install
进入../busybox-1.15.2/_install目录
$mkdir dev etc etc/init.d root sys proc tmp
$cd dev
$sudo mknod console c 5 1
$sudo mknod null c 1 3
$sudo mknod ttyAMA0 c 204 64
然后进入etc目录,创建group,inittab,passwd三个文件
#group:
root:x:0:
#inittab:
::sysinit:/etc/init.d/rcS
::respawn:/sbin/getty -L ttyAMA0 115200 xterm
#passwd:
root::0:0:root:/root:/bin/sh
最后进入/etc/init.d目录,创建rcS文件
#rcS:
#! /bin/sh
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
hostname qemu
/bin/sh
确定rootfs的位置,由于_install目录在重新编译busybox时候清空,先将rootfs拷贝至其他位置
$sudo cp -a <busybox>/_install <your rootfs>
3)配置nfs
假设你已经安装了nfs软件
新增/etc/qemu-ifup,它是qemu执行指定网络时候,会首先执行这个脚本,qemu的vlan有两种模式,详见qemu readme,我们现在只需要target连接到host,不
需要连接到internet。
panasonic@linux-tricy:~/桌面> cat /etc/qemu-ifup
#!/bin/sh
/sbin/ifconfig $1 192.168.0.1 promisc up
然后把脚本修改成可执行的
$sudo chmod u+x /etc/qemu-ifup
将rootfs设置到nfs共享目录
panasonic@linux-tricy:~/桌面> cat /etc/exports
/home/panasonic/rootfs 192.168.0.2(rw,no_root_squash,async,no_subtree_check)
设置/etc/hosts.allow
nfsd:192.168.0.2
portmap:192.168.0.2
mountd:192.168.0.2
lockd:192.168.0.2
statd:192.168.0.2
rquotad:192.168.0.2
注意:SUSE linux 防火墙设置
1关闭防火墙
2接口->自定义
设备Qemu 接口 tap0 配置区域为内部区域
3伪装->掩蔽网络 打勾
4新建/etc/sysconfig/network/ifcfg-tap0:
BOOTPROTO='static'
BROADCAST=''
ETHTOOL_OPTIONS=''
IPADDR='192.168.0.1'
MTU=''
NAME='Qemu'
NETMASK='255.255.255.0'
NETWORK=''
REMOTE_IPADDR=''
STARTMODE='auto'
UNIQUE=''
USERCONTROL='no'
重新启动nfs服务,然后可以简单的测试nfs服务是否配置成功
panasonic@linux-tricy:~/桌面> sudo mount -t nfs localhost:/home/panasonic/rootfs/ /mnt
root's password:
mount.nfs: mount to NFS server 'localhost:/home/panasonic/rootfs/' failed: RPC Error: Program not registered
panasonic@linux-tricy:~/桌面> sudo mount -t nfs localhost:/home/panasonic/rootfs/ /mnt
panasonic@linux-tricy:~/桌面> ls /mnt
bin dev etc linuxrc proc root sbin sys tmp
4)使用qemu的网络之前,需要加载虚拟网卡的模块tun
linux-tricy:/home/panasonic/桌面 # modprobe tun
linux-tricy:/home/panasonic/桌面 # lsmod
Module Size Used by
tun 16416 0
5)建立qemu启动脚本,可以少打几个字...
#!/bin/sh
qemu-system-arm -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=/etc/qemu-ifup -nographic \
-kernel <>/linux-2.6.30/arch/arm/boot/zImage \
-append "console=ttyAMA0 root="/dev/nfs" nfsroot="192".168.0.1:/home/panasonic/rootfs/,rsize=32768,wsize=32768,timeo=14,nfsvers=3 rw \ ip="192".168.0.2:192.168.0.1::255.255.255.0"
参数解析:
-net nic,model is used to set the model of the network card. ne2k_pci is a default.
tap:
QEMU adds a virtual network device on your host (called tapN), and you can then configure it as if it was a real ethernet card.
VLANs:
QEMU simulates several VLANs. A VLAN can be symbolised as a virtual connection between several network devices. These devices can be for example QEMU virtual Ethernet cards or virtual Host ethernet devices (TAP devices).
-nographic:
Normally, QEMU uses SDL to display the VGA output. With this option, you can totally disable graphical output so that QEMU is a simple command line application. The emulated serial port is redirected on the console. Therefore, you can still use QEMU to debug a Linux kernel with a serial console.
-kernel bzImage’
Use bzImage as kernel image.
‘-append cmdline’
Use cmdline as kernel command line
nfs选项中,rsize=32768,wsize=32768,timeo=14,nfsvers=3,可以改善网络的传输反应
退出qemu之后,最好killall qemu-system-arm,然后reset终端。
linux-tricy:/home/panasonic/桌面 # ./start-qemu
Starting Firewall Initialization (phase 2 of 2) done
Uncompressing Linux....................................................................................................... done, booting the kernel.
Linux version 2.6.30 (panasonic@linux-tricy) (gcc version 4.4.1 (Sourcery G++ Lite 2009q3-67) ) #4 Mon Dec 7 09:41:15 CST 2009
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr="00093177"
CPU: VIVT data cache, VIVT instruction cache
Machine: ARM-IntegratorCP
Memory policy: ECC disabled, Data cache writeback
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512
Kernel command line: console="ttyAMA0" root="/dev/nfs" nfsroot="192".168.0.1:/home/panasonic/rootfs/,rsize=32768,wsize=32768,timeo=14,nfsvers=3 rw ip="192".168.0.2:192.168.0.1::255.255.255.0
NR_IRQS:47
PID hash table entries: 512 (order: 9, 2048 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: 126392KB available (2848K code, 291K data, 104K init, 0K highmem)
SLUB: Genslabs="11", HWalign="32", Order="0-3", MinObjects="0", CPUs="1", Nodes="1"
Calibrating delay loop... 276.88 BogoMIPS (lpj=1384448)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 520 bytes
NET: Registered protocol family 16
bio: create slab <bio-0> at 0
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 4096 (order: 3, 32768 bytes)
TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP reno registered
NET: Registered protocol family 1
NetWinder Floating Point Emulator V0.97 (double precision)
Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
JFFS2 version 2.2. (NAND) ? 2001-2006 Red Hat, Inc.
msgmni has been set to 247
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered
io scheduler deadline registered
io scheduler cfq registered (default)
Serial: AMBA PL011 UART driver
mb:16: ttyAMA0 at MMIO 0x16000000 (irq = 1) is a AMBA/PL011
console [ttyAMA0] enabled
mb:17: ttyAMA1 at MMIO 0x17000000 (irq = 2) is a AMBA/PL011
brd: module loaded
loop: module loaded
tun: Universal TUN/TAP device driver, 1.6
tun: (C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com>
smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <nico@cam.org>
eth0: SMC91C11xFD (rev 1) at c888e000 IRQ 27 [nowait]
eth0: Ethernet addr: 52:54:00:12:34:56
mice: PS/2 mouse device common for all mice
TCP cubic registered
NET: Registered protocol family 17
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
eth0: link up
IP-Config: Complete:
device="eth0", addr="192".168.0.2, mask="255".255.255.0, gw="255".255.255.255,
host="192".168.0.2, domain=, nis-domain=(none),
bootserver="192".168.0.1, rootserver="192".168.0.1, rootpath=
Looking up port of RPC 100003/3 on 192.168.0.1
Looking up port of RPC 100005/3 on 192.168.0.1
VFS: Mounted root (nfs filesystem) on device 0:11.
/bin/sh: can't access tty; job control turned off
# cd ..
# ls
bin etc proc sbin tmp
dev linuxrc root sys
# ifconfig
eth0 Link encap:Ethernet HWaddr 52:54:00:12:34:56
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1478 errors:0 dropped:0 overruns:0 frame:0
TX packets:179 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1991973 (1.8 MiB) TX bytes:28906 (28.2 KiB)
Interrupt:27 Base address:0xe000 DMA chan:ff
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
文章评论(0条评论)
登录后参与讨论