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

优化OpenHarmony中lspci命令实现直接获取设备具体型号

OpenHarmony中由于开源协议的原因,默认使用toybox,而不是busybox。但是OpenHarmony使用的toybox还有一些不完善的地方,比如执行lspci命令无法获取到pci.ids数据库文件,从而无法获取到PCI设备的具体型号,如下图。于是将解决办法分析如下:

image.png

/usr/share/misc/pci.ids 是一个数据库文件,它包含了几乎所有已知的PCI设备ID、厂商ID、设备类型和子系统ID的对应名称。

解决办法

1.从https://pci-ids.ucw.cz/%E5%A4%84%E8%8E%B7%E5%8F%96%E5%88%B0pci.ids%E6%95%B0%E6%8D%AE%E5%BA%93%E6%96%87%E4%BB%B6%EF%BC%8C%E7%BC%96%E8%AF%91%E6%89%93%E5%8C%85%E5%88%B0%E5%BC%80%E5%8F%91%E6%9D%BF%E4%B8%AD%EF%BC%8C%E5%BC%80%E5%8F%91%E6%9D%BF%E4%B8%ADpci.ids%E7%9A%84%E8%B7%AF%E5%BE%84%E4%B8%BA%60/vendor/etc/pci.ids%60

image.png

2.修改toybox源码,将/usr/share/misc/pci.ids路径改为/vendor/etc/pci.ids

--- a/third_party/toybox/toys/other/lspci.c    2025-06-30 17:12:48.037944884 +0800
+++ a/third_party/toybox/toys/other/lspci.c    2025-06-30 17:13:42.807941470 +0800
@@ -23,7 +23,7 @@usage: lspci [-n] [-i FILE ]-n    Numeric output (repeat for readable and numeric)
-    -i    PCI ID database (default /usr/share/misc/pci.ids)
+    -i    PCI ID database (default /vendor/etc/pci.ids)*/@@ -120,7 +120,7 @@void lspci_main(void){if (CFG_LSPCI_TEXT && TT.n != 1) {
-    if (!TT.i) TT.i = "/usr/share/misc/pci.ids";
+    if (!TT.i) TT.i = "/vendor/etc/pci.ids";if (!(TT.db = fopen(TT.i, "r"))) perror_msg("%s", TT.i);}--- a/third_party/toybox/generated/help.h    2025-06-30 17:13:08.487943580 +0800
+++ a/third_party/toybox/generated/help.h    2025-06-30 17:13:26.137942414 +0800
@@ -230,7 +230,7 @@#define HELP_lsusb "usage: lsusb\n\nList USB hosts/devices."-#define HELP_lspci "usage: lspci [-ekmn] [-i FILE ] \n\nList PCI devices.\n-e    Print all 6 digits in class\n-i    PCI ID database (default /usr/share/misc/pci.ids)\n-k    Print kernel driver\n-m    Machine parseable format\n-n    Numeric output (repeat for readable and numeric)"
+#define HELP_lspci "usage: lspci [-ekmn] [-i FILE ] \n\nList PCI devices.\n-e    Print all 6 digits in class\n-i    PCI ID database (default /vendor/etc/pci.ids)\n-k    Print kernel driver\n-m    Machine parseable format\n-n    Numeric output (repeat for readable and numeric)"#define HELP_lsmod "usage: lsmod\n\nDisplay the currently loaded modules, their sizes and their dependencies."

修改效果

可以获取到pci具体信息,比如笔者板子上有两个rtl8126网卡,一张amd 580显卡

image.png

http://www.xdnf.cn/news/1356031.html

相关文章:

  • 机械学习综合练习项目
  • 基于SpringBoot的新能源汽车租赁管理系统【2026最新】
  • Linux 系统管理核心概念与常用命令速查
  • 春秋云镜 Hospital
  • 【Qt开发】常用控件(六)
  • 一个简洁的 C++ 日志模块实现
  • 【数位DP】D. From 1 to Infinity
  • 金山办公的服务端开发工程师-25届春招笔试编程题
  • Python训练营打卡 DAY 45 Tensorboard使用介绍
  • 基于电磁频谱地图的辐射源定位算法复现
  • 基于TimeMixer现有脚本扩展的思路分析
  • 基础IO
  • CryptSIPVerifyIndirectData函数分析
  • 刷题日记0823
  • 环境 (shell) 变量
  • Nacos-12--扩展:@RefreshScope和@ConfigurationProperties实现热更新的原理
  • Kubernetes笔记整合-1
  • 一种通过模板输出Docx的方法
  • LeakyReLU和ReLU的区别
  • 探索 JUC:Java 并发编程的神奇世界
  • KVM虚拟化:提升企业效率的利器
  • 【嵌入式】【搜集】RTOS相关技术信息整理
  • 微信小程序界面常用操作
  • SpringBoot自动装配原理深度解析
  • 电蚊拍的原理及电压电容参数深度解析:从高频振荡到倍压整流的完整技术剖析
  • Trae Solo模式生成一个旅行足迹App
  • 最新短网址源码,防封。支持直连、跳转。 会员无广
  • Azure Kubernetes Service (AKS)
  • 视觉革命:云渲染如何让创意不再受限于硬件
  • qt ElaWidgetTools第一个实例