Gentoo Archives: gentoo-commits

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