Hi,

AFAIR similar problem applies to util-linux/lspci.c.
Do you build busybox with shell enabled?
Instead of busybox's lspci/lsusb I use 2 quite simple shell scripts (working in 
hush).

-- 
Aleksander Mazur

Dnia 2023-12-13, o godz. 16:04:02
Peter Korsgaard <pe...@korsgaard.com> napisaƂ(a):

> Just listing the vendor/product IDs is not always very helpful, so add logic
> to print the manufacturer and product strings similar to the "big" usbutils
> versions.
> 
> Not all devices provide sensible strings though.  The usbutils version works
> around this by falling back to looking up the vendor/product IDs in the hwdb
> and using those strings instead, which is not an option here - Instead
> simply trim() the strings for readability.
> 
> lsusb | sort
> Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 001 Device 002: ID 0bda:5539 Realtek Semiconductor Corp.
> Integrated_Webcam_HD Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp. 58200
> Bus 001 Device 030: ID 8087:0aaa Intel Corp. Bluetooth 9460/9560 Jefferson
> Peak (JfP) Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> Bus 006 Device 002: ID 0bda:5487 Realtek Semiconductor Corp. Dell dock
> Bus 006 Device 003: ID 0bda:5413 Realtek Semiconductor Corp. Dell dock
> Bus 006 Device 004: ID 413c:b06e Dell Computer Corp. Dell dock
> Bus 006 Device 005: ID 0451:8142 Texas Instruments, Inc. TUSB8041 4-Port Hub
> Bus 006 Device 006: ID 0bda:402e Realtek Semiconductor Corp. USB Audio
> Bus 006 Device 007: ID 413c:1010 Dell Computer Corp. USB 2.0 Hub [MTT]
> Bus 006 Device 008: ID 413c:b06f Dell Computer Corp. Dell dock
> Bus 006 Device 009: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
> Bus 006 Device 010: ID 413c:2110 Dell Computer Corp. Dell Wired Multimedia
> Keyboard Bus 006 Device 011: ID 0451:8142 Texas Instruments, Inc. TUSB8041
> 4-Port Hub Bus 006 Device 012: ID 0451:3410 Texas Instruments, Inc. TUSB3410
> Microcontroller Bus 007 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 007 Device 002: ID 0bda:0487 Realtek Semiconductor Corp. Dell dock
> Bus 007 Device 003: ID 0bda:0413 Realtek Semiconductor Corp. Dell dock
> Bus 007 Device 004: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit
> Ethernet Adapter
> 
> ./busybox lsusb | sort
> Bus 001 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host
> Controller Bus 001 Device 002: ID 0bda:5539 CNFHH53Q0324300ACA10
> Integrated_Webcam_HD Bus 001 Device 003: ID 0a5c:5842 Broadcom Corp 58200
> Bus 001 Device 030: ID 8087:0aaa
> Bus 002 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host
> Controller Bus 003 Device 001: ID 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd
> xHCI Host Controller Bus 004 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64
> xhci-hcd xHCI Host Controller Bus 005 Device 001: ID 1d6b:0002 Linux
> 6.1.0-13-amd64 dummy_hcd Dummy host controller Bus 006 Device 001: ID
> 1d6b:0002 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host Controller Bus 006 Device
> 002: ID 0bda:5487 Dell Inc. Dell dock Bus 006 Device 003: ID 0bda:5413 Dell
> Inc. Dell dock Bus 006 Device 004: ID 413c:b06e Dell dock
> Bus 006 Device 005: ID 0451:8142
> Bus 006 Device 006: ID 0bda:402e Generic USB Audio
> Bus 006 Device 007: ID 413c:1010 USB 2.0 Hub [MTT]
> Bus 006 Device 008: ID 413c:b06f Dell dock
> Bus 006 Device 009: ID 046d:c016 Logitech Optical USB Mouse
> Bus 006 Device 010: ID 413c:2110 Dell Dell Wired Multimedia Keyboard
> Bus 006 Device 011: ID 0451:8142
> Bus 006 Device 012: ID 0451:3410 Texas Instruments TUSB3410 Boot Device
> Bus 007 Device 001: ID 1d6b:0003 Linux 6.1.0-13-amd64 xhci-hcd xHCI Host
> Controller Bus 007 Device 002: ID 0bda:0487 Dell Inc. Dell dock
> Bus 007 Device 003: ID 0bda:0413 Dell Inc. Dell dock
> Bus 007 Device 004: ID 0bda:8153 Realtek USB 10/100/1000 LAN
> 
> ./scripts/bloat-o-meter busybox_unstripped{_orig,}
> function                                             old     new   delta
> trim                                                   -     101    +101
> fileAction                                           338     431     +93
> add_sysfs_prop                                         -      70     +70
> open_read_close                                        -      54     +54
> read_close                                             -      35     +35
> .rodata                                             3268    3294     +26
> ------------------------------------------------------------------------------
> (add/remove: 5/0 grow/shrink: 2/0 up/down: 379/0)             Total: 379 bytes
> 
> Signed-off-by: Peter Korsgaard <pe...@korsgaard.com>
> ---
>  util-linux/lsusb.c | 28 +++++++++++++++++++++++++++-
>  1 file changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/util-linux/lsusb.c b/util-linux/lsusb.c
> index 262c70a1b..0a9e505f4 100644
> --- a/util-linux/lsusb.c
> +++ b/util-linux/lsusb.c
> @@ -24,6 +24,24 @@
>  
>  #include "libbb.h"
>  
> +static char * FAST_FUNC add_sysfs_prop(const char *dir, const char *suffix,
> +             char *buf, size_t size)
> +{
> +     char *filename;
> +     ssize_t len;
> +
> +     filename = concat_path_file(dir, suffix);
> +     len = open_read_close(filename, buf, size - 1);
> +     free(filename);
> +
> +     if (len < 0)
> +             len = 0;
> +
> +     buf[len] = '\0';
> +
> +     return trim(buf);
> +}
> +
>  static int FAST_FUNC fileAction(struct recursive_state *state UNUSED_PARAM,
>               const char *fileName,
>               struct stat *statbuf UNUSED_PARAM)
> @@ -61,7 +79,15 @@ static int FAST_FUNC fileAction(struct recursive_state
> *state UNUSED_PARAM, config_close(parser);
>  
>       if (busnum) {
> -             printf("Bus %s Device %s: ID %04x:%04x\n", busnum, devnum,
> product_vid, product_did);
> +             char name[256], *p;
> +
> +             p = add_sysfs_prop(fileName, "/manufacturer", name,
> sizeof(name) - 1);
> +             if (p != name)
> +                     p = stpcpy(p, " ");
> +             add_sysfs_prop(fileName, "/product", p, name + sizeof(name)
> - p); +
> +             printf("Bus %s Device %s: ID %04x:%04x %s\n", busnum, devnum,
> +                    product_vid, product_did, name);
>               free(busnum);
>               free(devnum);
>       }

#!/bin/sh

_0_00="Non-VGA unclassified device"
_0_01="VGA compatible unclassified device"
_1_00="SCSI storage controller"
_1_01="IDE interface"
_1_02="Floppy disk controller"
_1_03="IPI bus controller"
_1_04="RAID bus controller"
_1_05="ATA controller"
_1_06="SATA controller"
_1_07="Serial Attached SCSI controller"
_1_08="Non-Volatile memory controller"
_1_80="Mass storage controller"
_2_00="Ethernet controller"
_2_01="Token ring network controller"
_2_02="FDDI network controller"
_2_03="ATM network controller"
_2_04="ISDN controller"
_2_05="WorldFip controller"
_2_06="PICMG controller"
_2_07="Infiniband controller"
_2_08="Fabric controller"
_2_80="Network controller"
_3_00="VGA compatible controller"
_3_01="XGA compatible controller"
_3_02="3D controller"
_3_80="Display controller"
_4_00="Multimedia video controller"
_4_01="Multimedia audio controller"
_4_02="Computer telephony device"
_4_03="Audio device"
_4_80="Multimedia controller"
_5_00="RAM memory"
_5_01="FLASH memory"
_5_80="Memory controller"
_6_00="Host bridge"
_6_01="ISA bridge"
_6_02="EISA bridge"
_6_03="MicroChannel bridge"
_6_04="PCI bridge"
_6_05="PCMCIA bridge"
_6_06="NuBus bridge"
_6_07="CardBus bridge"
_6_08="RACEway bridge"
_6_09="Semi-transparent PCI-to-PCI bridge"
_6_0A="InfiniBand to PCI host bridge"
_6_80="Bridge"
_7_00="Serial controller"
_7_01="Parallel controller"
_7_02="Multiport serial controller"
_7_03="Modem"
_7_04="GPIB controller"
_7_05="Smard Card controller"
_7_80="Communication controller"
_8_00="PIC"
_8_01="DMA controller"
_8_02="Timer"
_8_03="RTC"
_8_04="PCI Hot-plug controller"
_8_05="SD Host controller"
_8_06="IOMMU"
_8_80="System peripheral"
_9_00="Keyboard controller"
_9_01="Digitizer Pen"
_9_02="Mouse controller"
_9_03="Scanner controller"
_9_04="Gameport controller"
_9_80="Input device controller"
_A_00="Generic Docking Station"
_A_80="Docking Station"
_B_00="386"
_B_01="486"
_B_02="Pentium"
_B_10="Alpha"
_B_20="Power PC"
_B_30="MIPS"
_B_40="Co-processor"
_C_00="FireWire (IEEE 1394)"
_C_01="ACCESS Bus"
_C_02="SSA"
_C_03="USB controller"
_C_04="Fibre Channel"
_C_05="SMBus"
_C_06="InfiniBand"
_C_07="IPMI SMIC interface"
_C_08="SERCOS interface"
_C_09="CANBUS"
_D_00="IRDA controller"
_D_01="Consumer IR controller"
_D_10="RF controller"
_D_11="Bluetooth"
_D_12="Broadband"
_D_20="802.1a controller"
_D_21="802.1b controller"
_D_80="Wireless controller"
_E_00="I2O"
_F_01="Satellite TV controller"
_F_02="Satellite audio communication controller"
_F_03="Satellite voice communication controller"
_F_04="Satellite data communication controller"
_10_00="Network and computing encryption device"
_10_10="Entertainment encryption device"
_10_80="Encryption controller"
_11_00="DPIO module"
_11_01="Performance counters"
_11_10="Communication synchronizer"
_11_20="Signal processing management"
_11_80="Signal processing controller"
_12_00="Processing accelerators"

strip_prefix() {
        local prefix= cnt=$3
        while [ $cnt -gt 0 ]; do
                prefix=${prefix}?
                cnt=$((cnt-1))
        done
        eval $1='${2#$prefix}'
}

for devp in /sys/bus/pci/devices/*; do
        PCI_CLASS=
        PCI_SLOT_NAME=
        PCI_ID=
        DRIVER=
        if [ -e "$devp/uevent" ] && . "$devp/uevent"; then
                len=${#PCI_CLASS}
                strip_prefix x $PCI_CLASS $((len-2))
                class=${PCI_CLASS%$x}
                len=${#class}
                strip_prefix subclass $class $((len-2))
                class=${class%$subclass}
                eval trans="\$_${class}_${subclass}"
                [ -z "$trans" ] && trans="Class $PCI_CLASS"
                echo "${PCI_SLOT_NAME#*:} $trans: $PCI_ID $DRIVER"
        fi
done
#!/bin/sh

# 2017-03-01

leading_zeros() {
        local x
        eval x="\$$1"
        while [ ${#x} -lt $2 ]; do
                x="0$x"
        done
        eval $1='$x'
}

for devp in /sys/bus/usb/devices/usb* /sys/bus/usb/devices/*-*; do
        if [ -e "$devp/devnum" ]; then
                read bus < "$devp/busnum"
                read dev < "$devp/devnum"
                read vid < "$devp/idVendor"
                read pid < "$devp/idProduct"
                [ -e "$devp/manufacturer" ] && read manufacturer < 
"$devp/manufacturer" || manufacturer=
                [ -e "$devp/product" ] && read product < "$devp/product" || 
product=
                [ "$manufacturer" = "$product" ] && manufacturer=
                [ -n "$manufacturer" -a -n "$product" ] && sep=" " || sep=
                leading_zeros bus 3
                leading_zeros dev 3
                echo "Bus $bus Device $dev: ID $vid:$pid 
${manufacturer}${sep}${product}"
        fi
done
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to