OpenHarmony之hdc
OpenHarmony之hdc
简介
hdc(OpenHarmony Device Connector)是 OpenHarmony 为开发人员提供的用于调试的命令行工具,通过该工具可以在Windows/Linux/MacOS等系统上与开发机或者模拟器进行交互。
类似于Android的adb,和adb类似,使用hdc的前提是开发机器hdc工具已安装好,设备端hdc已安装且已配置好。
开发机HDC
开发机hdc工具通过OpenHarmony sdk获取,hdc在sdk的 toolchains
目录下
从官方每日构建版本(http://ci.openharmony.cn/workbench/cicd/dailybuild/dailylist)里下载对应分支的SDK,
这里我对应的是OpenHarmony-3.2-Release的 ohos-sdk-full
解压:
zdd@xxx-PC:~/WorkSpace/OHOS/ohos-sdk$ tree
.
├── linux
│ ├── ets-linux-x64-3.2.15.3-Release.zip
│ ├── js-linux-x64-3.2.15.3-Release.zip
│ ├── native-linux-x64-3.2.15.3-Release.zip
│ ├── previewer-linux-x64-3.2.15.3-Release.zip
│ └── toolchains-linux-x64-3.2.15.3-Release.zip
└── windows
├── ets-windows-x64-3.2.15.3-Release.zip
├── js-windows-x64-3.2.15.3-Release.zip
├── native-windows-x64-3.2.15.3-Release.zip
├── previewer-windows-x64-3.2.15.3-Release.zip
└── toolchains-windows-x64-3.2.15.3-Release.zip
根据自己使用的系统,继续解压对应的 toolchains
压缩包,hdc
等工具就在 toolchains
里面。
设备端HDC
设备端hdc工具一般会随编译构建打包进文件系统。
设备端配置分2种不同的通路:USB或网络
USB的话,主要保证USB能用能通(驱动OK),使能USB的
otg
模式或peripheral
模式,并通过configfs配置好usb相关的参数并启动对应服务,一般是用init的cfg文件来配,例如rk3588的为init.rk3568.usb.cfg
,这里不详细展开了{ "jobs" : [{ "name" : "boot", "cmds" : [ "mkdir /dev/usb-ffs 0770 shell shell", "mkdir /dev/usb-ffs/hdc 0770 shell shell", "mount configfs none /config", "mkdir /config/usb_gadget/g1 0770 shell shell", "write /config/usb_gadget/g1/idVendor 0x2207", "write /config/usb_gadget/g1/idProduct 0x0018", "write /config/usb_gadget/g1/os_desc/use 1", "write /config/usb_gadget/g1/bcdDevice 0x0223", "write /config/usb_gadget/g1/bcdUSB 0x0200", "mkdir /config/usb_gadget/g1/strings/0x409 0770", "copy /sys/block/mmcblk0/device/cid /config/usb_gadget/g1/strings/0x409/serialnumber", "write /config/usb_gadget/g1/strings/0x409/manufacturer Rockchip", "write /config/usb_gadget/g1/strings/0x409/product \"HDC Device\"", "mkdir /config/usb_gadget/g1/functions/ffs.hdc", "mkdir /config/usb_gadget/g1/configs/b.1 0770 shell shell", "mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770 shell shell", "write /config/usb_gadget/g1/os_desc/b_vendor_code 0x1", "write /config/usb_gadget/g1/os_desc/qw_sign MSFT100", "write /config/usb_gadget/g1/configs/b.1/MaxPower 500", "symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b.1", "mount functionfs hdc /dev/usb-ffs/hdc uid=2000,gid=2000", "setparam sys.usb.configfs 1", "setparam sys.usb.controller fcc00000.dwc3" ] }, { "name" : "param:sys.usb.config=none && param:sys.usb.configfs=1", "condition" : "sys.usb.config=none && sys.usb.configfs=1", "cmds" : [ "write /config/usb_gadget/g1/os_desc/use 0", "setparam sys.usb.ffs.ready 0" ] }, { "name" : "param:init.svc.hdcd=stopped", "condition" : "init.svc.hdcd=stopped", "cmds" : [ "setparam sys.usb.ffs.ready 0" ] }, { "name" : "param:sys.usb.config=hdc && param:sys.usb.configfs=1", "condition" : "sys.usb.config=hdc && sys.usb.configfs=1", "cmds" : [ "write /config/usb_gadget/g1/idProduct 0x5000", "write /config/usb_gadget/g1/os_desc/use 1" ] } ] }
网络的话,主要保证网络能用能通(驱动OK),配置好网络IP等,设置hdc参数(主要是模式和端口),并启动hdcd服务,通过命令的方式如下,也可通过配置文件的方式:
# 设置hdc参数 param set persist.hdc.mode tcp param set persist.hdc.port xxxx # 启动hdcd服务 hdcd &
一些常用命令
当两端都配置好之后就可以愉快地使用hdc工具了,下面列举了一些常用的命令,更多说明详见官方文档或help:
#查询设备列表(-v 打印设备详细信息)
hdc list targets[-v]
#通过【ip地址:端口号】来连接指定的设备(-remove 断开与指定设备的连接)
hdc tconn host[:port][-remove]
#设备端对应daemon进程重启,并首先选用USB连接方式
hdc tmode usb
#调试
hdc shell
hdc hilog
#以读写模式挂载系统分区
hdc target mount
#设备重启
hdc target boot
#授予后台服务进程root权限, 使用-r参数取消授权
hdc smode
hdc smode -r
#发送文件至远端设备
hdc file send ./a.txt /data/local/tmp/a.txt
#从远端设备接收文件至本地
hdc file recv /data/local/tmp/a.txt ./a.txt
#安装HAP(-r 替换已存在应用 -d 允许降级安装 -g 应用动态授权)
hdc install [-r/-d/-g] package
#卸载HAP -k 保留/data/cache
hdc uninstall [-k] package
参考
http://docs.openharmony.cn/pages/v4.0/zh-cn/device-dev/subsystems/subsys-toolchain-hdc-guide.md/