CRUX PPC
A lightweight GNU/Linux distribution for PowerPC!
Subversion Repository
Parent Directory
|
Revision Log
Revision 62 -
(hide annotations)
Thu Feb 3 22:44:55 2011 UTC (2 years, 4 months ago) by acrux
File size: 4319 byte(s)
Thu Feb 3 22:44:55 2011 UTC (2 years, 4 months ago) by acrux
File size: 4319 byte(s)
synced with 2.7RC2
| 1 | acrux | 62 | #!/bin/sh |
| 2 | ############################################################################### | ||
| 3 | # Determines the Open Firmware path based on the linux device name | ||
| 4 | # | ||
| 5 | # Joseph Jezak <josejx@gentoo.org> Copyright (C) 2010 | ||
| 6 | # Rewrite of OFPath for newer kernels/scsi configurations | ||
| 7 | # | ||
| 8 | # This program is free software; you can redistribute it and/or | ||
| 9 | # modify it under the terms of the GNU General Public License | ||
| 10 | # as published by the Free Software Foundation; either version 2 | ||
| 11 | # of the License, or (at your option) any later version. | ||
| 12 | # | ||
| 13 | # This program is distributed in the hope that it will be useful, | ||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | # GNU General Public License for more details. | ||
| 17 | # | ||
| 18 | # You should have received a copy of the GNU General Public License | ||
| 19 | # along with this program; if not, write to the Free Software | ||
| 20 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 21 | # | ||
| 22 | ############################################################################### | ||
| 23 | |||
| 24 | ### Set this to 1 to turn on debugging messages | ||
| 25 | DEBUG=0 | ||
| 26 | |||
| 27 | ### Find the device tree | ||
| 28 | if [ ! -e /proc/device-tree ]; then | ||
| 29 | echo 1>&2 "ofpath: Cannot find the device tree!" | ||
| 30 | exit 1 | ||
| 31 | fi | ||
| 32 | DEV_TREE="/proc/device-tree" | ||
| 33 | |||
| 34 | ### Check if sys is mounted | ||
| 35 | if ! (grep -q '.* .* sysfs ' /proc/mounts 2> /dev/null) ; then | ||
| 36 | echo 1>&2 "ofpath: sysfs must be mounted for ofpath to support this system" | ||
| 37 | exit 1 | ||
| 38 | fi | ||
| 39 | |||
| 40 | ### Get the sysfs mount point | ||
| 41 | SYS="$(m=`grep '.* .* sysfs ' /proc/mounts | head -n 1` ; echo `d=${m#* };echo ${d%% *}`)" | ||
| 42 | if [ -z "$SYS" -o ! -d "$SYS" ] ; then | ||
| 43 | echo 1>&2 "ofpath: Unable to determine sysfs mountpoint" | ||
| 44 | exit 1 | ||
| 45 | fi | ||
| 46 | |||
| 47 | |||
| 48 | ### Get the device from the user | ||
| 49 | ### We dereference links to support devices like /dev/cdrom1 | ||
| 50 | DEVICE=$1 | ||
| 51 | if [ -z "$DEVICE" ]; then | ||
| 52 | echo 1>&2 "ofpath: No device specified!" | ||
| 53 | exit 1 | ||
| 54 | fi | ||
| 55 | DEVICE=$(readlink -f "$DEVICE") | ||
| 56 | DEVICE=$(basename $DEVICE) | ||
| 57 | if [ -z "$DEVICE" ] || [ ! -e "/dev/$DEVICE" ]; then | ||
| 58 | echo 1>&2 "ofpath: Invalid device: /dev/$DEVICE" | ||
| 59 | exit 1 | ||
| 60 | fi | ||
| 61 | [ "$DEBUG" = 1 ] && echo "Device is: $DEVICE" | ||
| 62 | |||
| 63 | ### Get the partition if we have it | ||
| 64 | case ${DEVICE} in | ||
| 65 | sd*) PARTITION="${DEVICE#sd?}" ;; | ||
| 66 | ### No partition for sr/sg devices | ||
| 67 | sr*|sg*) PARTITION="${DEVICE#sr?}" ;; | ||
| 68 | hd*) PARTITION="${DEVICE#hd?}" ;; | ||
| 69 | *) echo "Unknown device string."; exit 1;; | ||
| 70 | esac | ||
| 71 | if [ ! -z "$PARTITION" ] && [ "$DEBUG" = 1 ]; then | ||
| 72 | echo "Partition: $PARTITION" | ||
| 73 | fi | ||
| 74 | |||
| 75 | ### Get the disk device name | ||
| 76 | DISK_NAME="${DEVICE%%${PARTITION}}" | ||
| 77 | [ "$DEBUG" = 1 ] && echo "Disk Name: $DISK_NAME" | ||
| 78 | |||
| 79 | ### Find the devspec for the controller | ||
| 80 | DEVPATH=$(cd -P "$SYS/block/${DISK_NAME}/device" && pwd) | ||
| 81 | if [ -z "$DEVPATH" ]; then | ||
| 82 | echo "Unable to determine device path!" | ||
| 83 | exit 1 | ||
| 84 | fi | ||
| 85 | [ "$DEBUG" = 1 ] && echo "Devpath is: $DEVPATH" | ||
| 86 | |||
| 87 | ### Get the OF Path of the controller | ||
| 88 | case ${DISK_NAME} in | ||
| 89 | sd*|sg*|sr*) CONTROLLER_PATH=$(cat ${DEVPATH}/../../../devspec) ;; | ||
| 90 | hd*) CONTROLLER_PATH=$(cat ${DEVPATH}/../../devspec) ;; | ||
| 91 | *) CONTROLLER_PATH="" ;; | ||
| 92 | esac | ||
| 93 | if [ -z "$CONTROLLER_PATH" ]; then | ||
| 94 | echo "Unable to determine controller path!" | ||
| 95 | exit 1 | ||
| 96 | fi | ||
| 97 | [ "$DEBUG" = 1 ] && echo "Controller Path is: $CONTROLLER_PATH" | ||
| 98 | |||
| 99 | ### Generate the disk number and partition info | ||
| 100 | case ${DISK_NAME} in | ||
| 101 | sd*|sg*|sr*) | ||
| 102 | DISK_NO="$(cd ${DEVPATH}/../; pwd)"; | ||
| 103 | DISK_NO="${DISK_NO##*:}"; | ||
| 104 | ;; | ||
| 105 | hd*) | ||
| 106 | DISK_NO="$(cd ${DEVPATH}/../; pwd)"; | ||
| 107 | DISK_NO="${DISK_NO##*ide}"; | ||
| 108 | ;; | ||
| 109 | *) echo "Unsupported disk type!"; exit 1 ;; | ||
| 110 | esac | ||
| 111 | DISK_NO="disk@${DISK_NO}:" | ||
| 112 | [ "$DEBUG" = 1 ] && echo "Disk Number: ${DISK_NO}" | ||
| 113 | |||
| 114 | ### We need to get the controller port path (if it has one) | ||
| 115 | if [ ! -d "$DEV_TREE/$CONTROLLER_PATH/disk" ] && [ ! -d "$DEV_TREE/$CONTROLLER_PATH/$DISK_NO" ]; then | ||
| 116 | ### FIXME I don't know if every scsi device uses the host nomenclature | ||
| 117 | case ${DISK_NAME} in | ||
| 118 | sd*|sg*|sr*) | ||
| 119 | PORT="$(cd ${DEVPATH}/../../; pwd)"; | ||
| 120 | PORT="${PORT##*host}"; | ||
| 121 | CTL_PORT="${CONTROLLER_PATH##*/}"; | ||
| 122 | CTL_PORT="${CTL_PORT%%-root*}"; | ||
| 123 | PORT="$CTL_PORT@$PORT" | ||
| 124 | [ "$DEBUG" = 1 ] && echo "Port: $PORT" | ||
| 125 | ;; | ||
| 126 | *) echo "Unsupported disk type!"; exit 1 ;; | ||
| 127 | esac | ||
| 128 | fi | ||
| 129 | |||
| 130 | ### Add the partition information if required | ||
| 131 | if [ ! -z $PARTITION ]; then | ||
| 132 | DISK_NO="$DISK_NO$PARTITION" | ||
| 133 | fi | ||
| 134 | |||
| 135 | ### Build the OF Path | ||
| 136 | if [ -z "$PORT" ]; then | ||
| 137 | OFPATH="$CONTROLLER_PATH/$DISK_NO" | ||
| 138 | else | ||
| 139 | OFPATH="$CONTROLLER_PATH/${PORT}/$DISK_NO" | ||
| 140 | fi | ||
| 141 | |||
| 142 | ### Print out the ofpath | ||
| 143 | echo $OFPATH |
Properties
| Name | Value |
|---|---|
| svn:executable | * |