最近買了個友善之臂的NanoPi M1闆子,又在網上申請了個NanoPi NEO闆子,這兩個都是基于全志H3晶片的Crotex-A7四核ARM開發闆,兩個闆子可以共用一套開發環境,本文就以NanoPi NEO為例,簡單講述基于全志H3晶片的ARM交叉編譯開發環境搭建,和NFS網絡伺服器搭建。
基于全志H3晶片的ARM開發環境搭建
最近買了個友善之臂的NanoPi M1闆子,又在網上申請了個NanoPi NEO闆子,這兩個都是基于全志H3晶片的Crotex-A7四核ARM開發闆,兩個闆子可以共用一套開發環境,本文就以NanoPi NEO為例,簡單講述基于全志H3晶片的ARM開發環境搭建。
1. 安裝交叉編譯工具
1.1 擷取交叉編譯工具
在百度網盤中,給出了Nanopi NEO的交叉編譯工具:

注意:
第一個 gcc-linaro-arm.tar.xz 是用友善之臂給出的腳本編譯生成固件的;
如果需要交叉編譯工具編譯應用程式或者核心,需要使用第二個 arm-cortexa9-linux-gnueabihf-4.9.3-20160512.tar.xz 工具。
1.2 安裝交叉編譯工具
解壓:arm-cortexa9-linux-gnueabihf-4.9.3-20160512.tar.xz,得到 4.9.3 目錄,與其他平台搭建交叉編譯環境方法一樣,将該目錄複制到 /usr/local/arm/ 目錄下
設定環境變量,在 ~/.bashrc 最後添加:
# vim ~/.bashrc
PATH=$PATH:/usr/local/arm/4.9.3/bin/
export PATH
重新開機或者登出使用者再登入即可使用該交叉編譯工具。
1.3 驗證安裝是否成功
驗證交叉編譯工具是否安裝成功:
$ arm-cortexa9-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-cortexa9-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/usr/local/arm/4.9.3/bin/../libexec/gcc/arm-cortexa9-linux-gnueabihf/4.9.3/lto-wrapper
Target: arm-cortexa9-linux-gnueabihf
Configured with: /work/toolchain/build/src/gcc-4.9.3/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=arm-cortexa9-linux-gnueabihf --prefix=/opt/FriendlyARM/toolchain/4.9.3 --with-sysroot=/opt/FriendlyARM/toolchain/4.9.3/arm-cortexa9-linux-gnueabihf/sys-root --enable-languages=c,c++ --with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=vfpv3 --with-float=hard --with-pkgversion=ctng-1.21.0-229g-FA --with-bugurl=http://www.friendlyarm.com/ --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --with-gmp=/work/toolchain/build/arm-cortexa9-linux-gnueabihf/buildtools --with-mpfr=/work/toolchain/build/arm-cortexa9-linux-gnueabihf/buildtools --with-mpc=/work/toolchain/build/arm-cortexa9-linux-gnueabihf/buildtools --with-isl=/work/toolchain/build/arm-cortexa9-linux-gnueabihf/buildtools --with-cloog=/work/toolchain/build/arm-cortexa9-linux-gnueabihf/buildtools --with-libelf=/work/toolchain/build/arm-cortexa9-linux-gnueabihf/buildtools --enable-lto --with-host-libstdcxx=\'-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm\' --enable-threads=posix --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-gold --disable-multilib --with-local-prefix=/opt/FriendlyARM/toolchain/4.9.3/arm-cortexa9-linux-gnueabihf/sys-root --enable-long-long
Thread model: posix
gcc version 4.9.3 (ctng-1.21.0-229g-FA)
1.4 驗證交叉編譯工具是否能正常編譯
驗證安裝的交叉編譯工具編譯的程式在Nanopi NEO闆子上能夠運作:
1)先寫一個簡單的驗證程式,也就是程式員”家喻戶曉“的 Hello world!
$ cat hello.c
#include <stdio.h>
int main(void)
{
printf("Hello world!\n");
return 0;
}
2)将程式交叉編譯為闆子能運作的程式:
$ arm-cortexa9-linux-gnueabihf-gcc hello.c -o hello
3)編譯完成後生成的hello程式,檢視檔案屬性:
$ file hello
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.0.8, BuildID[sha1]=e471478037c7cf740dadac9ec82136aad38f0c4e, not stripped
2. 将程式通過NFS檔案系統複制到開發闆
2.1 先讓闆子連上網
1)確定闆子已經能夠正常聯網:
# ifconfig
eth0 Link encap:Ethernet HWaddr **:**:**:**:**:**
inet addr:***.***.*.*** Bcast:***.***.*.255 Mask:255.255.255.0
inet6 addr: ****::****:****:****:****/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:820 errors:0 dropped:0 overruns:0 frame:0
TX packets:637 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:513171 (501.1 KiB) TX bytes:49921 (48.7 KiB)
Interrupt:114
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:33 errors:0 dropped:0 overruns:0 frame:0
TX packets:33 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3304 (3.2 KiB) TX bytes:3304 (3.2 KiB)
2)ping外網,檢測是否能和外網通訊:
# ping www.baidu.com
PING www.baidu.com (163.177.151.110) 56(84) bytes of data.
64 bytes from www.baidu.com (163.177.151.110): icmp_seq=1 ttl=53 time=11.1 ms
64 bytes from www.baidu.com (163.177.151.110): icmp_seq=2 ttl=53 time=10.3 ms
64 bytes from www.baidu.com (163.177.151.110): icmp_seq=3 ttl=53 time=10.6 ms
^C
--- www.baidu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 10.356/10.740/11.183/0.350 ms
2.2 安裝NFS伺服器并配置NFS目錄
1)安裝NFS伺服器
# sudo apt-get install nfs-kernel-server
2)建立NFS目錄:
# vim /etc/exports
添加:
/mnt *(rw,sync,no_root_squash,no_subtree_check)
3)重新開機NFS伺服器:
# systemctl restart nfs-kernel-server
4)檢查nfs是否啟動:
# ps -aux | grep nfs
root 39 0.0 0.0 0 0 ? S< 14:53 0:00 [nfsiod]
root 29118 0.0 0.0 0 0 ? S 15:55 0:00 [nfsd]
root 29119 0.0 0.0 0 0 ? S 15:55 0:00 [nfsd]
root 29120 0.0 0.0 0 0 ? S 15:55 0:00 [nfsd]
root 29121 0.0 0.0 0 0 ? S 15:55 0:00 [nfsd]
root 29122 0.0 0.0 0 0 ? S 15:55 0:00 [nfsd]
root 29123 0.0 0.0 0 0 ? S 15:55 0:00 [nfsd]
root 29124 0.0 0.0 0 0 ? S 15:55 0:00 [nfsd]
root 29125 0.0 0.0 0 0 ? S 15:55 0:00 [nfsd]
root 29142 0.0 0.1 4136 748 ttyS0 S+ 15:56 0:00 grep nfs
2.3 通過NFS網絡伺服器傳輸檔案
通過NFS網絡伺服器挂載,将檔案拷貝到闆子上:
1)在PC的虛拟機上安裝NFS用戶端:
$ sudo apt-get install nfs-common
2)将闆子的 /mnt/nfs 目錄挂載到PC虛拟機的 /mnt 目錄:
$ sudo mount -t nfs -o intr,nolock 192.168.4.113:/mnt/nfs /mnt
3)将PC虛拟機上編譯好的程式拷貝到闆子上:
$ sudo cp hello /mnt
在闆子上的/mnt/nfs目錄下就可以看到拷貝過來的程式了:
# ls /mnt
hello
在開發闆上運作程式,驗證程式是否可以在闆子上運作:
# ./hello
Hello world!
驗證成功,由交叉編譯工具編譯的程式在闆子上可以正常運作。
至此,基于全志H3晶片的開發環境搭建完成,可以進行開發工作了。