基於全志H3芯片的ARM開發環境搭建


基於全志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芯片的開發環境搭建完成,可以進行開發工作了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM