交叉编译阿里云iotkit-embedded
(基于Ubuntu的iot sdk)
1.环境
1.1开发环境
系统版本:Ubuntu14.04
编译工具链:arm-linux-gcc version 4.4.1 (Sourcery G++ Lite 2009q3-67)
1.2目标机
board:x210
cpu:S5PV210
1.3iotkit-embedded版本
iotkit-embedded-RELEASED_V2_01_20171010(最新的版本在platform/os下是没有源码的,只有静态库的)
2.步骤
2.1大概思路
将编译器PLATFORM_CC由gcc替换为linux-arm-gcc,将链接器PLATFORM_AR由ar替换为arm-linux-ar。然后单独编译HAL_OS_linux.c HAL_TCP_linux.c HAL_UDP_linux.c这三个文件,生成对应的静态库A,最后再进入output/release/src目录下编译对应的sample同时链接A。
2.2具体操作
(1)修改make.settings
vim make.settings
BUILD_TYPE = debug
#PLATFORM_CC = gcc
#PLATFORM_AR = ar
PLATFORM_OS = linux
#
# Uncomment below and specify PATH to your toolchain when cross-compile SDK
#
# PLATFORM_CC = /home/edward/cached-toolchains/jcg.7620/bin/mipsel-linux-gcc
# PLATFORM_AR = /home/edward/cached-toolchains/jcg.7620/bin/mipsel-linux-ar
PLATFORM_CC = arm-linux-gcc
PLATFORM_AR = arm-linux-ar
FEATURE_MQTT_COMM_ENABLED = y
FEATURE_MQTT_DIRECT = y
FEATURE_MQTT_DIRECT_NOTLS = y
FEATURE_COAP_COMM_ENABLED = y
FEATURE_OTA_ENABLED = y
FEATURE_OTA_SIGNAL_CHANNEL = COAP
在iot_import.h中添加#define IOTX_WITHOUT_TLS宏如果不添加该宏则需要另外编译ssl部分+mbedtls
#ifndef IOTX_WITHOUT_TLS
#define IOTX_WITHOUT_TLS
#endif
#ifndef MQTT_DIRECT
#define MQTT_DIRECT //是否用MQTT直连模式代替HTTPS三方认证模式做设备认证
#endif
#ifndef MQTT_COMM_ENABLED
#define MQTT_COMM_ENABLED //是否使能MQTT通道功能的总开关
#endif
(2)配置、编译
make config
make -j4
(3)进入output/release/目录下,准备编译生成平台对应的静态库文件
cd output/release
mkdir linux_os
cp ../../src/platform/os/linux/*.c ./linux_os/
cd linux_os
vim Makefile
编写linux_os下的Makefile,可以参考我的
.PHONY: all
CC := arm-linux-gcc
AR := arm-linux-ar
CFLAGS := -I../include
CFLAGS += -I../include/iot-sdk
CFLAGS += -I../include/mbedtls
CFLAGS += -I../include/iot-sdk/imports/
all ::
$(CC) $(CFLAGS) -c HAL_OS_linux.c HAL_TCP_linux.c HAL_UDP_linux.c
$(AR) -r libiot_platform_zyg.a HAL_OS_linux.o HAL_TCP_linux.o HAL_UDP_linux.o
cp libiot_platform_zyg.a /home/scorpio/iotkit-embedded-RELEASED_V2_01_20171010/output/release/lib/ -rf
clean ::
rm *.o *.a
(4)开始编译例子
cd ../src
修改Makefile
.PHONY: all
CC := arm-linux-gcc
CFLAGS := -I../include
CFLAGS += -I../include/iot-sdk
CFLAGS += -I../include/mbedtls
CFLAGS += -I../include/iot-sdk/imports/
LDFLAGS := -L../lib/
#LDFLAGS += -liot_sdk -liot_platform
#LDFLAGS += -Bstatic -lmbedtls -lmbedx509 -lmbedcrypto
#LDFLAGS += -lgcov
LDFLAGS += ../lib/libiot_sdk.a ../lib/libiot_platform_zyg.a
#LDFLAGS += ../lib/libiot_sdk.a ../lib/libmbedx509.a ../lib/libmbedtls.a ../lib/libmbedcrypto.a ../lib/libmqtt.a ../lib/libhttp.a ../lib/libsystem.a
LDFLAGS += -lgcov
all ::
$(CC) $(CFLAGS) -o ext.mqtt mqtt-example.c $(LDFLAGS)
clean ::
rm -vf ext.mqtt
#all ::
# $(CC) $(CFLAGS) -o ext.coap coap-example.c $(LDFLAGS)
#clean ::
# rm -vf ext.coap
#all ::
# $(CC) $(CFLAGS) -o ext.http http-example.c $(LDFLAGS)
#clean ::
# rm -vf ext.http
修改完成后 make 即可
(4)将目标文件同步到开发板上
file ext.mqtt 查看文件的信息
ext.mqtt: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped
将程序放置在x210开发板上即可正常运行
注:
为了方便下次的操作,运行成功后可以选择将整个release文件夹copy出来,然后下次直接在release/src中修改对应的.c文件即可。