qemu 的beagleboard环境搭建

来源:互联网 发布:ubuntu 安装glsl 编辑:程序博客网 时间:2024/06/04 06:50

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 helpSupported machines are:akita                Akita PDA (PXA270)beagle               Beagle board (OMAP3530)beaglexm             Beagle board XM (OMAP3630)...realview-pb-a8       ARM RealView Platform Baseboard for Cortex-A8realview-pbx-a9      ARM RealView Platform Baseboard Explore for Cortex-A9smdkc210             Samsung SMDKC210 board (Exynos4210)...xilinx-zynq-a9       Xilinx Zynq Platform Baseboard for Cortex-A9z2                   Zipit Z2 (PXA27x)

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

安装linaro-image-tools工具

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

sudo add-apt-repository ppa:linaro-maintainers/toolssudo apt-get updatesudo 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:   LinuxCreated:      Wed Jul 26 11:01:25 2017Image Type:   ARM Linux Kernel Image (uncompressed)Data Size:    3836224 Bytes = 3746.31 kB = 3.66 MBLoad Address: 80008000Entry Point:  80008000Image Name:   initramfsCreated:      Wed Jul 26 11:01:25 2017Image Type:   ARM Linux RAMDisk Image (uncompressed)Data Size:    1861231 Bytes = 1817.61 kB = 1.78 MBLoad Address: 00000000Entry Point:  00000000Image Name:   boot scriptCreated:      Wed Jul 26 11:01:25 2017Image Type:   ARM Linux Script (uncompressed)Data Size:    444 Bytes = 0.43 kB = 0.00 MBLoad Address: 00000000Entry Point:  00000000Contents:   Image 0: 436 Bytes = 0.43 kB = 0.00 MB'/tmp/tmpXQb9tt/boot-disc/boot.scr' -> '/tmp/tmpXQb9tt/boot-disc/boot.ini'Populating rootfs partitionBe patient, this may take a few minutesCreating /etc/flash-kernel.confUpdating /etc/network/interfacesDone 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 C4Reading boot sectorLoading u-boot.bin from mmcU-Boot 2011.06 (Aug 19 2011 - 17:43:34)OMAP35XX-GP ES3.1, CPU-OPP2, L3-165MHz, Max CPU Clock 600 mHzOMAP3 Beagle board + LPDDR/NANDI2C:   readyDRAM:  256 MiBNAND:  256 MiBMMC:   OMAP SD/MMC: 0*** Warning - bad CRC, using default environmentERROR : Unsupport USB modeCheck that mini-B USB cable is attached to the deviceIn:    serialOut:   serialErr:   serialBeagle Rev C4No EEPROM on expansion boardDie ID #51454d5551454d555400000051454d55Hit any key to stop autoboot:  0 SD/MMC found on device 0reading boot.scr508 bytes readRunning bootscript from mmc ...## Executing script at 82000000reading uImage3836288 bytes readreading uInitrd1861295 bytes readreading board.dtb316 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 ... OKOK   Using Device Tree in place at 815f0000, end 815f313bStarting kernel ...Uncompressing Linux... done, booting the kernel...Begin: Running /scripts/init-bottom ... done.fsck from util-linux-ng 2.17.2rootfs: clean, 7353/193536 files, 60254/773120 blocksWelcome 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 theindividual files in /usr/share/doc/*/copyright.Linaro comes with ABSOLUTELY NO WARRANTY, to the extent permitted byapplicable law.root@linaro-nano:~#root@linaro-nano:~#

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

使用 qemu 调试linux驱动

至此,beagleqemu仿真环境已经搭建完毕,那么如何使用这个环境来进行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$ lsboard.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$ lsbin   etc         lib         media  proc  selinux  tmp  vmlinuzboot  home        lost+found  mnt    root  srv      usrdev   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文件,结果很多脚本文件执行就会出错。

参考博客:

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