source: overlays/install-overlay/root/functions.sh @ 5e26f0b

releng/10.0.1releng/10.0.2
Last change on this file since 5e26f0b was 5e26f0b, checked in by Kris Moore <kris@…>, 5 months ago

Add a important fix to video detection. For some reason on 10.x Xorg isn't detecting
video cards with difference BusID settings... This causes chaos when the board
is on a weird pci device, or has multiple video devices installed.

Now we will first probe for vgapci0, and setup an xorg.conf based upon that using
the correct BusID value.

If that fails, we will then test vgapci1, and lastly fallback to vesa mode

  • Property mode set to 100755
File size: 3.7 KB
Line 
1#!/bin/sh
2# Functions we source for starting the install / live mode
3###########################################################
4
5detect_x() 
6{
7  # Check if the user requested VESA mode
8  xvesa="NO"
9  v=`/bin/kenv xvesa 2>/dev/null`
10  if [ $? -eq 0 ]; then
11        xvesa=$v
12  fi
13
14  # If we are starting in VESA only mode
15  if [ "$xvesa" = "YES" ]; then
16    cp /root/cardDetect/XF86Config.compat /etc/X11/xorg.conf
17    return
18  fi
19
20  # First check if we are running as a VirtualBox guest
21  pciconf -lv | grep -q "VirtualBox"
22  if [ $? -eq 0 ] ; then cp /root/cardDetect/xorg.conf.virtualbox /etc/X11/xorg.conf ; return; fi
23
24  # Try the second card, since many optimus / amd hybrids have Intel on secondary
25  cfg_card_busid "1"
26
27}
28
29cfg_card_busid()
30{
31  whichcard="$1"
32
33  # This script will manually set BusID for the first or second vgapciX device
34  # For some reason in 10.0, it no longer auto-probes for different VGA devices :(
35  inCard=0
36  pciconf -lv > /tmp/.pciconf.$$
37  while read line
38  do
39    echo $line | grep -q "^vgapci"
40    if [ $? -eq 0 ] ; then
41       curCard=`echo $line | cut -d "@" -f 1 | sed 's|vgapci||g'`
42       busID="`echo $line | cut -d ':' -f 2-4`"
43       inCard=1
44       continue
45    fi
46
47    echo $line | grep -q "subclass"
48    if [ $? -eq 0 ] ; then inCard=0; continue; fi
49
50    if [ $inCard -eq 1 ] ; then
51       echo $line | grep -q "vendor"
52       if [ $? -eq 0 ]; then
53          case $curCard in
54             0) card1=`echo $line | cut -d "'" -f 2`
55                card1bus="$busID"
56                ;;
57             1) card2=`echo $line | cut -d "'" -f 2`
58                card2bus="$busID"
59                ;;
60             *) ;;
61          esac
62       fi
63    fi
64  done < /tmp/.pciconf.$$
65  rm /tmp/.pciconf.$$
66
67  # Which card are we configuring
68  if [ "$whichcard" = "1" ] ; then
69    cfgCard="$card1"
70    cfgCardBusID="$card1bus"
71  else
72    cfgCard="$card2"
73    cfgCardBusID="$card2bus"
74  fi
75
76  # No detected, return 1
77  if [ -z "$cfgCard" ] ; then return 1; fi
78
79  # Is this an Intel chipset?
80  echo "$cfgCard" | grep -q -i -e "intel"
81  if [ $? -eq 0 ] ; then
82     driver="intel"
83  fi
84  echo "$cfgCard" | grep -q -i -e "nvidia"
85  if [ $? -eq 0 ] ; then
86     driver="nvidia"
87  fi
88
89  # Found a card, lets try an xorg config for it
90  cp ${PROGDIR}/cardDetect/XF86Config.default /etc/X11/xorg.conf
91  if [ -n "$driver" ] ; then
92    echo "
93Section \"Device\"
94        Identifier      \"Card0\"
95        Driver          \"$driver\"
96        BusID           \"${cfgCardBusID}\"
97EndSection
98  " >> /etc/X11/xorg.conf
99  else
100    echo "
101Section \"Device\"
102        Identifier      \"Card0\"
103        BusID           \"${cfgCardBusID}\"
104EndSection
105  " >> /etc/X11/xorg.conf
106  fi
107
108  return 0
109}
110
111start_xorg()
112{
113
114  # Now run the X auto-detection
115  detect_x
116
117  # Run X Now
118  startx
119  if [ ! -e "/tmp/.xstarted" ]
120  then
121    # Failed to start X
122    # Lets try again with a secondary video card
123    rm /etc/X11/xorg.conf 2>/dev/null
124    cfg_card_busid "2"
125
126    startx
127    if [ ! -e "/tmp/.xstarted" ]
128    then
129      echo "ERROR: Failed to start X in SAFE mode... Trying VESA mode..."
130      rm /etc/X11/xorg.conf
131      cp /root/cardDetect/XF86Config.compat /etc/X11/xorg.conf
132      startx
133     if [ ! -e "/tmp/.xstarted" ]
134      then
135        # Try the Intel driver, since nvidia/vesa will fail on optimus cards
136        cp /root/cardDetect/XF86Config.intel /etc/X11/xorg.conf
137        startx
138        if [ ! -e "/tmp/.xstarted" ]
139        then
140          echo "ERROR: Failed to start X..."
141          echo "Dropping to failsafe console... Edit /etc/X11/xorg.conf, and run #startx to bring up the GUI."
142          echo "[Press Enter to Continue]"
143          read tmp
144          /bin/sh
145        fi
146      fi
147    fi
148  fi
149
150}
151
152rtn()
153{
154   echo "Press ENTER to continue"
155   read tmp
156}
Note: See TracBrowser for help on using the repository browser.