在模拟器上运行一个64bit linux kernel(aarch64)

来源:互联网 发布:霍启山 章子怡 知乎 编辑:程序博客网 时间:2024/04/30 00:51
为什么要在模拟器上运行一个linux kernel?
主要是为了方便调试内核和应用程序,编译内核源码,测试。aarch64,是调试64位内核和应用程序的。

1、下载编译器 64bit arm toochain
sudo apt-get install gcc-aarch64-linux-gnu
sudo apt-get install g++-aarch64-linux-gnu

2、下载qemu模拟器
git clone git://git.qemu.org/qemu.git qemu.git
cd qemu.git
./configure --target-list=aarch64-softmmu
make

3、下载文件系统
git clone git://git.buildroot.net/buildroot buildroot.git
cd buildroot.git
make menuconfig

下面是menuconfig的配置:
There are lots of configuration options to choose from but the following are what I use:

* Target Options -> Target Architecture(AArch64)
* Toolchain -> Toolchain type (External toolchain)
* Toolchain -> Toolchain (Linaro AArch64 14.02)
* System configuration -> Run a getty (login prompt) after boot (BR2_TARGET_GENERIC_GETTY)
* System configuration -> getty options -> TTY Port (ttyAMA0) (BR2_TARGET_GENERIC_GETTY_PORT)
* Target Packages -> Show packages that are also provided by busybox (BR2_PACKAGE_BUSYBOX_SHOW_OTHERS)
* Filesystem images -> cpio the root filesystem (for use as an initial RAM filesystem) (BR2_TARGET_ROOTFS_CPIO)

make

4、下载内核
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git linux.git
cd linux.git
ARCH=arm64 make defconfig
ARCH=arm64 make menuconfig
ARCH=arm64 make CONFIG_CROSS_COMPILE="aarch64-linux-gnu-"

5、测试 (cd qemu.git)
./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 512 -kernel ../linux-3.10.71/arch/arm64/boot/Image  -initrd ../buildroot.git/output/images/rootfs.cpio --append "console=ttyAMA0"

6、mount本地文件系统
./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 512 -kernel ../linux-3.10.71/arch/arm64/boot/Image  -initrd ../buildroot.git/output/images/rootfs.cpio --append "console=ttyAMA0" -fsdev local,id=r,path=/home/alex/lsrc/qemu/rootfs/trusty-core,security_model=none -device virtio-9p-device,fsdev=r,mount_tag=r

Welcome to Buildroot
buildroot login: root
# mount -t 9p -o trans=virtio r /mnt
# ls -l /mnt/
total 84
drwxr-xr-x    2 default  default      4096 Apr  2  2014 bin
drwxr-xr-x    2 default  default      4096 Feb 27  2014 boot
drwxr-xr-x    3 default  default      4096 Apr  2  2014 dev
drwxr-xr-x  64 default  default      4096 Apr  3  2014 etc
drwxr-xr-x    2 default  default      4096 Feb 27  2014 home
..

7、不需要自己编译,直接使用已有的内核加文件系统
wget http://people.linaro.org/~alex.bennee/images/aarch64-linux-3.15rc2-buildroot.img 
./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel aarch64-linux-3.15rc2-buildroot.img --append "console=ttyAMA0"

0 0
原创粉丝点击