本文以can-utils为例,讲述如何将can-utils集成到你的Openharmony系统
1.下载can-utils源码
通过下面命令将can-utils源码下载至Openharmony源码的third_party
cd third_party
git clone https://github.com/linux-can/can-utils.git can-utils
2. 创建BUILD.gn文件
在当前目录创建一个BUILD.gn文件, 来定义如何编译can-utils模块. 我们目前只编译了常用命令
import("//build/ohos.gni")config("can_utils_config") {include_dirs = [ ".", "include" ]defines = ["AF_CAN=PF_CAN","PF_CAN=29","SO_RXQ_OVFL=40","SCM_TIMESTAMPING_OPT_STATS=54","CLOCK_TAI=11","SO_TXTIME=61","SCM_TXTIME=SO_TXTIME","_FILE_OFFSET_BITS=64","_GNU_SOURCE",]
}# 用于收集所有命令 target 名称
cmd_targets = []foreach(cmd, [ "candump", "cansend", "cangen", "canplayer", "canbusload", "canerrsim", "canfdtest", "cansequence", "cansniffer"]) {ohos_executable(cmd) {sources = ["${cmd}.c","lib.c",]if (cmd == "canbusload") {sources += [ "canframelen.c" ]}configs = [ ":can_utils_config" ]install_enable = trueinstall_images = [ "system" ]part_name = "can-utils"subsystem_name = "thirdparty"}cmd_targets += [ ":$cmd" ]
}# 统一导出的 target:can-utils
group("can-utils") {deps = cmd_targets
}
3.创建bound.json
在当前目录创建一个元数据文件bound.json. 用来注册和描述can-utils组件
{"name": "can-utils","version": "1.0.0","publishAs": "code-segment","component": {"name": "can-utils","subsystem": "thirdparty","syscap": [],"features": [],"adapted_system_type": ["standard"],"rom": "100KB","ram": "100KB","deps": {"components": [],"third_party": []},"build": {"sub_component": ["//third_party/can-utils:can-utils"],"inner_kits": [],"test": []}}
}
4.将can-utils添加进编译系统
在平台代码中将can-utils模块添加进编译系统
我们的平台代码的位置为:vendor/hihope/rk3568/config.json
我们需要修改该文件添加以下内容:
@@ -264,6 +264,16 @@]}]
+ },
+ {
+ "subsystem": "thirdparty",
+ "components": [
+ {
+ "component": "can-utils",
+ "features": []
+ }
+ ]
+}]}