propagator/usb-resource/update-usb-ids.sh
2004-11-22 18:25:25 +00:00

78 lines
1.6 KiB
Bash
Executable File

#!/bin/sh -e
MODLIST=
MODHDR=
[ -x /usr/bin/getpciids ]
###############################################################################
# HCD: PCI Class:
# uhci-hcd 0x000c0300
# ohci-hcd 0x000c0310
# ehci-hcd 0x000c0320
###############################################################################
HCDS="uhci-hcd ohci-hcd ehci-hcd"
exit_handler()
{
local rc=$?
trap - EXIT
[ -z "$MODLIST" ] || rm -f -- "$MODLIST"
[ -z "$MODHDR" ] || rm -f -- "$MODHDR"
exit $rc
}
write_decls()
{
cat <<E_O_F
struct usb_module_map {
unsigned short vendor; /* vendor */
unsigned short id; /* device */
const char *name; /* human readable name */
const char *module; /* module to load */
};
#ifndef DISABLE_USB
char *usb_hcd[] = {
E_O_F
> "$MODLIST"
for hcd in `echo $HCDS`; do
echo $hcd >> "$MODLIST"
printf '\t"%s",\n' $hcd
done
cat <<E_O_F
};
#define HCD_NUM (sizeof(usb_hcd) / sizeof(char *))
struct pci_module_map usb_pci_ids[] = {
E_O_F
getpciids -f "$MODLIST" |\
while read vendor device subv subd module; do
[ -n "$module" ] || module="$subv"
echo $module $vendor $device
done |sort -u |while read module vendor device; do
printf '\t{ 0x%s, 0x%s, "%s", "%s" },\n' $vendor $device "" $module
done
cat <<E_O_F
};
int usb_num_ids = sizeof(usb_pci_ids) / sizeof(struct pci_module_map);
#endif /* DISABLE_USB */
E_O_F
}
trap exit_handler SIGHUP SIGPIPE SIGINT SIGTERM SIGQUIT EXIT
export TMPDIR=/tmp
MODLIST=`mktemp -t modlist.XXXXXXXXXX`
MODHDR=`mktemp -t modhdr.XXXXXXXXXX`
write_decls > "$MODHDR"
cat "$MODHDR"