RK3568------Openharmony 3.2-Release HDC调试工具

RK3568------Openharmony 3.2-Release HDC调试工具


前言

随着Openharmony设备开发的深入研究,我们有了调测工具的需求。在官网 HDC使用指导中,OHOS 官网向我们提供了调测工具,在前文《RK3568------Openharmony 3.2-Release 文件系统打包》中我们有提到过该工具,但是当时对Openharmony的学习还不够深入,暂时搁置了,今天我们针对HDC的使用以及遇到的问题,做一个总结。

一、HDC使用

根据官网的介绍,HDC连接设备有两种方式(实际上还有Uart方式,后面源码分析详解),USB和TCP。如果链接正常,直接连接即可(具体命令参数使用hdc -h详细介绍)

                         OpenHarmony device connector(HDC) ...

---------------------------------global commands:----------------------------------
 -h/help                               - Print hdc help
 -v/version                            - Print hdc version
 -l 0-5                                - Set runtime loglevel
 -t connectkey                         - Use device with given connect key
 checkserver                           - check client-server version
 checkdevice                           - check server-daemon version

---------------------------------component commands:-------------------------------
session commands(on server):
 discover                              - Discover devices listening on TCP via LAN broadcast
 list targets [-v]                     - List all devices status, -v for detail
 tconn key                             - Connect device via key, TCP use ip:port
                                         example:192.168.0.100:10178/192.168.0.100
                                         USB connect automatic, TCP need to connect manually

                                         UART connect need connect manually.
                                         Baud Rate can be specified with commas.
                                         key format: <Port Name>[,Baud Rate]
                                         example: tconn COM5,921600
                                         Default Baud Rate is 921600.

 start [-r]                            - Start server. If with '-r', will be restart server
 kill [-r]                             - Kill server. If with '-r', will be restart server
 -s [ip:]port                          - Set hdc server listen config

service commands(on daemon):
 target mount                          - Set /system /vendor partition read-write
 target boot [-bootloader|-recovery]   - Reboot the device or boot into bootloader\recovery.
 target boot [MODE]                    - Reboot the into MODE.
 smode [-r]                            - Restart daemon with root permissions, '-r' to cancel root
                                         permissions
 tmode usb                             - Reboot the device, listening on USB
 tmode port [port]                     - Reboot the device, listening on TCP port

---------------------------------task commands:-------------------------------------
file commands:
 file send [option] local remote       - Send file to device
 file recv [option] remote local       - Recv file from device
                                         option is -a|-s|-z
                                         -a: hold target file timestamp
                                         -sync: just update newer file
                                         -z: compress transfer
                                         -m: mode sync

forward commands:
 fport localnode remotenode            - Forward local traffic to remote device
 rport remotenode localnode            - Reserve remote traffic to local host
                                         node config name format 'schema:content'
                                         examples are below:
                                         tcp:<port>
                                         localfilesystem:<unix domain socket name>
                                         localreserved:<unix domain socket name>
                                         localabstract:<unix domain socket name>
                                         dev:<device name>
                                         jdwp:<pid> (remote only)
 fport ls                              - Display forward/reverse tasks
 fport rm taskstr                      - Remove forward/reverse task by taskstring

app commands:
 install [-r] src                      - Send package(s) to device and install them
                                         src examples: single or multiple packages and directories
                                         (.hap)
                                         -r: replace existing application
 uninstall [-k] package                - Remove application package from device
                                         -k: keep the data and cache directories

debug commands:
 hilog [-v]                            - Show device log, -v for detail
 shell [COMMAND...]                    - Run shell command (interactive shell if no command given)
 bugreport [PATH]                      - Return all information from the device, path will be save localpath
 jpid                                  - List pids of processes hosting a JDWP transport
 sideload [PATH]                       - Sideload the given full OTA package

security commands:
 keygen FILE                           - Generate public/private key; key stored in FILE and FILE.pub

---------------------------------flash commands:------------------------------------
flash commands:
 update packagename                    - Update system by package
 flash [-f] partition imagename        - Flash partition by image
 erase [-f] partition                  - Erase partition
 format [-f] partition                 - Format partition

二、HDC使用遇到的问题

大多数情况是第一次使用的同僚们,都会遇到各种各样的问题,下面详细介绍一下遇到的问题及解决思路

1. PC侧检侧不到设备

USB硬件
检查硬件,如果底板是自己画的,或者是不了解的底板,必须保证设备侧是USB从,才能被PC侧检测到

USB驱动
如果是自己的USB设备,要在内核启动日志中查看,USB的驱动是否加载成功

HDC版本不一致
根据官网的提示,要保证设备侧与PC侧的HDC版本一致,检查设备侧(hdcd -v)、PC侧(hdc -v)版本是否一致
HDC服务是否运行
根据官网的提示,要保证设备侧与PC侧的HDC服务正常启动

2. PC侧检测到设备,但是hdc list targets 却看不到设备(讨论群群友提供)

有的板子是emmc启动,有的板子是sd卡启动,因此mmcblk节点就不一样了。群友虽然也是emmc启动,但是群友的emmc 对应的节点是mmcblk1,根据(device/board/hihope/rk3568/cfg /init.rk3568.usb.cfg)配置文件:

在这里插入图片描述
可以看出,在配置中,HDC会根据启动设备的cid来为HCD提供识别ID。因为群友的emmc节点是mmcblk1,所以拷贝失败,导致无法生成HCD的ID,只需改成正确的节点路径即可。

3. 底板没有预留USB从设备,采用TCP方式连接无效

本人采用这种方式,一开始连接不上,官网描述不清楚,只是介绍使用 hdc tconn xxx.xxx.xxx.xxx:port连接,但是没有说如何配置port。针对以上情况,只能查看源码(//developtools/hdc)分析,根据源码发现,默认是只支持USB连接模式,需要设备侧开启TCP连接方式并且配置port,具体操作如下:
设备侧:

param set persist.hdc.mode tcp 重启生效
param set persist.hdc.port xxxx 重启生效
如果是实时生效 还可以在设备侧使用 hdcd -t 开启TCP模式

4 .持续补充…

三、HDC源码分析

源码路径(//developtools/hdc/src/daemon/main.cpp)
根据代码可知,支持3种模式 USB、TCP、UART
在这里插入图片描述
源码路径(//developtools/hdc/src/daemon/daemon_tcp.cpp)
根据源码可知,TCP需要配置port
在这里插入图片描述

四、效果展示

在这里插入图片描述


总结

本人之前一直从事应用开发,借着这次电鸿的契机进行系统级开发的学习,将我在工作中的遇到的问题及解决思路记录并分享,希望可以与诸君共勉
目前网上技术讨论群大都是鸿蒙的应用开发,总结此类文章也是希望将同样进行鸿蒙设备开发的同僚召集到一起,一起讨论学习。如果有同样在进行鸿蒙设备开发的朋友,可以加我的联系方式,期待您的消息
个人微信
在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值