使用Qemu模拟Cortex-A9运行U-boot和Linux


开发环境: Ubuntu 12.04  所有软件包为最新
1. 安装GNU工具链
  1. sudo apt-get insatll gcc-arm-linux-gnueabi
  2. sudo apt-get insatll g++-arm-linux-gnueabi
安装完成后会在 /usr/arm-linux-gnueabi/ 目录下生成库文件、头文件等。 我安装的GCC版本为:
  1. arm-linux-gnueabi-gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
  2. Copyright (C) 2011 Free Software Foundation, Inc.
2. 安装Qemu模拟器
  1. sudo apt-get install qemu qemu-system qemu-utils
这时应该已经可以运行qemu-system-arm命令了, 其版本为:
  1. qemu-system-arm --version
  2. QEMU emulator version 1.0.50 (Debian 1.0.50-2012.03-0ubuntu2), Copyright (c) 2003-2008 Fabrice Bellard

3. 编译和运行U-boot: 到 ftp://ftp.denx.de/pub/u-boot/ 下载最新版本的U-Boot源代码, 我用的目前最新版本 u-boot-2012.04.tar.bz2   解压后进入源代码目录,在Makefile里面增加两行:
  1. ARCH ?= arm
  2. CROSS_COMPILE ?= arm-linux-gnueabi-
其实就是告诉它使用ARM编译器来编译。
  1. make ca9x4_ct_vxp_config
  2. make
这里配置目标板为 Cortex-A9x4 vexpress. 之所以选这个配置可以从 boards.cfg文件里看到, vexpress是ARM公司使用Cortext-A9的一个开发板,相关的代码在 board/armltd/vexpress/ 目录,配置文件为include/configs/ca9x4_ct_vxp.h。  而且关键的是Qemu里面已经支持这个板卡。
编译完成后会生成u-boot文件 运行:
  1. qemu-system-arm -M vexpress-a9 -m 256M -nographic -kernel u-boot
或者
  1. qemu-system-arm -M vexpress-a9 -m 256M -serial stdio -kernel u-boot
发现,如果没有指定-nographics, 则必须要加-serial stdio才会有打印。
参数-m 256M为指定内存大小。-M 指定板卡的名称, 支持的板卡可以用-M ?查看, 如下:
  1. #qemu-system-arm -M ?
  2. Supported machines are:
  3. beagle Beagle board (OMAP3530)
  4. beaglexm Beagle board XM (OMAP3630)
  5. ............
  6. versatilepb ARM Versatile/PB (ARM926EJ-S)
  7. versatileab ARM Versatile/AB (ARM926EJ-S)
  8. vexpress-a9 ARM Versatile Express for Cortex-A9
  9. vexpress-a15 ARM Versatile Express for Cortex-A15
正常运行的结果:
  1. qemu-system-arm -M vexpress-a9 -m 256M -nographic -kernel u-boot
  2. U-Boot 2012.04 (Jul 08 2012 - 00:14:08)
  3. DRAM: 256 MiB
  4. WARNING: Caches not enabled
  5. Flash: ## Unknown flash on Bank 1 - Size = 0x00000000 = 0 MB
  6. ## Unknown flash on Bank 2 - Size = 0x00000000 = 0 MB
  7. *** failed ***
  8. MMC: MMC: 0
  9. *** Warning - bad CRC, using default environment
  10. In: serial
  11. Out: serial
  12. Err: serial
  13. Net: smc911x-0
  14. Hit any key to stop autoboot: 0
  15. VExpress#
  16. VExpress# printenv
  17. baudrate=38400
  18. bootcmd=run bootflash;
  19. bootdelay=2
  20. bootflash=run flashargs; cp ${ramdisk_addr} ${ramdisk_addr_r} ${maxramdisk}; bootm ${kernel_addr} ${ramdisk_addr_r}
  21. console=ttyAMA0,38400n8
  22. 。。。。。
注意:如果在检测Flash failed后停止运行,是因为在 arch/arm/lib/board.c里面 board_init_r()函数里检测Flash失败后调用了hang(), 暂时先把hang()去掉就可以运行下去了。
  • 1
  • 2
  • 下一页

相关内容