#!/bin/bash # # idr_install-2.6 # Script to compile and load Tahoma Technology # DR11-W driver for Linux version 2.6. # Can also configure rc.local and /etc/idr for driver autoload on boot. # # This code released under the GPL, and in the public domain # References to IKON left in place for compatibility and historical # reasons # # Tahoma Technology # (formerly Ikon Corporation) # 107 2nd Avenue North # Seattle, WA, USA 98109 # # 206.728.6465 # http://www.tahomatech.com # tahoma@tahomatech.com # ***************************************** # SEE BELOW FOR USER CONFIGURABLE VARIABLES # ***************************************** # general script variables IDR_SCRIPT_NAME="idr_install-2.6" IDR_SCRIPT_DATE="5 October, 2005 12:51" IDR_SCRIPT_DESC="Tahoma Technology (formerly Ikon Corporation) DR11 driver installer" IDR_LINUX_VERS="for Linux version 2.6.x including x86_64" IDR_THISDIR=`pwd` # make and copy variables IDR_MAKE=make IDR_GREP=grep IDR_SOURCE=idr_driver IDR_CFLAGS_EXTRA="" IDR_DFLAGS="" IDR_MODULE=idr IDR_KERNEL_VERSION=`uname -r` IDR_KERNEL_SOURCE_DIR=/lib/modules/$IDR_KERNEL_VERSION/build IDR_MODULE_DIR=/lib/modules/$IDR_KERNEL_VERSION/misc IDR_TEST_DIR="" # load (insmod), autoload, and dev node variables IDR_INSMOD=/sbin/insmod IDR_RMMOD=/sbin/rmmod IDR_FFLAG="" IDR_INT_NODELIST="" IDR_INT_NODE="" IDR_TEMP=idr_temp IDR_DRIVER=$IDR_MODULE IDR_NODENAME=$IDR_MODULE IDR_MINOR=0 IDR_GROUP=bin IDR_OWNER=bin IDR_PERM=666 IDR_INIT_SCRIPT=/etc/rc.d/rc.local IDR_INSTALL_SCRIPT_DIR=/etc/idr IDR_INSTALL_SCRIPT_PERM=744 IDR_INSTALL_SCRIPT_DIR_PERM=755 # *****USER CONFIGURABLE SCRIPT BEHAVIOR VARIABLES***** # these control variables have two or three options # those with YES|NO options force the associated # behavior -- those with an AUTO option allow the # script and/or the driver to autoconfigure the # associated behavior IDR_USER_DMA=AUTO # NO|AUTO - dma direct to/from user buffer # AUTO = YES unless kernel configured for > 4G RAM # NO or > 4G RAM = dma to/from kernel copy buffer IDR_ENB_DEBUG=NO # YES|NO - YES or script cmd line option = debug mode IDR_FORCE_LOAD=NO # YES|NO - force module load # *****USER CONFIGURABLE LOAD-TIME VARIABLES***** # the following will be passed to insmod and may # be edited to control driver and device configuration # IDR_BOARDS determines the number of boards probed # for and device nodes created IDR_BOARDS=4 # max number of boards and dev nodes IDR_MAX_PHYS_ORDER=4 # max dma xfer in "orders" of pages # also controls size of copy buffer (if not user dma) # larger user buffers will be done in max_phys chunks # max = PAGE_SIZE*(2**IDR_MAX_PHYS_ORDER) # w/current 4K page size, 0=4K, 1=8K, 2=16K, 3=32K, 4=64K ... IDR_SPEED=0 # handshake speed 0=fastest, 3=slowest IDR_DMA_TIME=30 # dma timeout in seconds IDR_RDY_TIME=30 # ready wait timeout in seconds IDR_ATTN_TIME=30 # attention wait timeout in seconds IDR_BYTE_SWAP=0 # 0=no swap, 1=swap IDR_CYCLE_POL=0 # 0=rising edge active, 1=falling edge active IDR_BUSY_POL=0 # 0=low assertion, 1=high assertion IDR_WRITE_CYCLE=1 # 0=do not pulse cycle on write, 1=pulse cycle on write IDR_READ_CYCLE=0 # 0=do not pulse cycle on read, 1=pulse cycle on read IDR_READ_ACF2=0 # 0=do not pulse acf2 on read, 1=pulse acf2 on read # the following function bit variables cause assertion if =1, no assertion if =0 IDR_OPEN_F3=0 IDR_OPEN_F2=0 IDR_OPEN_F1=0 IDR_WRITE_F3=1 IDR_WRITE_F2=0 IDR_WRITE_F1=0 IDR_READ_F3=1 IDR_READ_F2=0 IDR_READ_F1=1 echo # if no argument, print usage if [ -z $1 ] then echo "$IDR_SCRIPT_NAME: $IDR_SCRIPT_DATE" echo "$IDR_SCRIPT_DESC" echo "$IDR_LINUX_VERS" echo echo "usage: $IDR_SCRIPT_NAME [compile|load|autoload|remove|all]" echo echo " compile: compiles driver and copies to module directory" echo " load: loads driver into running kernel and creates device node(s)" echo " autoload: copies this script to $IDR_INSTALL_SCRIPT_DIR/" echo " and adds entry to rc.local to invoke this script (load) at boot time" echo " remove: unloads driver, deletes module, removes autoload entry," echo " script copy and directory, and device nodes" echo " all: remove, compile, load, and autoload" echo echo " compile and all may take an optional second argument: debug, which" echo " causes the driver to be compiled in debug mode (many printfs to log)" echo echo " some compile/install options are autodetected by this script and/or the" echo " driver code -- autodetected and hard coded options may be changed by" echo " editing this script" echo exit 0 fi # if arg #2 is debug, or debug enabled in script - set debug compile mode if [ $IDR_ENB_DEBUG = YES ] then IDR_DFLAGS=-DIDR_DEBUG fi if ! [ -z $2 ] then if [ $2 = debug ] then IDR_DFLAGS=-DIDR_DEBUG else echo "***** unrecognized 2nd argument!" ./$IDR_SCRIPT_NAME exit 1 fi fi # compile driver module and copy to module directory # first sort out the compile options if [ $1 = compile ] then echo "$IDR_SCRIPT_NAME: command is $1 $2" echo "removing old $IDR_MODULE.o .ko .mod.c .mod.o files (if any)" rm -f $IDR_MODULE.o rm -f $IDR_MODULE.ko rm -f $IDR_MODULE.mod.o rm -f $IDR_MODULE.mod.c # pass user dma/copy buffer mode to compiler if [ $IDR_USER_DMA = AUTO ] then echo "auto dma/copy buffer mode" IDR_CFLAGS_EXTRA="$IDR_CFLAGS_EXTRA -DIDR_DMA_MODE_AUTO" else echo "forcing copy buffer mode" IDR_CFLAGS_EXTRA="$IDR_CFLAGS_EXTRA -DIDR_DMA_MODE_COPY" fi if [ -n "$IDR_DFLAGS" ] then echo "debug compile enabled" fi echo "compiling $IDR_SOURCE.c using kbuild make" if ! $IDR_MAKE -C $IDR_KERNEL_SOURCE_DIR SUBDIRS=$PWD EXTRA_CFLAGS="$IDR_DFLAGS $IDR_CFLAGS_EXTRA" modules then echo "***** make error!" exit 1 fi if ! [ -d $IDR_MODULE_DIR ] then echo "creating $IDR_MODULE_DIR" mkdir $IDR_MODULE_DIR fi echo "copying $IDR_MODULE.ko to $IDR_MODULE_DIR" if ! cp $IDR_MODULE.ko $IDR_MODULE_DIR/ then echo "***** error copying $IDR_MODULE.ko to $IDR_MODULE_DIR!" exit 1 fi echo "compile and copy complete" exit 0 fi # load module into kernel and create device nodes # count to max boars and do sanity check against /proc/interrupts # when creating nodes (only create nodes for installed boards) if [ $1 = load ] then echo "$IDR_SCRIPT_NAME: command is $1" if [ $IDR_FORCE_LOAD = YES ] then IDR_FFLAG='-f' echo "forced load enabled" fi echo "loading module into kernel" if ! $IDR_INSMOD $IDR_FFLAG $IDR_MODULE_DIR/$IDR_MODULE.ko\ speed_def=$IDR_SPEED dma_time_def=$IDR_DMA_TIME\ attn_time_def=$IDR_ATTN_TIME rdy_time_def=$IDR_RDY_TIME\ byte_swap_def=$IDR_BYTE_SWAP cycle_pol_def=$IDR_CYCLE_POL\ busy_pol_def=$IDR_BUSY_POL write_cycle_def=$IDR_WRITE_CYCLE\ read_cycle_def=$IDR_READ_CYCLE read_acf2_def=$IDR_READ_ACF2\ open_f3_def=$IDR_OPEN_F3 open_f2_def=$IDR_OPEN_F2\ open_f1_def=$IDR_OPEN_F1 write_f3_def=$IDR_WRITE_F3\ write_f2_def=$IDR_WRITE_F2 write_f1_def=$IDR_WRITE_F1\ read_f3_def=$IDR_READ_F3 read_f2_def=$IDR_READ_F2\ read_f1_def=$IDR_READ_F1 max_phys_order=$IDR_MAX_PHYS_ORDER\ max_boards=$IDR_BOARDS then echo "***** insmod error!" exit 1 fi echo "removing stale device nodes (if any)" rm -f /dev/$IDR_NODENAME* echo "getting device major number from /proc/devices" IDR_MAJOR=`cat /proc/devices | awk "\\$2==\"$IDR_DRIVER\" {print \\$1}"` echo "getting node list from /proc/interrupts" IDR_INT_NODELIST=`$IDR_GREP -E -o "\<$IDR_NODENAME[[:digit:]]+" /proc/interrupts` echo "creating device node(s)" while [ $IDR_BOARDS -gt 0 ] do for IDR_INT_NODE in $IDR_INT_NODELIST do if [ "$IDR_INT_NODE" = $IDR_NODENAME$IDR_MINOR ] then if ! mknod /dev/$IDR_NODENAME$IDR_MINOR c $IDR_MAJOR $IDR_MINOR then echo "***** mknod error!" exit 1 fi echo "created device node /dev/$IDR_NODENAME$IDR_MINOR" echo "setting ownership and permissions" chown $IDR_OWNER /dev/$IDR_NODENAME$IDR_MINOR chgrp $IDR_GROUP /dev/$IDR_NODENAME$IDR_MINOR chmod $IDR_PERM /dev/$IDR_NODENAME$IDR_MINOR fi done IDR_BOARDS=$( expr $IDR_BOARDS - 1 ) IDR_MINOR=$( expr $IDR_MINOR + 1 ) done echo "driver loaded and device nodes created" echo "load complete" exit 0 fi # copy this script to script dir (/etc/idr, probably) and # invoke it (load) from /etc/rc.d/rc.local if [ $1 = autoload ] then echo "$IDR_SCRIPT_NAME: command is $1" echo "removing old $IDR_SCRIPT_NAME (if present) from $IDR_INSTALL_SCRIPT_DIR" if [ -d $IDR_INSTALL_SCRIPT_DIR ] then rm -f $IDR_INSTALL_SCRIPT_DIR/$IDR_SCRIPT_NAME* fi echo "creating $IDR_INSTALL_SCRIPT_DIR (if necessary) and setting permissions" if [ -d $IDR_INSTALL_SCRIPT_DIR ] then echo "$IDR_INSTALL_SCRIPT_DIR exists, leaving permissions unchanged" else if ! mkdir $IDR_INSTALL_SCRIPT_DIR then echo "***** error creating $IDR_INSTALL_SCRIPT_DIR!" exit 1 fi if ! chmod $IDR_INSTALL_SCRIPT_DIR_PERM $IDR_INSTALL_SCRIPT_DIR then echo "***** error setting permissions on $IDR_INSTALL_SCRIPT_DIR!" exit 1 fi fi echo "copying $IDR_SCRIPT_NAME to $IDR_INSTALL_SCRIPT_DIR and setting permissions" if ! cp $IDR_SCRIPT_NAME $IDR_INSTALL_SCRIPT_DIR/ then echo "***** error copying $IDR_SCRIPT_NAME to $IDR_INSTALL_SCRIPT_DIR!" rmdir --ignore-fail-on-non-empty $IDR_INSTALL_SCRIPT_DIR exit 1 fi if ! chmod $IDR_INSTALL_SCRIPT_PERM $IDR_INSTALL_SCRIPT_DIR/$IDR_SCRIPT_NAME then echo "***** error setting permissions on $IDR_SCRIPT_NAME!" exit 1 fi echo "removing old $IDR_SCRIPT_NAME entry (if any) from $IDR_INIT_SCRIPT" if ! sed /$IDR_SCRIPT_NAME/d $IDR_INIT_SCRIPT > ./$IDR_TEMP then echo "***** sed error removing entry from $IDR_INIT_SCRIPT!" exit 1 fi if ! cp ./$IDR_TEMP $IDR_INIT_SCRIPT then echo "***** error writing back $IDR_INIT_SCRIPT!" exit 1 fi echo "adding $IDR_SCRIPT_NAME to $IDR_INIT_SCRIPT" if ! echo "if [ -x $IDR_INSTALL_SCRIPT_DIR/$IDR_SCRIPT_NAME ] ; then { date ; echo ; echo \"\$0: calling $IDR_INSTALL_SCRIPT_DIR/$IDR_SCRIPT_NAME load\" ; $IDR_INSTALL_SCRIPT_DIR/$IDR_SCRIPT_NAME load ; } > $IDR_INSTALL_SCRIPT_DIR/$IDR_SCRIPT_NAME.bootlog 2>&1 ; fi" >> $IDR_INIT_SCRIPT then echo "***** error adding entry to $IDR_INIT_SCRIPT!" exit 1 fi rm -f ./$IDR_TEMP echo "$IDR_SCRIPT_NAME added to $IDR_INIT_SCRIPT" echo "autoload complete" exit 0 fi # unload driver and clean up if [ $1 = remove ] then echo "$IDR_SCRIPT_NAME: command is $1" echo "unloading module from kernel (if present)" $IDR_RMMOD $IDR_MODULE echo "removing device nodes" rm -f /dev/$IDR_NODENAME* echo "deleting $IDR_MODULE.ko module from $IDR_MODULE_DIR" rm -f $IDR_MODULE_DIR/$IDR_MODULE.ko echo "removing $IDR_MODULE_DIR (if present and empty)" rmdir --ignore-fail-on-non-empty $IDR_MODULE_DIR echo "removing $IDR_SCRIPT_NAME entry (if any) from $IDR_INIT_SCRIPT" if ! sed /$IDR_SCRIPT_NAME/d $IDR_INIT_SCRIPT > ./$IDR_TEMP then echo "***** sed error removing entry from $IDR_INIT_SCRIPT!" exit 1 fi if ! cp ./$IDR_TEMP $IDR_INIT_SCRIPT then echo "***** error writing back $IDR_INIT_SCRIPT!" exit 1 fi rm -f ./$IDR_TEMP echo "deleting $IDR_SCRIPT_NAME (if present) from $IDR_INSTALL_SCRIPT_DIR" if ! rm -f $IDR_INSTALL_SCRIPT_DIR/$IDR_SCRIPT_NAME* then echo "***** error deleting $IDR_INIT_SCRIPT from $IDR_INSTALL_SCRIPT_DIR!" exit 1 fi echo "removing $IDR_INSTALL_SCRIPT_DIR (if present and empty)" rmdir --ignore-fail-on-non-empty $IDR_INSTALL_SCRIPT_DIR echo "remove complete" exit 0 fi # compile, load, build nodes, and set autoload if [ $1 = all ] then echo "$IDR_SCRIPT_NAME: command is $1 $2" if ! ./$IDR_SCRIPT_NAME remove then echo "***** remove error!" exit 1 fi if ! ./$IDR_SCRIPT_NAME compile $2 then echo "***** compile error!" exit 1 fi if ! ./$IDR_SCRIPT_NAME load then echo "***** load error!" exit 1 fi if ! ./$IDR_SCRIPT_NAME autoload then echo "***** autoload error!" exit 1 fi echo "" echo "remove, compile, load, and autoload complete" exit 0 fi # if unrecognized arg, bitch, and print usage echo "***** unrecongnized 1st argument!" ./$IDR_SCRIPT_NAME exit 1