当前位置: 首页 > news >正文

尝试给OpenHarmony4.0增加可以在动态库中使用的日志模块

尝试给OpenHarmony4.0增加可以在动态库中使用的日志模块

  • 前言
  • 一、资源来源
  • 二、实践步骤
    • 1.修改OH内核并编译
    • 2.动态库增加welog打印
    • 3.设备验证
    • 打完收工
  • 总结
  • 参考


前言

最近在搞OpenHarmony4.0蓝牙模块的适配,最主要的工作就是在libbt_vendor.z.so这个库的编写修改,该库上承HDF驱动,下接内核驱动。
目前卡在了该库中对蓝牙设备进行相关操作的接口,需要增加日志打印进行调试。但OpenHarmony的hilog貌似在动态库中加的日志并不能通过hilog命令在串口或者HDC中进行打印,所以想再加一套单独的日志打印途径。


一、资源来源

OpenHarmony单模块welog打印机制
打算使用该内容进行测试使用。
https://gitee.com/itopen/module_code/tree/master
验证后发现基本按README.md的使用指导进行即可,但有些小细节需要自己摸索。

二、实践步骤

1.修改OH内核并编译

将gitee资源对应目录C/welog/driver的welog文件夹直接放到OH版本的内核驱动目录下,本文使用的是RISCV架构的OH4.0-RVBOOK版本,对应的目录为:

kernel/linux/rvbook-kernel/drivers/

其他版本的内核驱动目录比如:

kernel/linux/linux-5.10/drivers/

然后对该目录下的Kconfig和Makefile进行修改,因为有顺序影响,为了避免麻烦,所以建议将新增的内容直接放到对应文件的靠后位置。
Kconfig文件新增此行:

source "drivers/welog/Kconfig"

Makefile文件新增此行

obj-y               += welog/

修改保存后,删除OH版本out目录下的kernel和对应产品生成的images目录下的内核镜像,使用下面命令进行内核编译(有些产品不需要加“–no-prebuilt-sdk”选项):

./build.sh --product-name rvbook --ccache --no-prebuilt-sdk -T build_kernel

2.动态库增加welog打印

将gitee上include目录下的welog.h放到能被libbt_vendor调用到的对应目录(查看BUILD.gn即可),在需要加入之的.c文件中进行#include引用。修改该.c文件,比如op()代码增加welog打印。
根据welog.h的内容,发现此日志模块支持welog_err、welog_info、welog_debug三种模式,使用这些直接代替标准化格式输出的printf即可。
比如:

static int op(bt_opcode_t opcode, void *param)
{welog_err("bluetooth op start!! %d", opcode);int retval = 0;switch (opcode) {case BT_OP_POWER_ON: // Power on the BT Controller.if (rtkbt_transtype & RTKBT_TRANS_UART) {upio_set_bluetooth_power(UPIO_BT_POWER_OFF);usleep(20000L);welog_err("set power off and delay 200ms");upio_set_bluetooth_power(UPIO_BT_POWER_ON);welog_err("set power on and delay 00ms");}break;case BT_OP_POWER_OFF: // Power off the BT Controller.if (rtkbt_transtype & RTKBT_TRANS_UART) {upio_set_bluetooth_power(UPIO_BT_POWER_OFF);usleep(20000L);welog_err("set power off and delay 200ms");}break;// Establish hci channels. it will be called after BT_OP_POWER_ON.case BT_OP_HCI_CHANNEL_OPEN: {welog_err("bluetooth open channel");if ((rtkbt_transtype & RTKBT_TRANS_UART) && (rtkbt_transtype & RTKBT_TRANS_H5)) {welog_err("bluetooth trans h5");int fd, idx;int(*fd_array)[] = (int(*)[])param;if (userial_vendor_open((tUSERIAL_CFG *)&userial_H5_cfg) != -1) {retval = 1;}fd = userial_socket_open();if (fd != -1) {for (idx = 0; idx < HCI_MAX_CHANNEL; idx++) {(*fd_array)[idx] = fd;}} else {retval = 0;}} else if ((rtkbt_transtype & RTKBT_TRANS_UART) && (rtkbt_transtype & RTKBT_TRANS_H4)) {welog_err("bluetooth trans h4");/* retval contains numbers of open fd of HCI channels */int(*fd_array)[] = (int(*)[])param;int fd, idx;if (userial_vendor_open((tUSERIAL_CFG *)&userial_H4_cfg) != -1) {retval = 1;}fd = userial_socket_open();if (fd != -1) {for (idx = 0; idx < HCI_MAX_CHANNEL; idx++) {(*fd_array)[idx] = fd;}} else {retval = 0;}/* retval contains numbers of open fd of HCI channels */} else {welog_err("bluetooth USB op for %d", opcode);int fd, idx = 0;int(*fd_array)[] = (int(*)[])param;for (idx = 0; idx < 10L; idx++) {if (userial_vendor_usb_open() != -1) {retval = 1;break;}}fd = userial_socket_open();if (fd != -1) {for (idx = 0; idx < HCI_MAX_CHANNEL; idx++) {(*fd_array)[idx] = fd;}} else {retval = 0;}}}break;// Close all the hci channels which is opened.case BT_OP_HCI_CHANNEL_CLOSE: {userial_vendor_close();}break;// initialization the BT Controller. it will be called after// BT_OP_HCI_CHANNEL_OPEN. Controller Must call init_cb to notify the host// once it has been done.case BT_OP_INIT: {welog_err("bluetooth start BT_OP_INIT");if (rtkbt_transtype & RTKBT_TRANS_UART) {welog_err("rtkbt_transtype & RTKBT_TRANS_UART hw_config_start");hw_config_start(rtkbt_transtype);} else {welog_err("BT_OP_INIT else");int usb_info = 0;retval = userial_vendor_usb_ioctl(GET_USB_INFO, &usb_info);if (retval == -1) {welog_err("bluetooth get usb info fail");return retval;} else {welog_err("bluetooth hw_usb_config_start");hw_usb_config_start(RTKBT_TRANS_H4, usb_info);}}RTK_btservice_init();}break;// Get the LPM idle timeout in milliseconds.case BT_OP_GET_LPM_TIMER: {}break;// Enable LPM mode on BT Controller.case BT_OP_LPM_ENABLE: {}break;// Disable LPM mode on BT Controller.case BT_OP_LPM_DISABLE: {}break;// Wakeup lock the BTC.case BT_OP_WAKEUP_LOCK: {}break;// Wakeup unlock the BTC.case BT_OP_WAKEUP_UNLOCK: {}break;// transmit event response to vendor lib.case BT_OP_EVENT_CALLBACK: {hw_process_event((HC_BT_HDR *)param);}break;}welog_err("bluetooth op return result:%d", retval);return retval;
}

编译对应目标或者直接正版本增量编译,使打印生效。

./build.sh --product-name rvbook --ccache --no-prebuilt-sdk

3.设备验证

编译完成后进行全镜像烧录。
设备启动后,通过串口或者HDC查看设备/dev目录下设备
在这里插入图片描述
此处还需要通过chomd修改welog驱动权限,否则日志功能不可用。

chmod -R 777 /dev/welog

阅读新增的日志驱动代码,可以发现新的模块日志将会被保存在/data/log/welog/welog.log中
之后在确保新增日志的接口被调用后,发现该目录并没有日志文件生成。此处应该是日志模块代码的一个小bug,代码并没有生成不存在的子目录
因此需要手动

mkdir /data/log/welog/
chmod -R 777 /data/log/welog/

又因为该OH内核不支持vim等命令创建新文件,因此使用HDC将welog.log放到该目录下

./hdc file send welog.log /data/log/welog/

然后运行相关模块的代码,使用命令

tail -f /data/log/welog/welog.log

监测日志变化即可。
在这里插入图片描述

./hdc shell mount -oremount,rw /
./hdc shell mount -oremount,rw /vendor
./hdc shell mkdir /data/log/welog/
./hdc file send …/images/welog.log /data/log/welog/
./hdc shell chmod -R 777 /data/log/welog/

打完收工

总结

需要知道HDC用法,linux内核的一些基本知识,OH的修改、编译、烧录、运行。

参考

https://blog.csdn.net/weixin_42135087/article/details/139903669

相关文章:

  • 图像处理 -- ISP 之 tone mapping功能的实现原理
  • systemback制作Ubuntu自己的系统镜像
  • 观察者模式解析:实现对象间的舞蹈同步!
  • 怎么生成一个springboot的项目
  • Python中的random模块及相关模块详解
  • Application实际在云原生中的应用
  • 在ubuntu16.04下使用词典工具GoldenDict
  • thrift:拦截器ThriftEventHandler获取调用参数
  • SpringBoot项目启动后自动执行方法
  • 广州自闭症全托管学校-正规儿童康复中心
  • 利用深度学习技术来实现街景图像的语义分割(街景图像语义分割)
  • 基于WonderJourney生成电影级连续的3D场景视频
  • Java学习Day33:HTML 第四章:大战虎先锋(js)
  • 6个免费字体网站,无需担心版权问题~
  • Android 12系统源码_多屏幕(三)模拟辅助设备功能实现原理
  • 《Javascript高级程序设计 (第三版)》第五章 引用类型
  • 【跃迁之路】【735天】程序员高效学习方法论探索系列(实验阶段492-2019.2.25)...
  • 2018以太坊智能合约编程语言solidity的最佳IDEs
  • AngularJS指令开发(1)——参数详解
  • Eureka 2.0 开源流产,真的对你影响很大吗?
  • HTML-表单
  • JavaScript类型识别
  • JWT究竟是什么呢?
  • Puppeteer:浏览器控制器
  • 纯 javascript 半自动式下滑一定高度,导航栏固定
  • 大整数乘法-表格法
  • 分布式事物理论与实践
  • 欢迎参加第二届中国游戏开发者大会
  • 将 Measurements 和 Units 应用到物理学
  • 面试遇到的一些题
  • 如何邀请好友注册您的网站(模拟百度网盘)
  • 入职第二天:使用koa搭建node server是种怎样的体验
  • 深入浅出Node.js
  • 体验javascript之美-第五课 匿名函数自执行和闭包是一回事儿吗?
  • 3月7日云栖精选夜读 | RSA 2019安全大会:企业资产管理成行业新风向标,云上安全占绝对优势 ...
  • 从如何停掉 Promise 链说起
  • ​​快速排序(四)——挖坑法,前后指针法与非递归
  • ‌JavaScript 数据类型转换
  • ###STL(标准模板库)
  • #多叉树深度遍历_结合深度学习的视频编码方法--帧内预测
  • $.ajax()
  • $.ajax()方法详解
  • (02)Hive SQL编译成MapReduce任务的过程
  • (2022 CVPR) Unbiased Teacher v2
  • (23)Linux的软硬连接
  • (zhuan) 一些RL的文献(及笔记)
  • (阿里云在线播放)基于SpringBoot+Vue前后端分离的在线教育平台项目
  • (附源码)python房屋租赁管理系统 毕业设计 745613
  • (附源码)计算机毕业设计SSM保险客户管理系统
  • (九)c52学习之旅-定时器
  • (三)uboot源码分析
  • (提供数据集下载)基于大语言模型LangChain与ChatGLM3-6B本地知识库调优:数据集优化、参数调整、Prompt提示词优化实战
  • (图)IntelliTrace Tools 跟踪云端程序
  • (一) storm的集群安装与配置
  • (转)shell中括号的特殊用法 linux if多条件判断