BeagleBoard 的 QEMU 环境搭建 - Linux 驱动调试

Beagleboard is Not BeagleBone, 这篇文章的对象是 beagleboard, 不是 beaglebone

安装 qemu-system-arm

首先需要说明的是:使用sudo apt-get install安装后的qemu-system-arm是不支持beagle板的。
因此我们需要自己编译qemu-linaro源码。在此之前一定要卸载你系统中已有的qemu,运行:

$ sudo apt-get purge qemu*

编译qemu-linaro源码:

$ git clone git://git.linaro.org/qemu/qemu-linaro.git
$ cd qemu-linaro
$ sudo apt-get install zlib1g-dev
$ sudo apt-get install libglib2.0-dev

$ ./configure --prefix=/usr/bin
$ make
$ sudo make install

安装 zlib1g-dev 和 libglib-2.0-dev 是因为编译过程中会用到。安装完成后可运行以下命令查看 qemu 支持的板子:

$ qemu-system-arm -machine help

Supported machines are:
akita                Akita PDA (PXA270)
beagle               Beagle board (OMAP3530)
beaglexm             Beagle board XM (OMAP3630)
...
realview-pb-a8       ARM RealView Platform Baseboard for Cortex-A8
realview-pbx-a9      ARM RealView Platform Baseboard Explore for Cortex-A9
smdkc210             Samsung SMDKC210 board (Exynos4210)
...
xilinx-zynq-a9       Xilinx Zynq Platform Baseboard for Cortex-A9
z2                   Zipit Z2 (PXA27x)

可以看到,编译好的支持 beagle 和 beaglexm 板。

安装 linaro-image-tools 工具

首先是在 Ubuntu 上添加 apt-get 的源,然后安装 linaro-image-tools 工具,命令如下:

sudo add-apt-repository ppa:linaro-maintainers/tools
sudo apt-get update
sudo apt-get install linaro-image-tools

下载 omap3 硬件包并生成 beagle_sd.img 文件

一共两个文件,nano-n-tar-20110823-1.tar.gzhwpack_linaro-omap3_20110823-0_armel_supported.tar.gz

下载地址分别为:

http://download.csdn.net/detail/gzj2013/9910966
http://download.csdn.net/detail/gzj2013/9910994

将下载好的两个文件复制到一个目录后进行以下操作:

$ sudo linaro-media-create --image_file beagle_sd.img --dev beagle --binary nano-n-tar-20110823-1.tar.gz --hwpack hwpack_linaro-omap3_20110823-0_armel_supported.tar.gz

注意其中的–是两个横线,有些网页显示出来会变成中文的破折号,会导致命令执行失败。

提示一路按 Y,最后出现以下提示信息就说明镜像文件创建成功。

Image Name:   Linux
Created:      Wed Jul 26 11:01:25 2017
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    3836224 Bytes = 3746.31 kB = 3.66 MB
Load Address: 80008000
Entry Point:  80008000
Image Name:   initramfs
Created:      Wed Jul 26 11:01:25 2017
Image Type:   ARM Linux RAMDisk Image (uncompressed)
Data Size:    1861231 Bytes = 1817.61 kB = 1.78 MB
Load Address: 00000000
Entry Point:  00000000
Image Name:   boot script
Created:      Wed Jul 26 11:01:25 2017
Image Type:   ARM Linux Script (uncompressed)
Data Size:    444 Bytes = 0.43 kB = 0.00 MB
Load Address: 00000000
Entry Point:  00000000
Contents:
   Image 0: 436 Bytes = 0.43 kB = 0.00 MB
'/tmp/tmpXQb9tt/boot-disc/boot.scr' -> '/tmp/tmpXQb9tt/boot-disc/boot.ini'

Populating rootfs partition
Be patient, this may take a few minutes

Creating /etc/flash-kernel.conf

Updating /etc/network/interfaces

Done creating Linaro image on beagle_sd.img

QEMU 启动系统

生成 beagle_sd.img 文件后通过以下命令启动 QEMU:

sudo qemu-system-arm -M beaglexm -m 512 -sd ./beagle_sd.img -clock unix -serial stdio

执行后出现 QEMU 模拟窗口,开始显示系统启动过程,同时执行命令的窗口也开始显示系统控制台输出,启动过程需要等待一段时间,需要耐心一点。

Texas Instruments X-Loader 1.5.1 (Jul 26 2011 - 00:39:12)
Beagle Rev C4
Reading boot sector
Loading u-boot.bin from mmc


U-Boot 2011.06 (Aug 19 2011 - 17:43:34)

OMAP35XX-GP ES3.1, CPU-OPP2, L3-165MHz, Max CPU Clock 600 mHz
OMAP3 Beagle board + LPDDR/NAND
I2C:   ready
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
*** Warning - bad CRC, using default environment

ERROR : Unsupport USB mode
Check that mini-B USB cable is attached to the device
In:    serial
Out:   serial
Err:   serial
Beagle Rev C4
No EEPROM on expansion board
Die ID #51454d5551454d555400000051454d55
Hit any key to stop autoboot:  0 
SD/MMC found on device 0
reading boot.scr

508 bytes read
Running bootscript from mmc ...
## Executing script at 82000000
reading uImage

3836288 bytes read
reading uInitrd

1861295 bytes read
reading board.dtb

316 bytes read
## Booting kernel from Legacy Image at 80000000 ...
   Image Name:   Linux
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3836224 Bytes = 3.7 MiB
   Load Address: 80008000
   Entry Point:  80008000
   Verifying Checksum ... OK
## Loading init Ramdisk from Legacy Image at 81600000 ...
   Image Name:   initramfs
   Image Type:   ARM Linux RAMDisk Image (uncompressed)
   Data Size:    1861231 Bytes = 1.8 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 815f0000
   Booting using the fdt blob at 0x815f0000
   Loading Kernel Image ... OK
OK
   Using Device Tree in place at 815f0000, end 815f313b

Starting kernel ...

Uncompressing Linux... done, booting the kernel
...
Begin: Running /scripts/init-bottom ... done.
fsck from util-linux-ng 2.17.2
rootfs: clean, 7353/193536 files, 60254/773120 blocks

Welcome to Linaro 11.08 (GNU/Linux 3.0.0-1004-linaro-omap armv7l)

 * Documentation:  https://wiki.linaro.org/

The programs included with the Linaro system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Linaro comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

root@linaro-nano:~#
root@linaro-nano:~#

至此,系统启动完成,启动完成后可以通过 cat /proc/cpuinfo 命令查看 CPU 信息, 当然你也可以测试其它 Linux 命令.

使用 QEMU 调试 Linux 驱动

至此,BeagleBoard 的 QEMU 仿真环境已经搭建完毕,那么如何使用这个环境来进行 Linux 驱动开发呢?

$ sudo losetup /dev/loop0 ./beagle_sd.img
$ sudo fdisk -l /dev/loop0
      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1   *          63      106494       53216    c  W95 FAT32 (LBA)
/dev/loop0p2          106496     6291455     3092480   83  Linux

$ mkdir tmp/
$ sudo mount -o loop,offset=$[63*512] ./beagle_sd.img ./mountpoint
$ ls
board.dtb  boot.ini  boot.scr  boot.txt  MLO  u-boot.bin  uImage  uInitrd

$ sudo mount -o loop,offset=$[106496*512] /dev/loop0 tmp/
$ cd tmp
$ ls
bin   etc         lib         media  proc  selinux  tmp  vmlinuz
boot  home        lost+found  mnt    root  srv      usr
dev   initrd.img  md5sum.txt  opt    sbin  sys      var

$ sudo losetup -d /dev/loop0

此时,我们可以将已经编译好的驱动模块文件复制到该目录下,重新启动 QEMU 系统就可以使用 insmod 加载该驱动模块了。

注意:

uImage 要根据你的驱动所使用的内核版本来替换,一般只需将 uImage 替换即可。

几点说明

因为网上有其他一些资料使用的是一些 linaro 中比较新的版本,但是推荐使用的linaro-media-create 的版本却是很旧,我尝试过 linaro-image-tools-0.4.8.tar.gz 版本来生成 beagle_sd.img 文件,结果很多脚本文件执行就会出错。

参考资料

[1]. http://www.cnx-software.com/2011/09/26/beagleboard-emulator-in-ubuntu-with-qemu/
[2]. http://shortcircuits.io/uefi-with-beagleboard-using-qemu.html

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值