优化OpenHarmony中lspci命令实现直接获取设备具体型号
·
OpenHarmony中由于开源协议的原因,默认使用toybox,而不是busybox。但是OpenHarmony使用的toybox还有一些不完善的地方,比如执行lspci
命令无法获取到pci.ids数据库文件,从而无法获取到PCI设备的具体型号,如下图。于是将解决办法分析如下:
/usr/share/misc/pci.ids 是一个数据库文件,它包含了几乎所有已知的PCI设备ID、厂商ID、设备类型和子系统ID的对应名称。
解决办法
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显卡
更多推荐
所有评论(0)