SetupDevEnv

来自飞腾CPU与嵌入式系统
Zhuangyy讨论 | 贡献2016年11月8日 (二) 18:25的版本
跳到导航 跳到搜索

Native开发环境

飞腾系列本身CPU性能较强, 因此可以直接作为开发机使用. 在作为开发机使用的时候, 建议安装Debian操作系统.


交叉编译环境

飞腾系列CPU可以直接使用linaro官方编译器. [网页地址]

当前NetONE系统所使用的toolchain是gcc-linaro-5.3-2016.02-x86_64_aarch64-linux-gnu.tar.xz (Aarch64 little-endian)

交叉编译器可以在host设备(例如x64)上编译target(例如arm64)平台上的程序. 最大的优点是编译速度快, 缺点是编译完的程序要copy到target设备上才能运行, debug也不是很方便


QEMU

QEMU同样可以在x64的机器上建立起arm64的开发环境, 而且使用方式类似Native环境, 可以在代码编译后, 直接执行并debug. 下面将以debian为例, 说明如何在x64设备上建立基于qemu的arm64开发环境.

首先, 你需要有一台x64的设备, 安装有debian, 在x64上, 执行:

 1apt-get install qemu qemu-user-static binfmt-support debootstrap
 2qemu-debootstrap --arch=arm64 --keyring /usr/share/keyrings/debian-archive-keyring.gpg --variant=buildd --exclude=debfoster testing debian-arm64 http://mirrors.163.com/debian
 3chroot debian-arm64  # 现在你已经在arm64环境之下了
 4echo "deb http://mirrors.163.com/debian testing main" > /etc/apt/sources.list
 5apt-get update
 6apt-get install debian-ports-archive-keyring file# 这时候执行的apt-get命令已经是arm64的程序了
 7gcc -o hello hello.c #编译hello world
 8./hello #执行hello world
 9file hello
10# 输出: hello: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=ddf80581621cd711415b234ee33e7b048dccd21c, not stripped

不过QEMU的缺点是: 由于是以虚拟化的方式运行, 因此速度比较(非常)慢. 不适合编译类似linux内核这样的大型程序.