搭建Embedded Linux kernel环境--在QEMU上运行ARM linux系统

来自  http://blog.sina.com.cn/s/blog_a558c25a01012rfl.html



本文的目的:

搭建Embedded Linux kernel学习的环境,在PC(Linux) 的QEMU虚拟机上运行Linux系统,以便之后的进一步调试。 .

本文阐述的内容:

在Linux主机上运行QEMU虚拟机,模拟ARM versatile平台,并在该平台上启动Linux系统的步骤


本文大纲:

1. 安装Toolchain
2. 安装QEMU
3. Build Linux kernel
4. 准备root filesystem
5. 启动QEMU



1. 安装Toolchain

1). 打开以下页面:
http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/

2). 在Supported processors中选择ARM processors->Download the GNU/Linux Release

3). 填写Name, Email, Country的信息,click 'Get Lite'. 下载地址会发到Email邮箱中

4). 在Email中click下载地址,打开下载页面后click "Download Sourcery CodeBench Lite 2011.09-70"

5). 在列出的Packages中选择Recommended Packages中IA32 GNU/LINUX Installer, 此时将下载arm-2011.09-70-arm-none-linux-gnueabi.bin,该文件可直接运行图形界面安装。(也可选择Advanced Packages中的TAR包自行安装,但运行图形界面安装非常方便,不需要考虑太多设置)

6). 在shell中运行
$./arm-2011.09-70-arm-none-linux-gnueabi.bin
开始图形安装界面,按提示安装。

7). 安装完毕后,在shell中确认arm-none-linux-gnueabi-的命令是否已有效。
(如果在安装中选择将CodeSourcery安装到user的home目录下的话,path将被自动添加到user的bash profile中,可重新运行bash profile来enable codesourcery的path. [centos: source ~/.bash_profile, ubuntu: source ~/.profile]

2. 安装QEMU

1). 打开http://wiki.qemu.org/Download,下载qemu-1.0.1.tar.gz

2). 解压缩tar包,编译qemu-system-arm:
$tar zxvf qemu-1.0.1.tar.gz
$cd qemu-1.0.1
$./configure --target-list=arm-softmmu --prefix=/usr/local/      (必须指定target-list,否则会编译所有arch类型的binary)
$make;make install

3). 在shell中确认qemu-system-arm命令已有效


3. Build Linux kernel


1). 从kernel.org下载kernel源代码
方法1:直接得到tar包:
$wget www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.33.7.tar.gz
$tar zxvf linux-2.6.33.7.tar.gz
方法2:用git:
$git clone http://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
$git checkout -B v2.6.33.7 v2.6.33.7  #<---将创建v2.6.33.7的Branch

2). 配置,编译kernel
进入kernel的目录
$make mrproper  #清除所有配置和编译产生的文件
$make ARCH=arm versatile_defconfig  #使用versatile的default configuration
$make ARCH=arm menuconfig #做微小改动
在Kernel Feature中选中 "Use the ARM EABI to compile the kernel"选项。保存退出。
$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- #开始编译

编译完成后,在arch/arm/boot/下会生成zImage

4. 准备root filesystem
(部分内容来自opencsl.openfoundry.org)

1). 下载busybox
$wget http://www.busybox.net/downloads/
$bunzip2 busybox-1.19.4.tar.bz2

2).配置编译busybox
进入busybox-1.19.4
$make mrproper  #清除所有配置和编译产生的文件
$make ARCH=arm defconfig #使用default configuration
$make ARCH=arm menuconfig #做微小改动
选中Busybox Settings->Build Options->Build BusyBox as a static binary (no shared libs),保存退出。
$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- #开始编译
$make ARCH=arm install #编译生成的目标可执行文件等将被安装在_install/目录下。

3). 创建root file system

进入上述busybox make install后的_install/目录

创建root file system必要的目录:
$mkdir etc etc/init.d dev root tmp

在dev/下创建设备开机必须的设备node:
$cd dev
$sudo mknod console c 5 1
$sudo mknod null c 1 3
$sudo mknod ttyAMA0 c 204 64

指定开机要运行的init程序,busybox已包含此功能,只要创建一个指向busybox的init软link即可:
¥ln -s bin/busybox init

创建开机要执行的script:

$vi etc/inittab,内容以下:

*******************************************************
::sysinit:/etc/init.d/rcS

::respawn:/sbin/getty -L ttyAMA0 115200 xterm
*******************************************************
 
$vi etc/init.d/rcS,内容以下:

*******************************************************
#! /bin/sh

mkdir -p /proc
mount -t proc proc /proc
mkdir -p /sys
mount -t sysfs sysfs /sys
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
hostname LINUX-EXPLORER
*******************************************************

创建登录帐号的文件:

$vi etc/passwd,内容如下:

*******************************************************
root::0:0:root:/root:/bin/sh
*******************************************************

$vi etc/group,内容如下:

*******************************************************
root:x:0:
*******************************************************

到此一个简单的root file system就在_install/下创建好了。因为每次make install busybox时都会更新_install目录下的文件,为了便于管理,我们将制作好的root file system复制到另外的地方。

$mkdir /path/of/rootfs (e.g. ~/rootfs/)
$cp -a /.../busybox-1.19.4/_install/* /path/of/rootfs

4). 使用nfs访问root file system
因为系统启动时将通过nfs访问文件系统,所以必须使刚刚创建的root file system可以被nfs mount.

安装nfs server:
每个Linux系统略有不同,这里不详述。

将/path/of/rootfs添加到/etc/exportfs中:

$sudo vi /etc/exportfs
添加一行:
/path/of/rootfs     *(rw,sync,no_root_squash,insecure)
保存退出。

更新nfs export的目录:
$sudo exportfs -r

确认刚才export的目录能够被nfs mount:
$sudo mount localhost:/path/of/rootfs /mnt

5. 启动QEMU

以上在qemu中启动Linux的准备工作都做好了,下面试着启动:

在kernel目录下启动:

$qemu-system-arm -nographic -cpu arm926 -M versatilepb -kernel arch/arm/boot/zImage -append "console=ttyAMA0 rw ip=on root=/dev/nfs nfsroot=localhost:/path/to/rootfs"

-append后面""中是kernel的启动参数,详细解释请看kernel src目录下Documentation/kernel-parameters.txt

猜你喜欢

转载自blog.csdn.net/konga/article/details/51169374
今日推荐