Skip to content

Instantly share code, notes, and snippets.

@penguin2716
Created October 2, 2011 19:40
Show Gist options
  • Save penguin2716/1257834 to your computer and use it in GitHub Desktop.
Save penguin2716/1257834 to your computer and use it in GitHub Desktop.
Shellscript to help find linux module sources for pci devices
#!/bin/sh
if [ $# -ne 1 ]
then
echo "Error: Please run with a keyword for searching pci devices."
echo "keyword example: ether, vga, audio, etc..."
exit 1
fi
echo "* symlink: /usr/src/linux -> `readlink /usr/src/linux`"
echo
key="$1"
pciinfo=`lspci | grep -i ${key}`
if [ "${pciinfo}" = "" ]
then
echo "Error: No matching pci device"
exit 1
fi
pcino=`echo "${pciinfo}" | awk '{print $1}'`
echo "* following devices are found."
echo "${pciinfo}"
echo
if [ `lspci | grep -i ${key} | wc -l` -gt 1 ]
then
echo "Found 2 or more devices. exit."
exit 2
fi
echo -n "Do you want to continue? [Y/n] "
read ans
if [ -z "$ans" -o "$ans" = "Y" ]
then
echo "continue."
else
echo "cancelled."
exit 1
fi
echo
devid=`cat /sys/bus/pci/devices/0000\:${pcino}/device | sed -e 's/^0x//g'`
vndid=`cat /sys/bus/pci/devices/0000\:${pcino}/vendor | sed -e 's/^0x//g'`
echo "* keyword: ${key}"
echo "* pci id: ${pcino}"
echo "* device: 0x${devid}"
echo "* vendor: 0x${vndid}"
echo
echo "* searching with vendor id (${vndid}) in include/linux/pci_ids.h"
defmacro=`grep -i ${vndid} /usr/src/linux/include/linux/pci_ids.h | awk '{print $2}'`
if [ -n "${defmacro}" ]
then
echo "* macro defined as \"${defmacro}\""
else
echo "* no macro defined"
fi
echo
echo "* searching with device id (${devid}) in drivers/* ..."
grep -ilR ${devid} /usr/src/linux/drivers/*
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment