compile libsocketcan and canutils for Android 9
以下紀錄如何在 linux x86 64 unbutu 16.04下compile compile libsocketcan and canutils for Android 9\
==前置作業==
.下載及安裝 android-ndk-r20
因作業系統是 ubuntu 16.04屬於 linux,所以下載 android-ndk-r20-linux-x86_64.zip
解壓縮檔案,目錄為o:\tools\android-ndk-r20\
根據我的電腦環境,環境cross compile的環境變數
#=== Android P NDK env setup ==
export NDK=/home/bgbg2/tools/android-ndk-r20/toolchains/llvm
export TOOLCHAIN=$NDK/prebuilt/linux-x86_64
export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
==libsocketcan-0.0.11==
.從網站 https://public.pengutronix.de/software/libsocketcan/ 下載 libsocketcan-0.0.11
務必下載 libsocketcan-0.0.11 ,因為此版才有支援 aarch64-linux-android
解壓縮到目錄 o:\tools\test1\libsocketcan-0.0.11\
切換到此o:\tools\test1\libsocketcan-0.0.11\目錄內,mkdir out 建立 out folder,但不要切換進去,維持在o:\tools\test1\libsocketcan-0.0.11\
執行環境設定
export NDK=/home/bgbg2/tools/android-ndk-r20/toolchains/llvm
export TOOLCHAIN=$NDK/prebuilt/linux-x86_64
export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
執行 configure
#./configure --host=aarch64-linux-android --prefix=/home/bgbg2/tools/test1/libsocketcan-0.0.11/out
#make
#make install
檔案產生在 o:\tools\test1\libsocketcan-0.0.11\out\lib\libsocketcan.a libsocketcan.la libsocketcan.so pkgconfig
使用 file libsocketcan.so 檢查檔案elf格式
--
file libsocketcan.so
libsocketcan.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, not stripped
--
確定檔案的確為 ARM 64 for Android.
==canutils-4.0.6==
至網站 https://public.pengutronix.de/software/socket-can/canutils/v4.0/ 下載canutils-4.0.6.tar.bz2
解壓縮 tar -xvf canutils-4.0.6.tar.bz2 到路徑 /tools/test1/canutils-4.0.6
如果直接執行 configure
./configure --host=aarch64-linux-android --prefix=/home/bgbg2/tools/test1/canutils-4.0.6/out libsocketcan_LIBS=-lsocketcan LDFLAGS=-L/home/bgbg2/tools/test1/libsocketcan-0.0.11/out/lib libsocketcan_CFLAGS=-I/home/bgbg2/tools/test1/libsocketcan-0.0.11/out/include CFLAGS=-I/home/bgbg2/tools/test1/libsocketcan-0.0.11/out/include
會出現
configure: WARNING: If you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be used.
checking build system type... x86_64-unknown-linux-gnu
checking host system type... Invalid configuration `aarch64-linux-android': machine `aarch64-linux' not recognized
configure: error: /bin/sh config/autoconf/config.sub aarch64-linux-android failed
錯誤訊息
為了讓 canutils-4.0.6 也支援 arm android 9,必須
複製 "O:\tools\test1\libsocketcan-0.0.11\config\autoconf\config.sub" 到 "O:\tools\test1\canutils-4.0.6\config\autoconf\config.sub"
在 /tools/test1/canutils-4.0.6 目錄下執行 ./autogen.sh
修改"O:\tools\test1\canutils-4.0.6\configure"
去掉 line 4602
--
PKG_CHECK_MODULES(libsocketcan,
libsocketcan >= 0.0.8,
,
AC_MSG_ERROR([*** libsocketcan version above 0.0.8 not found on your system]))
---
執行環境設定
export NDK=/home/bgbg2/tools/android-ndk-r20/toolchains/llvm
export TOOLCHAIN=$NDK/prebuilt/linux-x86_64
export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
執行 configure
./configure --host=aarch64-linux-android --prefix=/home/bgbg2/tools/test1/canutils-4.0.6/out libsocketcan_LIBS=-lsocketcan LDFLAGS=-L/home/bgbg2/tools/test1/libsocketcan-0.0.11/out/lib libsocketcan_CFLAGS=-I/home/bgbg2/tools/test1/libsocketcan-0.0.11/out/include CFLAGS=-I/home/bgbg2/tools/test1/libsocketcan-0.0.11/out/include
#make
#make install
檔案產生在/tools/test1/canutils-4.0.6/out/bin/candump canecho cansend cansequence
file candump
candump: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/, not stripped
確定檔案的確為 ARM 64 for Android.
---在Android 9上測試--
adb root
adb disable-verity
adb reboot
adb push canconfig /vendor/bin
adb push libsocketcan.so/vendor/bin
export LD_LIBRARY_PATH=/vendor/bin
adb chmod 777 /vendor/bin/canconfig
adb chmod 777 /vendor/bin/libsocketcan.so
canconfig
show
---
usage:
canconfig <dev> bitrate { BR } [sample-point { SP }]
BR := <bitrate in Hz>
SP := <sample-point {0...0.999}> (optional)
canconfig <dev> bittiming [ VALs ]
VALs := <tq | prop-seg | phase-seg1 | phase-seg2 | sjw>
tq <time quantum in ns>
prop-seg <no. in tq>
phase-seg1 <no. in tq>
phase-seg2 <no. in tq
sjw <no. in tq> (optional)
canconfig <dev> restart-ms { RESTART-MS }
RESTART-MS := <autorestart interval in ms>
canconfig <dev> ctrlmode { CTRLMODE }
CTRLMODE := <[loopback | listen-only | triple-sampling | berr-reporting] [on|off]>
canconfig <dev> {ACTION}
ACTION := <[start|stop|restart]>
canconfig <dev> clockfreq
canconfig <dev> bittiming-constants
canconfig <dev> berr-counter
---
應該就可以順利在 android 9上面執行了
文章標籤
全站熱搜
留言列表