通过Simplicity Studio生成的Host工程,支持在编译时选择是否依赖readline等库接口,具体是否使用这些外部so库,通过make中加入相应选项指定即可。
编译参数:
make COMPILER=aarch64-openwrt-linux-gcc LINKER=aarch64-openwrt-linux ARCHIVE=aarch64-openwrt-linux-gcc-ar COMPILER_FLAGS="-std=gnu11" LINKER_FLAGS="-lm -ldl -lpthread -lrt" LD=aarch64-openwrt-linux-gcc NO_READLINE=1
编译过程中遇到问题报错如下:
readline相关库
,因为加入了NO_READLINE=1
选项)book@ubuntu ~/zigbeehost/v2.7/app/build/ZigbeeGatewayHost [master]$ make COMPILER=aarch64-openwrt-linux-gcc LINKER=aarch64-openwrt-linux ARCHIVE=aarch64-openwrt-linux-gcc-ar COMPILER_FLAGS="-std=gnu11" LINKER_FLAGS="-lm -ldl -lpthread -lrt" LD=aarch64-openwrt-linux-gcc NO_READLINE=1
aarch64-openwrt-linux-gcc -I./ -I./../../.. -I./../../../protocol/zigbee/app/framework -I./../../../protocol/zigbee/app/framework/../.. -I./../../../protocol/zigbee/app/framework/../../stack -I./../../../protocol/zigbee/app/framework/../util -I./../../../protocol/zigbee/app/framework/../util/common -I./../../../protocol/zigbee/app/framework/../util/ezsp -I./../../../protocol/zigbee/app/framework/../util/serial -I./../../../protocol/zigbee/app/framework/../util/zigbee-framework -I./../../../protocol/zigbee/app/framework/cli -I./../../../protocol/zigbee/app/framework/include -I./../../../protocol/zigbee/app/framework/security -I./../../../protocol/zigbee/app/framework/util -I./ZigbeeGatewayHost -I./../../../platform/base/hal -I./../../../platform/base/hal/plugin -I./../../../platform/base/hal/.. -I./../../../platform/base/hal/micro/generic -I./../../../platform/base/hal/micro/unix/host -I../../../platform/base/hal/micro/unix/host/board -I../../../util/plugin/plugin-common/mbedtls -I../../../util/third_party/mbedtls -I../../../util/third_party/mbedtls/include -I../../../util/third_party/mbedtls/include/mbedtls -I../../../util/third_party/mbedtls/sl_crypto/include -I~/hi-wooya/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/include/readline -DUNIX -DUNIX_HOST -DPHY_NULL -DCONFIGURATION_HEADER=\"../../../protocol/zigbee/app/framework/util/config.h\" -DEZSP_HOST -DGATEWAY_APP -DZA_GENERATED_HEADER=\"./ZigbeeGatewayHost.h\" -DATTRIBUTE_STORAGE_CONFIGURATION=\"./ZigbeeGatewayHost_endpoint_config.h\" -DPLATFORM_HEADER=\"../../../platform/base/hal/micro/unix/compiler/gcc.h\" -DBOARD_HOST -DBOARD_HEADER=\"ZigbeeGatewayHost_board.h\" -DEM_AF_TEST_HARNESS_CODE -DEM_AF_LINK_M -DEM_AF_LINK_PTHREAD -DEMBER_AF_API_EMBER_TYPES=\"stack/include/ember-types.h\" -DEMBER_AF_API_DEBUG_PRINT=\"app/framework/util/print.h\" -DEMBER_AF_API_AF_HEADER=\"app/framework/include/af.h\" -DEMBER_AF_API_AF_SECURITY_HEADER=\"app/framework/security/af-security.h\" -DEMBER_AF_API_NEIGHBOR_HEADER=\"stack/include/stack-info.h\" -DEMBER_STACK_ZIGBEE -DEZSP_ASH -DMBEDTLS_CONFIG_FILE=\"mbedtls-config-generated.h\" -std=gnu11 -MMD -MP -MF build/znet-bookkeeping.d -DNO_READLINE -c znet-bookkeeping.c -o build/znet-bookkeeping.o
In file included from znet-bookkeeping.c:5:0:
../../../platform/base/hal/micro/unix/compiler/gcc.h:107:6: error: #error endianess not defined
#error endianess not defined
^
Makefile:437: recipe for target 'build/znet-bookkeeping.o' failed
make: *** [build/znet-bookkeeping.o] Error 1
book@ubuntu ~/zigbeehost/v2.7/app/build/ZigbeeGatewayHost [master]$
在../../../platform/base/hal/micro/unix/compiler/gcc.h
文件新增aarch64架构定义,在原有defined(arm)后边新增defined(aarch64)
#ifdef DOXYGEN_SHOULD_SKIP_THIS
#define BIGENDIAN_CPU false
#else
#if defined(__i386__)
#define BIGENDIAN_CPU false
#elif defined(__ARM7__)
#define BIGENDIAN_CPU false
#elif defined(__x86_64__)
#define BIGENDIAN_CPU false
#elif defined(__arm__) || defined(__aarch64__)
#if defined(__BIG_ENDIAN)
#define BIGENDIAN_CPU true
#else
#define BIGENDIAN_CPU false
#endif
#elif defined(__LITTLE_ENDIAN__)
#define BIGENDIAN_CPU false
#elif defined(__BIG_ENDIAN__)
#define BIGENDIAN_CPU true
#elif defined(__APPLE__)
#define BIGENDIAN_CPU true
#elif defined(__mips__)
#if defined(__BIG_ENDIAN)
#define BIGENDIAN_CPU true
#else
#define BIGENDIAN_CPU false
#endif
#else
#error endianess not defined
#endif
#endif
aarch64-openwrt-linux-gcc -I./ -I./../../.. -I./../../../protocol/zigbee/app/framework -I./../../../protocol/zigbee/app/framework/../.. -I./../../../protocol/zigbee/app/framewor
k/../../stack -I./../../../protocol/zigbee/app/framework/../util -I./../../../protocol/zigbee/app/framework/../util/common -I./../../../protocol/zigbee/app/framework/../util/ezsp
-I./../../../protocol/zigbee/app/framework/../util/serial -I./../../../protocol/zigbee/app/framework/../util/zigbee-framework -I./../../../protocol/zigbee/app/framework/cli -I./
../../../protocol/zigbee/app/framework/include -I./../../../protocol/zigbee/app/framework/security -I./../../../protocol/zigbee/app/framework/util -I./ZigbeeGatewayHost -I./../..
/../platform/base/hal -I./../../../platform/base/hal/plugin -I./../../../platform/base/hal/.. -I./../../../platform/base/hal/micro/generic -I./../../../platform/base/hal/micro/un
ix/host -I../../../platform/base/hal/micro/unix/host/board -I../../../util/plugin/plugin-common/mbedtls -I../../../util/third_party/mbedtls -I../../../util/third_party/mbedtls/in
clude -I../../../util/third_party/mbedtls/include/mbedtls -I../../../util/third_party/mbedtls/sl_crypto/include -I~/hi-wooya/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_u
Clibc-0.9.33.2/usr/include/readline -DUNIX -DUNIX_HOST -DPHY_NULL -DCONFIGURATION_HEADER=\"../../../protocol/zigbee/app/framework/util/config.h\" -DEZSP_HOST -DGATEWAY_APP -DZA
_GENERATED_HEADER=\"./ZigbeeGatewayHost.h\" -DATTRIBUTE_STORAGE_CONFIGURATION=\"./ZigbeeGatewayHost_endpoint_config.h\" -DPLATFORM_HEADER=\"../../../platform/base/hal/micro/unix/
compiler/gcc.h\" -DBOARD_HOST -DBOARD_HEADER=\"ZigbeeGatewayHost_board.h\" -DEM_AF_TEST_HARNESS_CODE -DEM_AF_LINK_M -DEM_AF_LINK_PTHREAD -DEMBER_AF_API_EMBER_TYPES=\"stack/includ
e/ember-types.h\" -DEMBER_AF_API_DEBUG_PRINT=\"app/framework/util/print.h\" -DEMBER_AF_API_AF_HEADER=\"app/framework/include/af.h\" -DEMBER_AF_API_AF_SECURITY_HEADER=\"app/framew
ork/security/af-security.h\" -DEMBER_AF_API_NEIGHBOR_HEADER=\"stack/include/stack-info.h\" -DEMBER_STACK_ZIGBEE -DEZSP_ASH -DMBEDTLS_CONFIG_FILE=\"mbedtls-config-generated.h\" -
std=gnu11 -MMD -MP -MF build/ezsp.d -DNO_READLINE -c ../../../protocol/zigbee/app/util/ezsp/ezsp.c -o build/ezsp.o
aarch64-openwrt-linux-gcc -I./ -I./../../.. -I./../../../protocol/zigbee/app/framework -I./../../../protocol/zigbee/app/framework/../.. -I./../../../protocol/zigbee/app/framewor
k/../../stack -I./../../../protocol/zigbee/app/framework/../util -I./../../../protocol/zigbee/app/framework/../util/common -I./../../../protocol/zigbee/app/framework/../util/ezsp
-I./../../../protocol/zigbee/app/framework/../util/serial -I./../../../protocol/zigbee/app/framework/../util/zigbee-framework -I./../../../protocol/zigbee/app/framework/cli -I./
../../../protocol/zigbee/app/framework/include -I./../../../protocol/zigbee/app/framework/security -I./../../../protocol/zigbee/app/framework/util -I./ZigbeeGatewayHost -I./../..
/../platform/base/hal -I./../../../platform/base/hal/plugin -I./../../../platform/base/hal/.. -I./../../../platform/base/hal/micro/generic -I./../../../platform/base/hal/micro/un
ix/host -I../../../platform/base/hal/micro/unix/host/board -I../../../util/plugin/plugin-common/mbedtls -I../../../util/third_party/mbedtls -I../../../util/third_party/mbedtls/in
clude -I../../../util/third_party/mbedtls/include/mbedtls -I../../../util/third_party/mbedtls/sl_crypto/include -I~/hi-wooya/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_u
Clibc-0.9.33.2/usr/include/readline -DUNIX -DUNIX_HOST -DPHY_NULL -DCONFIGURATION_HEADER=\"../../../protocol/zigbee/app/framework/util/config.h\" -DEZSP_HOST -DGATEWAY_APP -DZA
_GENERATED_HEADER=\"./ZigbeeGatewayHost.h\" -DATTRIBUTE_STORAGE_CONFIGURATION=\"./ZigbeeGatewayHost_endpoint_config.h\" -DPLATFORM_HEADER=\"../../../platform/base/hal/micro/unix/
compiler/gcc.h\" -DBOARD_HOST -DBOARD_HEADER=\"ZigbeeGatewayHost_board.h\" -DEM_AF_TEST_HARNESS_CODE -DEM_AF_LINK_M -DEM_AF_LINK_PTHREAD -DEMBER_AF_API_EMBER_TYPES=\"stack/includ
e/ember-types.h\" -DEMBER_AF_API_DEBUG_PRINT=\"app/framework/util/print.h\" -DEMBER_AF_API_AF_HEADER=\"app/framework/include/af.h\" -DEMBER_AF_API_AF_SECURITY_HEADER=\"app/framew
ork/security/af-security.h\" -DEMBER_AF_API_NEIGHBOR_HEADER=\"stack/include/stack-info.h\" -DEMBER_STACK_ZIGBEE -DEZSP_ASH -DMBEDTLS_CONFIG_FILE=\"mbedtls-config-generated.h\" -
std=gnu11 -MMD -MP -MF build/ezsp-host-io.d -DNO_READLINE -c ../../../protocol/zigbee/app/ezsp-host/ezsp-host-io.c -o build/ezsp-host-io.o
../../../protocol/zigbee/app/ezsp-host/ezsp-host-io.c: In function 'ezspSetupSerialPort':
../../../protocol/zigbee/app/ezsp-host/ezsp-host-io.c:254:25: error: 'CSTART' undeclared (first use in this function)
tios.c_cc[VSTART] = CSTART; // define XON and XOFF
^
../../../protocol/zigbee/app/ezsp-host/ezsp-host-io.c:254:25: note: each undeclared identifier is reported only once for each function it appears in
../../../protocol/zigbee/app/ezsp-host/ezsp-host-io.c:255:24: error: 'CSTOP' undeclared (first use in this function)
tios.c_cc[VSTOP] = CSTOP;
^
Makefile:437: recipe for target 'build/ezsp-host-io.o' failed
make: *** [build/ezsp-host-io.o] Error 1
book@ubuntu ~/zigbeehost/v2.7/app/build/ZigbeeGatewayHost [master]$
解决:添加NO_READLINE=1
make COMPILER=aarch64-openwrt-linux-gcc LINKER=aarch64-openwrt-linux ARCHIVE=aarch64-openwrt-linux-gcc-ar COMPILER_FLAGS="-std=gnu11" LINKER_FLAGS="-lm -ldl -lpthread -lrt" LD=aarch64-openwrt-linux-gcc NO_READLINE=1
此方式编译遇到的问题如下
NO_READLINE=1
选项,使用libreadline.so
相关库,并在此基础上新增了-lreadline 和 -lncurses
选项aarch64-openwrt-linux-gcc -I./ -I./../../.. -I./../../../protocol/zigbee/app/framework -I./../../../protocol/zigbee/app/framework/../.. -I./../../../protocol/zigbee/
app/framework/../../stack -I./../../../protocol/zigbee/app/framework/../util -I./../../../protocol/zigbee/app/framework/../util/common -I./../../../protocol/zigbee/ap
p/framework/../util/ezsp -I./../../../protocol/zigbee/app/framework/../util/serial -I./../../../protocol/zigbee/app/framework/../util/zigbee-framework -I./../../../pr
otocol/zigbee/app/framework/cli -I./../../../protocol/zigbee/app/framework/include -I./../../../protocol/zigbee/app/framework/security -I./../../../protocol/zigbee/ap
p/framework/util -I./ZigbeeGatewayHost -I./../../../platform/base/hal -I./../../../platform/base/hal/plugin -I./../../../platform/base/hal/.. -I./../../../platform/ba
se/hal/micro/generic -I./../../../platform/base/hal/micro/unix/host -I../../../platform/base/hal/micro/unix/host/board -I../../../util/plugin/plugin-common/mbedtls -I
../../../util/third_party/mbedtls -I../../../util/third_party/mbedtls/include -I../../../util/third_party/mbedtls/include/mbedtls -I../../../util/third_party/mbedtls/sl_crypto/include -I~/hi-wooya/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/include/readline -DUNIX -DUNIX_HOST -DPHY_NULL -DCONFIGURATIO
N_HEADER=\"../../../protocol/zigbee/app/framework/util/config.h\" -DEZSP_HOST -DGATEWAY_APP -DZA_GENERATED_HEADER=\"./ZigbeeGatewayHost.h\" -DATTRIBUTE_STORAGE_CONFIG
URATION=\"./ZigbeeGatewayHost_endpoint_config.h\" -DPLATFORM_HEADER=\"../../../platform/base/hal/micro/unix/compiler/gcc.h\" -DBOARD_HOST -DBOARD_HEADER=\"ZigbeeGatew
ayHost_board.h\" -DEM_AF_TEST_HARNESS_CODE -DEM_AF_LINK_M -DEM_AF_LINK_PTHREAD -DEMBER_AF_API_EMBER_TYPES=\"stack/include/ember-types.h\" -DEMBER_AF_API_DEBUG_PRINT=\
"app/framework/util/print.h\" -DEMBER_AF_API_AF_HEADER=\"app/framework/include/af.h\" -DEMBER_AF_API_AF_SECURITY_HEADER=\"app/framework/security/af-security.h\" -DEMB
ER_AF_API_NEIGHBOR_HEADER=\"stack/include/stack-info.h\" -DEMBER_STACK_ZIGBEE -DEZSP_ASH -DMBEDTLS_CONFIG_FILE=\"mbedtls-config-generated.h\" -std=gnu11 -MMD -MP -MF
build/linux-serial.d -c ../../../protocol/zigbee/app/util/serial/linux-serial.c -o build/linux-serial.o
../../../protocol/zigbee/app/util/serial/linux-serial.c:47:51: fatal error: readline/readline.h: No such file or directory
compilation terminated.
Makefile:437: recipe for target 'build/linux-serial.o' failed
make: *** [build/linux-serial.o] Error 1
book@ubuntu ~/zigbeehost/v2.7/app/build/ZigbeeGatewayHost [master]$
通过COMPILER_INCLUDES
指定readline/readline.h
文件所在头文件路径
查找头文件:
book@ubuntu ~/qca/qsdk [vcpe_dev]$ find -name readline.h ./build_dir_bak/target-arm_cortex-a7_musl-1.1.16_eabi/gdb-7.8/readline/readline.h
./build_dir_bak/target-arm_cortex-a7_musl-1.1.16_eabi/readline-6.3/ipkg-install/usr/include/readline/readline.h
./build_dir_bak/target-arm_cortex-a7_musl-1.1.16_eabi/readline-6.3/readline.h
./build_dir_bak/target-arm_cortex-a7_musl-1.1.16_eabi/bash-4.3/lib/readline/readline.h
./build_dir_bak/target-arm_cortex-a7_musl-1.1.16_eabi/samba-3.6.25/lib/replace/system/readline.h
./build_dir_bak/toolchain-arm_cortex-a7_gcc-5.2.0_musl-1.1.16_eabi/gdb-linaro-7.6-2013.05/readline/readline.h
选择工具链相关的路径
make COMPILER=aarch64-openwrt-linux-gcc LINKER=aarch64-openwrt-linux-gcc ARCHIVE=aarch64-openwrt-linux-ar COMPILER_FLAGS="-std=gnu11" LINKER_FLAGS="-lreadline -lncurses -lm -ldl -lpthread -lrt" LD=aarch64-openwrt-linux-gcc COMPILER_INCLUDES=-I../../../../../qca/qsdk/build_dir_bak/toolchain-arm_cortex-a7_gcc-5.2.0_musl-1.1.16_eabi/gdb-linaro-7.6-2013.05
ttribute-table.o build/client-api.o build/message.o build/multi-network.o build/print.o build/print-formatter.o build/process-cluster-message.o build/process-global-message.o build/service-discovery-common.o build/time-util.o build/util.o build/af-main-host.o build/service-discovery-host.o -lreadline -lncurses -lm -ldl -lpthread -lrt -o ./build/exe/ZigbeeGatewayHost
/data1/yehe/qca/qsdk/staging_dir/toolchain-aarch64_cortex-a53_gcc-5.2.0_musl-1.1.16/lib/gcc/aarch64-openwrt-linux-musl/5.2.0/../../../../aarch64-openwrt-linux-musl/bin/ld: cannot find -lreadline
/data1/yehe/qca/qsdk/staging_dir/toolchain-aarch64_cortex-a53_gcc-5.2.0_musl-1.1.16/lib/gcc/aarch64-openwrt-linux-musl/5.2.0/../../../../aarch64-openwrt-linux-musl/bin/ld: cannot find -lncurses
collect2: error: ld returned 1 exit status
Makefile:406: recipe for target 'build/exe/ZigbeeGatewayHost' failed
make: *** [build/exe/ZigbeeGatewayHost] Error 1
make: write error: stdout
book@ubuntu ~/zigbeehost/v2.7/app/build/ZigbeeGatewayHost [master]$
查找libreadline.so、libncurses.so
库路径
解决:
make COMPILER=aarch64-openwrt-linux-gcc LINKER=aarch64-openwrt-linux-gcc ARCHIVE=aarch64-openwrt-linux-ar COMPILER_FLAGS="-std=gnu11" LINKER_FLAGS="-lreadline -lncurses -lm -ldl -lpthread -lrt" LD="aarch64-openwrt-linux-gcc -L../../../../../qca/qsdk/staging_dir/target-aarch64_cortex-a53_musl-1.1.16/usr/lib" COMPILER_INCLUDES=-I../../../../../qca/qsdk/build_dir_bak/toolchain-arm_cortex-a7_gcc-5.2.0_musl-1.1.16_eabi/gdb-linaro-7.6-2013.05
root@book:~# ./ZigbeeGatewayHost -f x -b 115200 -p /dev/ttyMSM2
Reset info: 11 (SOFTWARE)
ERROR: ezspForceReset 0x21
Assertion failed: false (../../../protocol/zigbee/app/framework/util/af-main-host.c: emAfResetAndInitNCP: 344)
Aborted
root@book:~# ZigbeeGatewayHost>Child process for serial input got EOF. Exiting
root@viomi:~#
原因:函数emAfResetAndInitNCP返回了错误