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

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐