[pxc] More generalized form of pxc_load

M Bianchi mbianchi@Foveal.com
Fri, 1 Feb 2002 09:05:12 -0500


--FL5UXtIhxfXey3p5
Content-Type: text/plain; charset=us-ascii

Folks,

I offer this more generalized version of the pxc_load proceedure to the
community.

I have Imagenation PX500, PX510, PX610, and PXC200L PCI framegrabbers in my
systems, and often more than one card at a time.  I wanted a means to
automatically detect and configure the cards found so, starting with px_load
and pxc_load, I created this shell script.
Running it in an  /etc/rc.d/init.d/*  file during boot configures just the
required /dev/px* files for the cards found.

The Usage message reads:

Usage:  framegrabber_load.sh [ -v ] { -l | -u }
Load or unload the kernel modules for the framegrabbers installed on the
system.  Creates the device files in  /dev  for the framegrabbers found.
Must be run as root.

One these flag arguments is required:
-l      load (or unload and reload) the framegrabber modules
-u      unload the framegrabber modules

Options:
-v      Verbose; announce successful load or unload.

Setup:
This command must be run in the directory where the kernel modules are present.
Kernel modules are named with the recognized device names followed by the
kernel version as reported by the  uname -r  command.  For example for a
PXC200 Imagenation board running on Linux kernel 2.2.12-16, the module file is
named  pxc200_2.2.12-16 .  The module is listed by lsmod(1) as  pxc200 .
If this device_kernel form of module file does not exist, then  <device>.o  is
tried.  If that does not exist, then either  pxc.o  (for the PXC200) or
 pxdrv.o  (for the PX500, PX510 or PX600) is tried.
Recognized Imagenation framegrabbers:  PXC200  PX500  PX510  PX600
Note: the PX610A is not supported.


The code is licensed under the GNU General Public License.
Comments, bug fixes and suggested improvements are welcome.

-- 
 Mike Bianchi
 Foveal Systems
 190 Loantaka Way
 Madison NJ  07940-1910

 +1 973 822-2085	Voice and Fax

 MBianchi@Foveal.com

 Create videos of auditorium presentations without a crew?
 Yes!
 http://www.AutoAuditorium.com

--FL5UXtIhxfXey3p5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=framegrabber_load
Content-Transfer-Encoding: quoted-printable

#! /bin/sh
#                       Copyright (c) 2000 Foveal Systems
#	MBianchi@Foveal.com
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 2 of the License, or
#	(at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#	$Header: /usr/home/mbianchi/src/autoaud/5.0.aa/RCS/framegrabber_load.sh,v=
 5.3 2002/02/01 14:04:23 mbianchi Exp $

cmd=3D$( basename $0 )

function Echo {
	#	prints on stderr!
	echo >&2 "${cmd}: $@"
}

function Verbose {
	#	prints on stdout!
	case $1 in
	-f )
		file=3D$2
		shift 2
		echo "$@" >>${file}
	esac
	if [ ${verbose} ]
	then
		echo "${cmd}:  $@"
	fi
}

function Usage {
	echo >&2 '=07'
	if [ $# -gt 0 ]
	then
		Echo "$@"
	fi
	echo >&2 "Usage:  ${cmd} [ -v ] { -l | -u }
Load or unload the kernel modules for the framegrabbers installed on the
system.  Creates the device files in  /dev  for the framegrabbers found.
Must be run as root.

One these flag arguments is required:
-l	load (or unload and reload) the framegrabber modules
-u	unload the framegrabber modules

Options:
-v	Verbose; announce successful load or unload.

Setup:
This command must be run in the directory where the kernel modules are pres=
ent.
Kernel modules are named with the recognized device names followed by the
kernel version as reported by the  uname -r  command.  For example for a
PXC200 Imagenation board running on Linux kernel 2.2.12-16, the module file=
 is
named  pxc200_2.2.12-16 .  The module is listed by lsmod(1) as  pxc200 .
If this device_kernel form of module filename does not exist, then  <device=
>.o
is tried.  If that does not exist, then either  pxc.o  (for the PXC200) or
 pxdrv.o  (for the PX500, PX510 or PX600) is tried.
Recognized Imagenation framegrabbers:  PXC200  PX500  PX510  PX600
Note: the PX610A is not supported.
"
	exit 255
}

badoption=3Dneed_required_option
unload=3D
verbose=3D
while getopts :vlu option
do
	case ${option} in
	l )
		load=3Dload
		badoption=3D
		;;
	u )
		unload=3Dunload
		badoption=3D
		;;
	v )
		verbose=3Dverbose
		;;
	'?' )
		Echo "invalid option -${OPTARG}"
		badoption=3Dbadoption
		;;
	* )
		Echo "oops!  unimplimented option -${option}"
		badoption=3Dbadoption
	esac
done
shift $( expr ${OPTIND} - 1 )

if [ -n "${badoption}"  -o  $# -gt 0 ]
then
	Usage "Unexpected arguments:  $*"
fi

if [ -n "${load}"  -a  -n "${unload}" ]
then
	Usage "Cannot specify both -l and -u options."
fi

eval $( id  |  sed 's/(.*//' )
if [ "${uid}" !=3D 0 ]
then
	Usage "Must be run as root."
fi


function MakeDevice {
	dev_filename=3D$1
	major=3D$2
	max_minor=3D$3
	index=3D$4

	for j in \
		' MINOR=3D0	TYPE=3D		' \
		' MINOR=3D16	TYPE=3Dpgm	' \
		' MINOR=3D32	TYPE=3Dctl	' \
		' MINOR=3D48	TYPE=3DH		' \
		' MINOR=3D64	TYPE=3DHpgm	' \
		' MINOR=3D80	TYPE=3Dppm	' \
		' MINOR=3D96	TYPE=3Drgb	' \
		' MINOR=3D112	TYPE=3Dbgr	' \
		' MINOR=3D128	TYPE=3DHppm	' \
		' MINOR=3D144	TYPE=3DHrgb	'
	do
		eval ${j}

		if [ ${MINOR} -gt ${max_minor} ]
		then
			return
		fi

		file=3D${dev_filename}${index}${TYPE}
		let MINOR+=3D${index}

		rm -f ${file}
		mknod ${file} c ${major} ${MINOR}  &&
			chmod go+w ${file}
	done
}

exitcode=3D0
found_device=3D0

#	DEVICE		the device name found in /proc/devices
#	DEV_FILENAME	the root of the device filename, starts with  /dev/
#	BOARDID		the string for the board found in /proc/pci
#	MAX_MINOR	the maximum minor device number base supported.
#			E.g.	/dev/px0Hpgm is minor device 64
#				/dev/px1Hpgm is minor device 65, etc.
#	Maybe someday ...
#	  DEVICE=3Dpx610A
#	  DEV_FILENAME=3D/dev/px
#	  BOARDID=3D"Multimedia controller:.*\<SAA7146\>"
#	  MAX_MINOR=3D64

for i in \
	' DEVICE=3Dpxc200
	  DEV_FILENAME=3D/dev/pxc
	  BOARDID=3D"Multimedia video controller:.*\<Bt848\>"
	  MAX_MINOR=3D144
	  DEFAULT_DOT_O_FILE=3Dpxc.o
	' \
	' DEVICE=3Dpx500
	  DEV_FILENAME=3D/dev/px
	  BOARDID=3D"Multimedia video controller:.*\<SAA7116\>"
	  MAX_MINOR=3D64
	  DEFAULT_DOT_O_FILE=3Dpxdrv.o
	'
do
	eval ${i}

	device_count=3D$( lspci  |  grep -ic "${BOARDID}" )
	if [ ${device_count} -le 0 ]
	then
		continue
	fi

	module_file=3D${DEVICE}_$( uname -r )
	dot_o_file=3D${DEVICE}.o

	/sbin/rmmod  ${DEVICE}  2>/dev/null
	rm -f ${DEV_FILENAME}*
	if [ ${unload} ]
	then
		continue
	fi

	if [ -s ${module_file} ]
	then
		:
	elif [ -s ${dot_o_file} ]
	then
		module_file=3D${dot_o_file}
	elif [ -s ${DEFAULT_DOT_O_FILE} ]
	then
		module_file=3D${DEFAULT_DOT_O_FILE}
	else
		Echo "$(pwd):
  No file  ${module_file} ,  ${dot_o_file} , or  ${DEFAULT_DOT_O_FILE}
  Need module for \"${BOARDID}\"."
		exitcode=3D1
		continue
	fi

	found_device=3D1
	insmod_cmd=3D"/sbin/insmod  --force  --name=3D${DEVICE}  ${module_file}"
	if ${insmod_cmd}
	then
		Verbose Loaded module ${module_file} for ${DEVICE}.
		major=3D$( grep "${DEVICE}" /proc/devices  |  awk '{print $1}' )
		while [ ${device_count} -gt 0 ]
		do
			let device_count-=3D1
			MakeDevice ${DEV_FILENAME} ${major} ${MAX_MINOR} \
								${device_count}
			Verbose Created ${DEV_FILENAME}${device_count}
		done
	else
		Verbose "insmod(1) failed:
	${insmod_cmd}"
		exitcode=3D2
	fi
done

if [ ${found_device} =3D 0 ]
then
	Verbose No devices found.
fi

exit ${exitcode}

--FL5UXtIhxfXey3p5--