Build-Cortex-A9-Linux-Debug-Environment with QEMU

It takes 8 weeks, and run successfully now. :-)

Prepare:

Ubuntu 14.04, 16.10, Cross Compiler, QEUM, U-boot, Linux, Root-FS.

  • Ubuntu
    • 14.04, 16.10
  • Cross Compiler

    • sudo apt-get insatll gcc-arm-linux-gnueabi

    • sudo apt-get insatll g++-arm-linux-gnueabi

    • 安装完成后会在 /usr/arm-linux-gnueabi/ 目录下生成库文件、头文件等。 我安装的GCC版本为:

        arm-linux-gnueabi-gcc \(Ubuntu/Linaro 4.7.3-12ubuntu1\) 4.7.3
      
        Copyright \(C\) 2012 Free Software Foundation, Inc.
      
  • QEMU

    • way 1: sudo apt-get install qemu qemu-system qemu-utils
    • qemu-system-arm --version

    • git clone git://git.qemu.org/qemu.git

    预安装以下库:

    • sudo apt-get install zlib1g-dev

    • sudo apt-get install libglib2.0-0

    • sudo apt-get install libglib2.0-dev

    • 配置qemu,支持模拟arm架构下的所有单板:

                ./configure --target-list=arm-softmmu --audio-drv-list=
      

    编译和安装:

                make
    
                     make install
    
  • U-Boot

    • git clone git://git.denx.de/u-boot.git

    • focus@focus-VirtualBox:~/QEMU/u-boot$ ls configs/ |less

      focus@focus-VirtualBox:~/QEMU/u-boot$ ls configs/ | grep a9

      usb_a9263_dataflash_defconfig

      vexpress_ca9x4_defconfig

    • focus@focus-VirtualBox:~/QEMU/u-boot$ ls configs/vexpress*

      configs/vexpress_aemv8a_dram_defconfig configs/vexpress_ca15_tc2_defconfig

      configs/vexpress_aemv8a_juno_defconfig configs/vexpress_ca5x2_defconfig

      configs/vexpress_aemv8a_semi_defconfig configs/vexpress_ca9x4_defconfig

      focus@focus-VirtualBox:~/QEMU/u-boot$ sudo make vexpress_ca9x4_defconfig

      focus@focus-VirtualBox:~/QEMU/u-boot$ sudo 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. ............
  • Linux

    • sudo git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

    • 修改Makefile, ARCH = arm, CROSS_COMPILE=arm-linux-gnueabi-

      1. make vexpress_defconfig

      (可以到 arch/arm/configs/ 目录看到所有自带的配置文件, 我们使用vexpress板卡默认的配置文件)

      然后 make menuconfig --> System Type 把 Enable the L2x0 outer cache controller 取消, 否则Qemu会起不来, 暂时还不知道为什么。然后就可以make了。 最后会生成 arch/arm/boot/zImage 文件, 这就是我们需要的内核映像。

  • Root-FS

    • Busybox Settings ---> Build Options --->

      [*] Build BusyBox as a static binary (no shared libs)

            ~$cd busybox
      
                    \# Adjust some settings as mentioned above
      
           ~/busybox$ARCH=arm CROSS\_COMPILE=arm-linux-gnueabihf- make menuconfig
      
                   \# Compile Busybox
      
            ~/busybox$ARCH=arm CROSS\_COMPILE=arm-linux-gnueabihf- make -j4
      
        SCRIPT:
      

#!/bin/bash

#Remove old files

sudo rm -rf rootfs

rmdir tmpfs

rm -f a9rootfs.ext3

#Create new rootfs folder

sudo mkdir rootfs

sudo cp busybox/_install/* rootfs/ -raf

#Create folders required by Linux convention

sudo mkdir -p rootfs/proc/

sudo mkdir -p rootfs/sys/

sudo mkdir -p rootfs/tmp/

sudo mkdir -p rootfs/root/

sudo mkdir -p rootfs/var/

sudo mkdir -p rootfs/mnt/

#Download sample etc files with init procedure and copy it to rootfs

wget http://files.cnblogs.com/files/pengdonglin137/etc.tar.gz

tar -xf ./etc.tar.gz

sudo cp etc rootfs/ -arf

#Copy shared libraries to rootfs

sudo cp -arf /usr/arm-linux-gnueabi/lib rootfs/

sudo rm rootfs/lib/*.a

sudo arm-linux-gnueabi-strip rootfs/lib/*

#Create basic device nodes

sudo mkdir -p rootfs/dev/

sudo mknod rootfs/dev/tty1 c 4 1

sudo mknod rootfs/dev/tty2 c 4 2

sudo mknod rootfs/dev/tty3 c 4 3

sudo mknod rootfs/dev/tty4 c 4 4

sudo mknod rootfs/dev/console c 5 1

sudo mknod rootfs/dev/ttyAMA0 c 204 64

sudo mknod rootfs/dev/null c 1 3

#Create ext3 image file

dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=$((32))

mkfs.ext3 a9rootfs.ext3

#Copy all the files in our rootfs to image

mkdir -p tmpfs

sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop

sudo cp -r rootfs/* tmpfs/

sudo umount tmpfs

rmdir tmpfs

results for ""

    No results matching ""