MINI2440 Dev Board Emulated by QEMU

References:

1. 使用qemu 建立mini2440的模拟仿真环境

2. <<使用qemu 建立mini2440的模拟仿真环境>>补充修正说明

3. 手把手教你制作根文件系统

4. http://repo.or.cz/w/qemu/mini2440.git


Introduction

本文基于如下开源项目:

description Samsung s3c2440 and arm920t support for the mini2440 dev board
homepage URL http://code.google.com/p/mini2440/
owner buserror@gmail.com
last change Thu, 13 Oct 2011 11:24:48 +0000
URL git://repo.or.cz/qemu/mini2440.git
http://repo.or.cz/r/qemu/mini2440.git
Push URL ssh://repo.or.cz/srv/git/qemu/mini2440.git

readme
MINI2440 u-boot, kernel & distro project

This tree is part of a project to get up-to-date u-boot/kernel for the Samsung S3C2440 based board known as "MINI2440".
You can find this great board for really cheap, with:
        + 400Mhz ARM9 (arm920t)
        + 64MB SDRAM
        + 64MB NAND / 2MB NOR
        + SD, USB host/device, 3 uarts, 100BaseT etc etc
        + 3.5 or 7" TFT touch screen


Available git trees:

        http://repo.or.cz/w/u-boot-openmoko/mini2440.git
                More modern u-boot, based on openmoko's fork, with mcc support, usb etc

        http://repo.or.cz/w/linux-2.6/mini2440.git
                Bleeding edge Modern Kernel board support (based on Linus's)
                Kernel is now stable, and supports pretty much all the peripherals

        http://repo.or.cz/w/openembedded/mini2440.git
                Openembedded fork with support for mini2440
                Contains enough to build a toolchain and a flash image.

        http://repo.or.cz/w/qemu/mini2440.git
                A QEMU fork that emulates most of a mini2440 !
                Supports booting NAND, SD, NFS etc. LCD is recognized etc..
                You need a valid u-boot.bin to start, and a kernel uImage as parameter

        http://repo.or.cz/w/mini2440-tools.git
                Various tools & Scripts for the mini.

Feel free to email me to get push access to these trees.

Preparation - Toolchain and Directory

Build Environment:

  1. qemu: gcc version 4.4.5 (Debian 4.4.5-8)
  2. linux kernel & uboot: gcc version 4.4.1 (Sourcery G++ Lite 2010q1-188) (系统路径默认)
  3. busybox: crosstool gcc-3.4.5-glibc-2.3.6 (tls) - with thread supported

Directory:

qemu-mini2440
├── busybox-1.7.0
├── fs_mini_mdev
├── fs_qtopia
├── fs_busybox
├── gcc-3.4.5-glibc-2.3.6
├── linux-2.6
├── qemu
├── uboot

QEMU for MINI2440

Dowload

首先下载qemu for mini2440

git clone git://repo.or.cz/qemu/mini2440.git  qemu

如果感觉速度慢或者出错,直接打包下载 (下同)

http://repo.or.cz/w/qemu/mini2440.git/snapshot/HEAD.tar.gz

改名并解压后,进入源代码的主目录中

Compile

cd qemu
./configure --target-list=arm-softmmu
make

Uboot for MINI2440

Download

下载u-boot for mini2440

git clone  git://repo.or.cz/w/u-boot-openmoko/mini2440.git uboot

或者打包下载

http://repo.or.cz/w/u-boot-openmoko/mini2440.git/snapshot/HEAD.tar.gz

注意: 采用打包下载的时候这几个包的文件名可能相同,注意区分)

Compile

解压后,配置Makefile文件,打开Makefile文件,CROSS_COMPILE变量赋值,即自己所使用的交叉编译工具链,比如我的是arm-none-linux-gnueabi-,保存退出,输入

make CROSS_COMPILE=arm-linux- mini2440_config
make CROSS_COMPILE=arm-linux-

注意: 如果想在之后使用u-boot 的nfs下载文件功能,需要修改代码中的一部分,将net/nfs.c文件中的 NFS_TIMEOUT = 2UL 修改为 NFS_TIMEOUT = 20000UL 否则会造成nfs文件下载失败,如果不使用nfs下载功能,不改也可。

稍等两分钟,即在当前目录下生成名为 u-boot.bin 的文件。

Install

将生成的u-boot.bin拷贝到qemu/mini2440目录下

Linux Kernel 2.6 for MINI2440

Current version is: Linux version 2.6.32-rc8

Dowload

下载 linux kernel for mini2440:

git clone git://repo.or.cz/w/linux-2.6/mini2440.git linux-2.6

如果感觉速度慢或者出错,直接打包下载

http://repo.or.cz/w/linux-2.6/mini2440.git/snapshot/HEAD.tar.gz

改名并解压后,进入源代码的主目录中

Compile

make ARCH=arm mini2440_defconfig
make ARCH=arm menuconfig

enable eabi menu options

kernel Features -->
Memory split (3G/1G user/kernel split) --->
[ ] Preemptible Kernel (EXPERIMENTAL)
[*] Use the ARM EABI to compile the kernel
[*] Allow old ABI binaries to run with this kernel (EXPERIMENTAL)
[ ] High Memory Support (EXPERIMENTAL)
      Memory model (Flat Memory) --->
[ ] Add LRU list to track non-evictable pages
(4096) Low address space to protect from user allocation

注意: 如果这些选项不打开,会造成有些旧的文件系统和操作系统不兼容。 NFS挂载这些文件系统后启动时出现问题: Kernel panic - not syncing: No init found.

即使打开这些选项,也同样建议使用和kernel兼容的gcc-glibc版本去 编译busybox和文件系统

make ARCH=arm CROSS_COMPILE=arm-linux- uImage

如果编译uImage时出现错误:

"mkimage" command not found - U-Boot images will not be built

是因为没有安装生成uImage的工具,运行

sudo apt-get install uboot-mkimage

安装该命令,或者把上面uboot/tools中build好的工具加入到路径中。

Install

之后会在arch/arm/boot/目录下生成uImage 文件,将此文件复制到qemu/mini2440文件夹下, 并将mini2440文件夹中的mini2440_start.sh作如下修改:

...

cmd="$base/../arm-softmmu/qemu-system-arm \
        -M mini2440 $* \
        -serial stdio \
        -kernel $base/uImage \
        -mtdblock "$name_nand" \
...

输入下面命令试一下,这时应该看到qemu启动后进入了u-boot界面下:

cd qemu/mini2440
sudo mini2440/mini2440_start.sh

在uboot的提示符下输入:

bootm

就会看到linux内核启动的画面,但此时还没有根文件系统,我们稍候介绍采用nfs挂载根文件系统

Busy Box

Download

下载 http://busybox.net/downloads/busybox-1.7.0.tar.bz2 并解压缩

Compile

注意:关于如何使用crosstool构建交叉编译工具链: gcc-3.4.5-glibc-2.3.6 (tls) 不在此展开。

修改busybox解压缩根目录的Makefile,设置CROSS_COMPILE变量为gcc-3.4.5-glibc-2.3.6所在路径:

CROSS_COMPILE   ?= /home/justin/my/path/to/gcc-3.4.5-glibc-2.3.6/bin/arm-linux-
cd busybox-1.7.0
make ARCH=arm defconfig
make ARCH=arm menuconfig

这个版本的busybox用gcc/glibc来编译不能使用静态链接选项,请确定配置如下:

Busybox Settings --> Build Options -->
[ ] Build BusyBox as a static binary (no shared libs)
[ ] Force NOMMU build
  [*] Build with Large File Support (for accessing files > 2 GB)
  ()  Cross Compiler prefix
  ()  Additional CFLAGS
make ARCH=arm CONFIG_PREFIX=../fs_busybox install

Root File system

Root fs 的制作不在这里详述,参考韦东山《嵌入式linux应用开发完全手册》, 因为后面需要从NFS挂载根文件系统,这里说明几点需要注意的地方。

/dev/console & /dev/null 设备文件

需要在busybox生成的根文件系统中,手动建立这两个设备文件, 否则会出现下列错误:

VFS: Mounted root (nfs filesystem).
Freeing init memory: 112K
Warning: unable to open an initial console.

这是因为当mdev/udev机制起作用之前系统就需要对这两个设备文件进行读写。

只需要挂载NFS之前,在Debian主机环境中运行:

cd fs_busybox/dev
sudo mknod console c 5 1
sudo mknod null c 1 3

然后重新启动NFS服务即可。

使用 mdev机制动态建立设备文件

create the file fs_busybox/etc/init.d/rcS

#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s

and change it to executable:

chmod +x fs_busybox/etc/init.d/rcS

串口改名

create the file fs_busybox/etc/inittab

# /etc/inittab
::sysinit:/etc/init.d/rcS
#s3c2410_serial0::askfirst:-/bin/sh
ttySAC0::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r

在实际开发板串行口为s3c2410_serial0,但是在qemu模拟器中应为ttySAC0

如果不更改上述名称,当kernel启动后,控制台启动login shell的信 息不会显示在串口上,(qemu 启动选项 -serial stdio 将串口输出到主机 console terminal窗口,如不设置,在kernel启动后不能得到mini2440上的shell提示符) 因而不会看到下面信息 (Please press Enter to activate this console. 之后的输出):

Freeing init memory: 128K
init started: BusyBox v1.7.0 (2008-01-22 10:04:09 EST)
starting pid 741, tty '': '/etc/init.d/rcS'

Please press Enter to activate this console.
starting pid 746, tty '/dev/ttySAC0': '/bin/sh'
#

禁止网卡重新配置

因为是从NFS上mount根文件系统,如果使用的是现成的根文件目录,需要禁止系统启动时重新配置网卡,需要检查

$NFS_ROOT/etc/init.d 下文件,注释掉ifconfig相关命令:

# ifconfig lo 127.0.0.1
# route add default gw 192.168.1.2
# ifconfig eth0 192.168.1.6 up

否则会出现找不到根文件系统的错误

Kernel panic - not syncing: Attempted to kill init (???)

Mount NFS RootFS

Install NFS Servcie on Debian

sudo apt-get install nfs-kernel-server

之后修改/etc/exports文件,添加如下一行

/home/username/nfs *(rw,sync,no_root_squash)

注意 /home/username/nfs 为你所要共享的目录, 然后重启动NFS server:

sudo /etc/init.d/nfs-kernel-server restart

忽略如下警告(或者在/etc/exports中加入no_subtree_check选项):

exportfs: /etc/exports [3]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/opt/FriendlyARM/mini2440/root_qtopia".

Assuming default behaviour ('no_subtree_check').

NOTE: this default has changed since nfs-utils version 1.0.x

启动 nfs服务后,测试 nfs服务是否成功启动

sudo mkdir /mnt/nfs
sudo mount -t nfs localhost:/home/username/nfs /mnt/nfs

查看/mnt/nfs文件是否于/home/username/nfs 中相同,若一样 ,OK

QEMU虚拟网卡配置

在qemu/mini2440目录下新建两个文件:

#!/bin/sh
echo "Excuting qemu-ifup"
ifconfig $1 10.0.0.1
#!/bin/sh
echo "Close tap!"
sudo ifconfig $1 10.0.0.1 down

更改可执行属性:

chmod a+x qemu-*.sh

更改qemu/mini2440/mini2440_start.sh:

...
cmd="$base/../arm-softmmu/qemu-system-arm \
        -M mini2440 $* \
        -serial stdio \
        -kernel $base/uImage \
        -mtdblock "$name_nand" \
        -show-cursor \
        -usb -usbdevice keyboard -usbdevice mouse \
        -usbdevice tablet \
        -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=./qemu-ifup.sh,downscript=./qemu-ifdown.sh \
        -monitor telnet::5555,server,nowait"
...

注意其中网卡配置:

        -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=./qemu-ifup.sh,downscript=./qemu-ifdown.sh \

如果运行该脚本出现如下错误:

"warning: could not open /dev/net/tun: no virtual network emulation"

需要确保主机环境正确配置了tun/tap虚拟网络,参考:

http://www.linuxdiyf.com/viewarticle.php?id=40202 以及 debian: minixonbochs

并且确保用sudo root 权限运行脚本qemu/mini2440/mini2440_start.sh (或者chmod 777 /dev/net/tun)

Try it out

输入下面命令试一下,这时应该看到qemu启动后进入了u-boot界面下:

cd qemu/mini2440
sudo mini2440_start.sh

在uboot的提示符下输入:

set bootargs noinitrd root=/dev/nfs rw nfsroot=10.0.0.1:/home/justin/path/to/nfs/fs_busybox ip=10.0.0.10:10.0.0.1::255.255.255.0 console=ttySAC0,115200
bootm

注意: 上述命令行中, 10.0.0.10是qemu eth0的初始ip地址,10.0.0.1是主机虚拟网卡的ip地址。(host-only mode)

在主机terminal窗口看到如下输出证明成功:

VFS: Mounted root (nfs filesystem) on device 0:13.
Freeing init memory: 128K
init started: BusyBox v1.7.0 (2008-01-22 10:04:09 EST)
starting pid 741, tty '': '/etc/init.d/rcS'

Please press Enter to activate this console.
starting pid 746, tty '/dev/ttySAC0': '/bin/sh'
# ls
bin      etc      linuxrc  proc     sbin     tmp
dev      lib      mnt      root     sys      usr
#
Wiki comments powered by Disqus