#!/bin/ksh # Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. #ident "@(#)usbconfig 1.18 04/05/26 SMI" # This script is being made available by Sun merely as a convenience to you. # This script is provided "AS IS." Sun makes no warranties of any kind # whatsoever with respect to this script. ALL EXPRESS OR IMPLIED CONDITIONS, # REPRESENTATIONS AND WARRANTIES, INCLUDING ANY WARRANTY OF NON-INFRINGEMENT OR # IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE # HEREBY DISCLAIMED AND EXCLUDED TO THE EXTENT ALLOWED BY APPLICABLE LAW. IN NO # EVENT WILL SUN BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, # SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR PUNITIVE DAMAGES HOWEVER # CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY ARISING OUT OF THE USE OF OR # INABILITY TO USE THIS SCRIPT, EVEN IF SUN HAS BEEN ADVISED OF THE # POSSIBILITY OF SUCH DAMAGES. # This script sets up and maintains USB configuration in the dual framework # environment. It allows users to set up to run all USB hardware on the USBA # 1.0 framework (the preferred configuration), the default configuration for # the platform, and a configuration where hardware which can be operated by # either framework is operated by the old framework. The latter case is when # host controller drivers exist for both frameworks (OHCI on SPARC and UHCI on # X86). The latter configuration can be used for running legacy drivers not # supported by the USBA 1.0 framework. # # It checks current configuration and prints it out. It prevents # changing to the already-existing configuration. # # It also stores current configuration in a file, so that the user can # restore the current configuration after an upgrade. # Choose "Restore previous configuration" to do this. Note that if no upgrade # or configuration changes have been done, this option will do nothing since # the configuration is currently the same as "the previous configuration." # # Please note that ONLY THE DEFAULT and ALL-ON-1 CONFIGURATIONS ARE OFFICIALLY # SUPPORTED. The other configurations have not gone through the same rigorous # testing that is required for official support. # WARNING: before applying any USB patches to the system, please # return the system back to its original (default) state. Then apply # the patches and re-run the usbconfig script." # This script has one commandline option. If run with "-v", the commands which # actually change the configuration are run without sending their output and # error messages to NULL. When run without "-v" these commands run silently. # Availability of various drivers on the various OS platforms # ------------------------------------------------------------------------- # Platform ohci usba10_ohci uhci usba10_uhci usba10_ehci # ------------------------------------------------------------------------- # S9U7 X86 no yes yes yes yes # S9U6 X86 no yes yes no yes # # S9U7 Sparc yes yes no no yes # S9U6 Sparc yes yes no no yes # S8HW5/3 Sparc yes yes no no yes # Note that usba10_uhci exists only on S9U7 X86. # # If it doesn't exist, as with S9U6 X86, there is no difference in operation # between the "default" configuration and the all-on-1 configuration. In both # cases, all uhci hardware will be operated by the original framework and all # ohci hardware will be operated by the USBA 1.0 framework. In this case, # if the configuration is already default (as it should be) a message is # printed and the script exists. If the configuration is not default, the # script automatically resets default configuration. # The choices offered by this script have been simplified since the last # release. This is because, unlike before, usba10_ehci is now proven, and # because the current selections allow the option to use of the original # framework whenever available, as well as the option to use the USBA 1.0 # framework everywhere. Please send questions to usb-DDK-help@sun.com. # Globals for use in reading and writing previous configuration # A keyword to help sanity check the file USB_CONFIG_FLAG=USB_CONFIG # Name of the permanent file storing previous configuration PERM_CONFIG_FILE=/var/sadm/system/admin/.usbconfig # Name of a temporary file used for processing TEMP_CONFIG_FILE=/tmp/usbconfig.$$ # Global names of the three USB states supported by this program ALL_ON_10="All_on_10" # All USB hardware on USBA 1.0 FW DEFAULT="Default" # One 1.1 host controller has 1.0 USB HW on # USBA 0.0 / 2.0 USB HW on USBA 1.0. # Other 1.1 host controller is on USBA 1.0 # Get previous configuration from file. Returns in the global previous_config # one of the above 2 USB states supported by this program. function get_previous_config { # Initialize previous installation info from file. # Do nothing if file doesn't exist if [ -f $PERM_CONFIG_FILE ] ; then # Take the first line with valid header grep $USB_CONFIG_FLAG $PERM_CONFIG_FILE | \ head -1 > $TEMP_CONFIG_FILE # Get configuration as second item in that line previous_config=`/usr/bin/nawk '{ print $2 }' $TEMP_CONFIG_FILE` # Keep valid values, discard invalid ones. case "$previous_config" in "$ALL_ON_10" | "$DEFAULT") break ;; *) print "\n (Unknown or invalid previous" \ "usb configuration.)" previous_config= esac fi } # Get current configuration from /etc/driver_aliases file # Returns in global current_config a valid configuration, or NULL if unknown # Different functions for SPARC and x86 function get_current_config_sparc { # Local variables typeset usba10_ohci typeset usba10_ehci typeset ohci # Valid returned values for usba10_ohci are "pci1033,35", # "pciclass,0c0310", or NULL if not configured # Valid returned values for usba10_ehci are "pciclass,0c0320" or NULL # Valid returned values for ohci are "pciclass,0c0310" or NULL egrep [oe]hci /etc/driver_aliases | \ while read driver binding ; do eval $driver=$binding done # Assess configuration. Return in global $current_config # All sparc systems have ohci. if [ "$usba10_ohci" -a "$usba10_ohci" == "pciclass,0c0310" \ -a "$usba10_ehci" ] ; then current_config="$ALL_ON_10" elif [ "$usba10_ohci" -a "$usba10_ohci" == "pci1033,35" \ -a "$usba10_ehci" -a "$ohci" ] ; then current_config="$DEFAULT" fi } function get_current_config_i386 { # Local variables typeset usba10_uhci typeset usba10_ohci typeset usba10_ehci typeset uhci # Valid returned values for usba10_uhci are "pci1106,3038", # "pciclass,0c0300", or NULL if not configured # Valid returned values for usba10_ehci are "pciclass,0c0320" or NULL # Valid returned values for uhci are "pciclass,0c0300" or NULL # Valid returned values for usba10_ohci are "pciclass,0c0310" or NULL egrep [uoe]hci /etc/driver_aliases | \ while read driver binding ; do eval $driver=$binding done # Assess configuration. Return in global $current_config if [ "$usba10_uhci" -a "$usba10_uhci" == "pciclass,0c0300" \ -a "$usba10_ehci" -a "$usba10_ohci" ] ; then current_config="$ALL_ON_10" # Default configuration for systems with usba10_uhci elif [ "$usba10_uhci" -a "$usba10_uhci" == "pci1106,3038" \ -a "$usba10_ehci" -a "$uhci" -a "$usba10_ohci" ] ; then current_config="$DEFAULT" # Default configuration for systems without usba10_uhci elif [ "$uhci" -a "$uhci" == "pciclass,0c0300" \ -a "$usba10_ehci" -a "$usba10_ohci" ] ; then current_config="$DEFAULT" fi } # Print configuration for SPARC # Arg 1 is one of the valid configurations defined above. function print_config_sparc { case "$1" in "$ALL_ON_10" ) print " All USB devices in ohci port: " \ "USBA 1.0 framework" ;; "$DEFAULT" ) print " All USB 1.1 devices in USB 1.1 ohci port: " \ "original framework" print " All other USB device / ohci port " \ "combinations: USBA 1.0 framework" ;; * ) print " Unknown" esac print } # Print configuration for X86 # Arg 1 is one of the valid configurations defined above. function print_config_i386 { case "$1" in "$ALL_ON_10" ) print " Any USB device in any port: " \ "USBA 1.0 framework" ;; "$DEFAULT" ) print " All USB 1.1 devices in USB 1.1 uhci ports: " \ "original framework" print " All other USB device / port combinations: " \ "USBA 1.0 framework" ;; * ) print " Unknown" esac print } function cleanup_existing_configuration { eval "rem_drv usba10_ohci $msgroute" eval "rem_drv usba10_ehci $msgroute" eval "rem_drv ohci $msgroute" if [ "$PLATFORM" == "i386" ] ; then eval "rem_drv usba10_uhci $msgroute" eval "rem_drv uhci $msgroute" fi print "Please be aware that the configuration," print "including the controller number of some USB disks, can change." if [ "$1" != "$DEFAULT" ] ; then print "\nNOTE: Default configuration must be restored" print "before pkgrm will successfully remove USB packages.\n" fi } # This function write the configuration file # Arg is the configuration string function maintain_config_file { print "This file maintains usb configuration" >$PERM_CONFIG_FILE print "and is used by the usb configuration script" >$PERM_CONFIG_FILE print "$USB_CONFIG_FLAG $1" >$PERM_CONFIG_FILE } # This function warns if needed drivers are missing. Argument list is of # drivers needed for a given configuration. This function is needed since we # now silence add_drv errors by default. function check_missing_drivers { while [ "$1" ] ; do driver=/kernel/drv/$1 if [ "$PLATFORM" == "sparc" ] ; then if [ `isainfo -b` -eq "64" ] ; then driver=/kernel/drv/sparcv9/$1 fi fi if [ ! -x "$driver" ] ; then print "\nWARNING: Driver $driver" print " doesn't exist or is missing execute" \ "permissions." print " This could render this system unusable " print " if this driver operates keyboards or mice." print " Press ^C now to abort," \ "or any other key to continue" read -r dummy fi shift 1 done } function set_up_all_on_10 { if [ "$current_config" != "$ALL_ON_10" ] ; then if [ "$PLATFORM" == "sparc" ] ; then check_missing_drivers usba10_ohci usba10_ehci else check_missing_drivers usba10_ohci usba10_ehci \ usba10_uhci fi # Let all driver reconfiguration go through without interruption trap '' INT TERM QUIT cleanup_existing_configuration "$ALL_ON_10" eval "add_drv -n -i '\"pciclass,0c0310\"' usba10_ohci $msgroute" eval "add_drv -n -i '\"pciclass,0c0320\"' usba10_ehci $msgroute" # Platform-specific installs. # # Note that add_drv's without aliases are done because # SUNWusb uninistall script expects ohci to be installed on # sparc and uhci to be installed on x86. if [ "$PLATFORM" == "sparc" ] ; then eval "add_drv -n ohci $msgroute" else eval "add_drv -n uhci $msgroute" eval "add_drv -n -i '\"pciclass,0c0300\"' " \ "usba10_uhci $msgroute" fi trap - INT TERM QUIT do_reboot=1 else print "All_on_10 configuration already setup" fi maintain_config_file "$ALL_ON_10" } function set_up_default_sparc { if [ "$current_config" != "$DEFAULT" ] ; then check_missing_drivers usba10_ohci ohci usba10_ehci # Let all driver reconfiguration go through without interruption trap '' INT TERM QUIT cleanup_existing_configuration "$DEFAULT" eval "add_drv -n -i '\"pci1033,35\"' usba10_ohci $msgroute" eval "add_drv -n -i '\"pciclass,0c0310\"' ohci $msgroute" eval "add_drv -n -i '\"pciclass,0c0320\"' usba10_ehci $msgroute" trap - INT TERM QUIT do_reboot=1 else print "Default configuration already setup" fi maintain_config_file "$DEFAULT" } function set_up_default_i386 { if [ "$current_config" != "$DEFAULT" ] ; then check_missing_drivers usba10_uhci uhci usba10_ohci usba10_ehci # Let all driver reconfiguration go through without interruption trap '' INT TERM QUIT cleanup_existing_configuration "$DEFAULT" eval "add_drv -n -i '\"pci1106,3038\"' usba10_uhci $msgroute" eval "add_drv -n -i '\"pciclass,0c0300\"' uhci $msgroute" eval "add_drv -n -i '\"pciclass,0c0310\"' usba10_ohci $msgroute" eval "add_drv -n -i '\"pciclass,0c0320\"' usba10_ehci $msgroute" trap - INT TERM QUIT do_reboot=1 else print "Default configuration already setup" fi maintain_config_file "$DEFAULT" } function print_options_sparc { print "Configuration options:" print " Any USB device in any ohci port: USBA 1.0 framework " \ "[\"1\"]" print print " All USB 1.1 devices in USB 1.1 ohci ports: original framework " \ "[\"D\"]" print " All other USB device / ohci port combinations: USBA 1.0 framework" } function print_options_i386 { print "Configuration options:" print print " Any USB device in any port: USBA 1.0 framework " \ "[\"1\"]" print print " All USB 1.1 devices in USB 1.1 uhci ports: original framework " \ "[\"D\"]" print " All other USB device / port combinations: USBA 1.0 framework" } # Program starts executing here. id | grep "uid=[0-9](" >/dev/null if [ $? -ne 0 ] ; then print "You must run this script as root" exit 0 fi PLATFORM=`uname -p` # Don't check for [usba10_]uhci for now as some systems won't have it. if [ "$PLATFORM" == "sparc" ] ; then if [ ! -f /kernel/drv/sparcv9/usba10_ohci -o \ ! -f /kernel/drv/sparcv9/usba10_ehci -o \ ! -f /kernel/misc/sparcv9/usba10 ] ; then print "This sparc system does not have a " \ "USB Dual Framework environment." exit 0 fi # X86 else if [ ! -f /kernel/drv/usba10_ohci -o \ ! -f /kernel/drv/usba10_ehci -o \ ! -f /kernel/misc/usba10 ] ; then print "This x86 system does not have a " \ "USB Dual Framework environment." exit 0 fi fi # Support the -v option for verbose output while getopts :v option ; do case $option in v) VERBOSE="y" ;; \?) print "Please run as $0 [-v]" print " where -v is verbose" ;; esac done if [ "$VERBOSE" ] ; then msgroute="" else msgroute=">/dev/null 2>&1" fi print "\nWelcome to the USB configuration program.\n" get_current_config_$PLATFORM # Initializes current_config # usba10_uhci exists only on S9U7 X86. # # If it doesn't exist, there is no difference in operation between the # "default" configuration and the all-on-1 configuration. All uhci # hardware will be operated by the original framework. All ohci # hardware will be operated by the USBA 1.0 framework. Print a # message to this effect, since there is no choice to offer the user. force_default="false" if [ "$PLATFORM" == "i386" -a ! -f /kernel/drv/usba10_uhci ] ; then print "Support for running uhci ports on USBA 1.0 is not installed." if [ "$current_config" == "$DEFAULT" ] ; then print "If desired, please install a version of patch " \ "115554 which has it." exit else print "Unknown configuration. Setting default configuration" force_default="true" fi fi if [ "$force_default" == "false" ] ; then print "Current configuration is:" print_config_$PLATFORM "$current_config" print_options_$PLATFORM get_previous_config # Initializes previous_config if [ "$previous_config" ] ; then print "\n Restore previous configuration" \ " [\"P\"]" print_config_$PLATFORM "$previous_config" fi fi completed= # Filled in upon completion below while [ -z $completed ] ; do if [ "$force_default" == "true" ] ; then answer=d else if [ "$previous_config" ] ; then print -n "\nWhat would you like to do [1/D/P]: " else print -n "\nWhat would you like to do [1/D]: " fi read -r answer || exit fi if [ "$answer" == "P" -o "$answer" == "p" ] ; then case "$previous_config" in "$ALL_ON_10" ) answer=1 ;; "$DEFAULT" ) answer=d ;; * ) continue ;; esac fi case "$answer" in 1 ) set_up_all_on_10 completed=yes ;; D|d ) set_up_default_$PLATFORM completed=yes ;; esac done if [ "$do_reboot" ] ; then print "\nA system reboot is needed\n" print "SYSTEM WILL REBOOT IN 5 SECONDS UNLESS INTERRUPTED BY ^C" sleep 5 init 6 fi