Qemu下u-Boot + Kernel + rootfs完整启动移植

对于Ubuntu12.04系统,首先要安装如下的库文件,不然在后续的移植过程中会出错

1、zlib库

sudo apt-get install zlib1g-dev

2、glib库的安装

1)在Ubuntu下,通过如下命令来获取glib库,命令为:git clone https://git.gnome.org/browse/glib

2)下载完后,进入glib库所在的目录。cd ~/glib/

3)执行sh autogen.sh文件,产生configure配置文件

4) ./configure                           #运行脚本`configure' 

5) make                                   # 构建GLIB库
6)如果必要,切换到root用户下,接着执行如下命令:

rm -rf /install-prefix/include/glib.h /install-prefix/include/gmodule.h
make install   

 

3、autoreconf

sudo apt-get install autoconf

 

4、libsdl1.2


一、安装Qemu

下载地址:http://wiki.qemu.org/Download;选的软件版本为:qemu-1.7.0.tar.bz2

解压安装:

1)新建一个文件夹,用于安装qemu
fantasy@fantasy:/opt$ sudo mkdir /opt/qemu_bin

2)配置
fantasy@fantasy:~/Debug_Kernel/qemu-1.7.0$./configure --prefix=/opt/qemu_bin --target-list="arm-softmmu arm-linux-user x86_64-linux-user x86_64-softmmu" --enable-debug
其中 --prefix表示qemu安装的目录,--target-list表示表示qemu仿真的CPU架构,此处选择支持arm和x86_64 CPU。

加入arm-linux-user后,在对应安装的目录下才会生成qemu-arm文件,不然没有。


可以通过fantasy@fantasy:~/Debug_Kernel/qemu-1.7.0$ ./configure -help来看配置选项

3)make

在该过程中出现了如下错误:
错误1:
(cd /home/fantasy/Debug_Kernel/qemu-1.7.0/pixman; autoreconf -v --install)
/bin/sh: 1: autoreconf: not found
make: *** [/home/fantasy/Debug_Kernel/qemu-1.7.0/pixman/configure] Error 127

解决方法:
sudo apt-get install autoconf


错误2:
configure.ac:75: error: possibly undefined macro: AC_PROG_LIBTOOL
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.

解决方法:
缺少libtool库
sudo apt-get install libtool


4)make install

这样在/opt/qemu_bin目录下就生成了如下的文件:



其中qemu-arm用来执行ARM二进制文件,qemu-system-arm用来启动AMR OS。


二、Qemu仿真ARM

使用Qemu主要有两个目的,一是用来执行运行arm程序,另一个是boot和运行arm kernel

 

对于第一种情况,可以执行利用qemu来运行和测试arm程序,而不需要安装arm os或kernel,qemu的这种特性非常有用,和节省时间。

对于第二种情况,可以用于boot用于arm的Linux kernel。

 

1. 第一种情况,利用Qemu来运行ARM程序

现在,开始开发一个简单的测试程序,我们都知道,开发运行于Intel CPU上的程序,需要用的是x86工具链,因此,若开发运行于ARMCPU上的程序,则需要用arm工具链。从如下地址下载:

http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/

 

1)下载下来后,解压:tar -xvfarm-2013.11-33-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

2)进入bin目录:cd arm-2013.11/bin,如下图


3)设置环境变量:

       a)打开/etc/profile文件,命令:sudo vim /etc/profile

       b)在其中加入arm工具链的bin文件所在的路径,即:exportPATH=$PATH:~/my_workplace/arm-tool-chain/arm-2013.11/bin

4)运行一下命令:source /etc/profile,则到此arm工具链就可以使用了。

 

以下测试一下工具链的使用。

1) 首先创建一个简单的测试程序test.c,代码如下:

#include <stdio.h>

int main()
{
	printf("Welcome to the Open World!\n");
	return 0;
}


2) 运行arm-none-linux-gnueabi-gcc test.c-o test进行编译

 

3) 编译成功后,在当前目录下生成一个test文件,利用file命令来查看test文件的属性,从显示的结果来看,是用于运行ARM平台的可执行文件,如下图所示

 

4) 运行test可执行文件,执行如下命令:

qemu-arm -L~/my_workplace/arm-tool-chain/arm-2013.11/arm-none-linux-gnueabi/libc ./test

在运行该程序时,必须链接到ARM库,其中–L即用于链接ARM库。

       输出如下图所示:



2.第二种情况,利用Qemu来启动ARM的Linux kernel。

首先,来学习一下U-Boot, 对于ARM处理器,U-Boot是用于bootloader最好的选择,U-boot可以用于不同的CPU架构,像PPC,MIPS,x86等等。

1)下载和编译U-Boot

下载发行版本:从ftp://ftp.denx.de/pub/u-boot/地址下载,我选择的版本是u-boot-2010.03.tar.bz2

2)解压,命令为:

tar -jxvf u-boot-2010.03.tar.bz2 

3)进入解压后的文件夹中,命令:

cd u-boot-2010.03/

4)针对ARM平台进行编译,使其适合用于ARM处理器,

配置U-boot用于特定的板子(此处versatilepb),执行如下命令:

make versatilepb_config arch=ARM CROSS_COMPILE=arm-none-linux-gnueabi-

如下图:



5)编译U-Boot,命令为:

make all arch=ARM CROSS_COMPILE=arm-none-linux-gnueabi-

6)在Qemu中运行U-Boot,命令为:

qemu-system-arm -M versatilepb -nographic -kernel u-boot.bin

运行结果如下:



适用于ARM平台的kernel的编译

1)下载内核,解压,我下载的内核版本为(linux-3.13.5)

# tar -jxvf linux-3.13.5.tar.bz2


2)  配置内核,

# cd linux-3.13.5

# make menuconfig ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-

会出现如下错误:

scripts/kconfig/mconf.o: Infunction `show_help':

mconf.c:(.text+0x8a4): undefinedreference to `stdscr'

解决方法:

sudoapt-get install libncurses5  libncurses5-dev

 

指定了架构为ARM,同时调用ARM工具链来构建内核,在Kernel Features导航窗口中,使能“Use the ARM EABI to compilethe kernel”(EABI是Embedded Application BinaryInterface),若该项没选,则内核将无法加载test程序。

 


修改Kernel用于U-Boot加载

由于我们是基于U-Boot来加载内核,应该需要对Kernel进行修改,由于Kernel zImage与U-Boot不兼容,所以我们使用uImage来替代,uImage对Kernel Image的头进行了修改,以支持U-Boot。

编译Kernel,选择构建uImage用于U-Boot(编译时需要指定架构和ARM工具链)

# make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- uImage -s

若按这个命令编译,会出现如下错误:

multiple (or no) load addresses: 
This is incompatible with uImages
Specify LOADADDR on the commandline to build an uImage
make[1]: *** [arch/arm/boot/uImage] Error 1
make: *** [uImage] Error 2


解决办法:

运行如下编译命令:

make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- LOADADDR=0x80008000 uImage -s

 

编译好后,就生成了uImage文件,通过file命令来查看uImage文件的属性,如下图:

 

接着,在Qemu上测试uImage,结果如下图所示:

。。。

 



参考资料:

1. http://www.linuxforu.com/2011/05/quick-quide-to-qemu-setup/

2. http://www.linuxforu.com/2011/06/qemu-for-embedded-systems-development-part-1/

3. http://www.linuxforu.com/2011/07/qemu-for-embedded-systems-development-part-2/

4. http://www.linuxforu.com/2011/08/qemu-for-embedded-systems-development-part-3/

5. http://www.elinux.org/Virtual_Development_Board

6. http://www.cnblogs.com/heaad/archive/2010/07/17/1779829.html

7. http://wenku.baidu.com/link?url=iXtGe29tPdbpmE5oxUHERamFjbs2tkS9Hy7Ut7YOaoAd39i90d7KANEx0dUjzZFh0o888sb_WGdaaRp0rs4XkqiqgIAXwSdEEqbLp0p2tru

Git参考资料:

8. http://blog.csdn.net/five3/article/details/8904635

9. http://wenku.it168.com/d_000598232.shtml

  • 2
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,以下是帮助你搭建QEMU OpenWrt + Cortex-A7 + Visual Studio虚拟开发和debug环境的步骤: 1. 安装QEMU 首先,你需要安装QEMU模拟器。你可以从官网下载QEMU的最新版本:https://www.qemu.org/download/ 。 2. 下载OpenWrt 接下来,你需要下载OpenWrt的镜像文件。你可以从OpenWrt的官网下载:https://openwrt.org/downloads 。 3. 安装交叉编译工具链 你需要安装针对Cortex-A7处理器的交叉编译工具链。你可以从ARM的官网下载:https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads 。 安装完工具链后,将其添加到系统的PATH环境变量中。 4. 启动OpenWrt 使用QEMU启动OpenWrt。命令如下: ``` qemu-system-arm -M vexpress-a9 -m 256M -kernel openwrt-armvirt-32-zImage -append "root=/dev/vda rootfstype=ext4 rootwait console=ttyAMA0" -drive file=openwrt-armvirt-32-root.ext4,if=none,id=hd0 -device virtio-blk-device,drive=hd0 -netdev user,id=network0 -device virtio-net-device,netdev=network0 ``` 5. 连接到OpenWrt 使用SSH连接到OpenWrt。命令如下: ``` ssh -t root@localhost -p 2222 ``` 6. 安装Visual Studio 安装Windows版的Visual Studio。你可以从Microsoft的官网下载:https://visualstudio.microsoft.com/downloads/ 。 7. 配置Visual Studio 在Visual Studio中,选择“工具”>“选项”>“调试”>“远程调试”,然后添加一个新的远程调试器。 设置目标为OpenWrt的IP地址和端口号(默认为2222)。选择“使用SSH连接”选项,并输入用户名和密码。 8. 开始调试 现在你已经准备好在Visual Studio中进行调试了。首先,设置断点或者在代码中插入调试语句。然后,使用Visual Studio启动远程调试器,并连接到OpenWrt。 现在你可以在Visual Studio中进行调试了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值