Add support to ofpath for usb-storage and fix sbp-2 storage
[yaboot.git] / ybin / ofpath
index f2d55ca0060a7f4dd4a44dd315b7405f9a32c2d1..b4981d79443c1abe323503951998233fec752f02 100755 (executable)
@@ -250,7 +250,7 @@ scsiinfo()
        DEVHOST="$(v=$(echo ${DEVINFO##*Host: scsi}) ; echo ${v%% *})"
        [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVHOST=$DEVHOST"
 
-       if [ "$DEVTYPE" = "Direct-Access" ] ; then
+       if [ "$DEVTYPE" = "Direct-Access" ] || [ "$DEVTYPE" = "Direct-Access-RBC" ] ; then
            DEVCOUNT="$(($DEVCOUNT + 1))"
            [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: DEVCOUNT=$DEVCOUNT"
            if [ "$SUBDEV" = "$DEVCOUNT" ] ; then
@@ -298,10 +298,34 @@ scsi_ofpath()
            echo "${DEVICE_PATH##*device-tree}/@$DEVICE_ID:$PARTITION"
            ;;
        ata_k2|sata_svw)
+            #Not all G5 device trees have a compatible "k2-sata" node 
+            #per channel use parent
            HOST_LIST="$(for i in `find /proc/device-tree -name compatible ` ; do
-                       lgrep "$i" "k2-sata" ; done | sort)"
+                       lgrep "$i" "k2-s-ata" ; done | sort)"
            DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
-           echo "${DEVICE_PATH##*device-tree}/disk@0:$PARTITION"
+           K2_DEVICE_ID=0
+           while [ "$DEVICE_PATH" = "" ] ; do
+               SCSI_HOSTNUMBER=`expr $SCSI_HOSTNUMBER - 1`
+               let "K2_DEVICE_ID += 1"
+               DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
+           done
+           echo "${DEVICE_PATH##*device-tree}/k2-sata@$K2_DEVICE_ID/disk@0:$PARTITION"
+           ;;
+       usb-storage)
+            HOST_LIST="$(for i in `find /proc/device-tree -name name | grep usb` ; do
+                        lgrep "$i" "disk" ; done)"
+            DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
+            echo "${DEVICE_PATH##*device-tree}:$PARTITION"
+           ;;
+       sbp2|"")
+            # sbp-2 driver may not have a dir in /proc/scsi
+            HOST_LIST="$(for i in `find /proc/device-tree -name name` ; do
+                        lgrep "$i" "sbp-2" ; done)"
+            if [ "$SCSI_HOSTNUMBER" = "" ] ; then
+                SCSI_HOSTNUMBER=1
+            fi
+            DEVICE_PATH="$(printhost $SCSI_HOSTNUMBER $HOST_LIST)"
+            echo "${DEVICE_PATH##*device-tree}/disk@0:$PARTITION"
            ;;
        *)
            echo 1>&2 "$PRG: Driver: $SCSI_DRIVER is not supported"
@@ -396,6 +420,10 @@ ide_ofpath()
                local MASTER="/@$(($(cat /proc/ide/${IDEBUS}/channel) * 2 + 0))"
                local SLAVE="/@$(($(cat /proc/ide/${IDEBUS}/channel) * 2 + 1))"
                ;;
+           spi)
+               local MASTER="/disk@$(cat /proc/ide/${IDEBUS}/channel),0"
+               local SLAVE="/disk@$(cat /proc/ide/${IDEBUS}/channel),1"
+               ;;
            *)
                echo 1>&2 "$PRG: Unsupported IDE device type: \"$(cat /proc/device-tree${DEVSPEC}/device_type 2> /dev/null)\""
                return 1
@@ -659,7 +687,7 @@ chrp()
 {
     case "$DEVNODE" in
        sd*)
-           if ls -l /proc/device-tree | grep -q ^lr ; then
+           if ls -l /proc/device-tree | grep -q ^d ; then
                true
            else
                echo 1>&2 "$PRG: /proc/device-tree is broken."
@@ -766,7 +794,7 @@ fixdevfs()
            local DEVTYPE="$(v=$(echo ${DEVINFO##*Type: }) ; echo ${v%% *})"
            [ "$DEBUG" = 1 ] && echo 1>&2 "$PRG: DEBUG: fixdevfs: DEVTYPE=$DEVTYPE"
 
-           if [ "$DEVTYPE" = "Direct-Access" ] ; then
+           if [ "$DEVTYPE" = "Direct-Access" ] || [ "$DEVTYPE" = "Direct-Access-RBC" ] ; then
                ## Lets find out some more information
                ## get the device id.
                local DEVID="$(v=$(echo ${DEVINFO##*Id: }) ; n=$(echo ${v%% *}) ; echo ${n#*0})"
@@ -906,6 +934,8 @@ elif (cat /proc/cpuinfo 2>/dev/null | grep ^motherboard | grep -q AAPL) ; then
     SUBARCH=OldWorld
 elif (cat /proc/cpuinfo 2> /dev/null | grep ^machine | grep -q 'CHRP IBM') ; then
     SUBARCH=CHRP
+elif (cat /proc/cpuinfo 2>/dev/null | grep ^machine | grep -q 'CHRP Pegasos') ; then
+    SUBARCH=Pegasos
 else
     echo 1>&2 "$PRG: This machine is not yet supported"
     exit 1
@@ -928,7 +958,8 @@ PARTITION="${DEVICE##*[a-z]}"
 
 ## use appropriate search for right sub arch.
 case "$SUBARCH" in
-    NewWorld)
+    # Pegasos OF seems to be NewWorld-ish enough to cope with this.
+    NewWorld|Pegasos)
        newworld || exit 1
        ;;
     OldWorld)