framebufferwizard 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. #!/bin/sh
  2. #(c) Copyright 2005 Barry Kauler www.goosee.com/puppy
  3. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  4. #pup up to 1.0.3 only used Xvesa Kdrive server.
  5. #v1.0.4 introduces framebuffer Xfbdev Kdriver server, choice
  6. #at first bootup.
  7. PSFND="`ps`"
  8. MSGWIN="WARNING: CHOOSING \"YES\" WILL CAUSE IMMEDIATE REBOOT!"
  9. if [ ! "`echo -n "$PSFND" | grep "/bin/xwin"`" = "" ];then
  10. MSGWIN="PLEASE CLOSE ALL OTHER WINDOWS BEFORE CHOOSE \"YES\"!
  11. DO THAT RIGHT NOW IF YOU ARE GOING TO CHOOSE THE \"YES\" OPTION!"
  12. fi
  13. MSGFB="
  14. CURRENT STATUS:
  15. The Xfbdev Kdrive framebuffer X server is currently not running.
  16. "
  17. if [ "`readlink /usr/X11R7/bin/X`" = "Xfbdev" ];then
  18. MSGFB="
  19. CURRENT STATUS:
  20. The Xfbdev Kdrive framebuffer X server is currently running,
  21. and the video setting currently is:
  22. `cat /etc/videofb`
  23. "
  24. fi
  25. if [ "`readlink /usr/X11R7/bin/X`" = "Xvesa" ];then
  26. MSGFB="
  27. The Xfbdev Kdrive framebuffer X server is currently not running.
  28. The Xvesa Kdrive X server is now running.
  29. To keep the current situation, select \"No\" button.
  30. To adjust Xvesa settings, run the Xvesa Video Wizard.
  31. "
  32. fi
  33. #will call this script from /etc/rc.d/rc.local0, after /usr is loaded,
  34. #as this script and modinfo are both in /usr/sbin/.
  35. #rc.local0 appends "boot" on the commandline...
  36. if [ ! "$1" = "boot" ];then
  37. if [ ! -f /usr/X11R7/bin/Xfbdev ];then #precaution.
  38. dialog --title "Xfbdev Video Wizard" --msgbox "Sorry, this build of Puppy does not
  39. have the Xfbdev Kdrive X server.
  40. Press ENTER key to exit..." 0 0
  41. exit
  42. fi
  43. dialog --title "Xfbdev Video Wizard" --yesno "Welcome to the Framebuffer Wizard!
  44. Puppy has two different Kdrive X servers, Xvesa and Xfbdev.
  45. Xvesa is the default and works on most PCs. Xfbdev may work
  46. on some video hardware that Xvesa does not work properly on,
  47. also Xfbdev allows adjustment of the screen refresh frequency.
  48. The Framebuffer Wizard can only make changes at bootup, so if
  49. you answer \"Yes\" here, the PC will reboot immediately and the
  50. Wizard will run.
  51. $MSGFB
  52. $MSGWIN
  53. Press ENTER key while \"Yes\" highlighted (for immediate reboot)
  54. otherwise TAB or RIGHT-ARROW to highlight \"No\" then ENTER..." 0 0
  55. if [ $? -eq 0 ];then
  56. #rm -f /usr/X11R7/bin/X
  57. echo -n "1" > /root/.fbbootflag
  58. sync
  59. if [ "`echo -n "$PSFND" | grep "/bin/xwin"`" = "" ];then
  60. exec reboot #running without X.
  61. else
  62. exec /usr/X11R7/bin/fvwmreboot #a window manager is running.
  63. fi
  64. fi
  65. exit
  66. fi
  67. #did pass "boot" param, so continuing...
  68. loadfbfunc() {
  69. case $VIDEOMODULE in
  70. sisfb)
  71. MODEXEC="modprobe sisfb mode=$RESXYB rate=$FBRATE"
  72. modprobe sisfb mode=$RESXYB rate=$FBRATE 2> /tmp/fbmnterr.txt
  73. RETVAL=$?
  74. ;;
  75. tridentfb)
  76. MODEXEC="modprobe tridentfb mode=$RESXYN bpp=$RESBPP"
  77. modprobe tridentfb mode=$RESXYN bpp=$RESBPP 2> /tmp/fbmnterr.txt
  78. RETVAL=$?
  79. ;;
  80. intelfb)
  81. MODEXEC="modprobe intelfb mode=${RESXYN}-${RESBPP}@${FBRATE} accel=1 mtrr=1"
  82. modprobe intelfb mode=${RESXYN}\-${RESBPP}@${FBRATE} accel=1 mtrr=1 2> /tmp/fbmnterr.txt
  83. RETVAL=$?
  84. ;;
  85. neofb)
  86. MODEXEC='modprobe neofb #note, no params.'
  87. modprobe neofb 2> /tmp/fbmnterr.txt #note, no params?
  88. RETVAL=$?
  89. ;;
  90. rivafb)
  91. MODEXEC='modprobe rivafb #note, no params.'
  92. modprobe rivafb 2> /tmp/fbmnterr.txt #note, no params?
  93. RETVAL=$?
  94. ;;
  95. esac
  96. }
  97. #just use the existing configuration if /root/.fbbootflag=0...
  98. if [ ! -f /root/.fbbootflag ];then
  99. echo -n "1" > /root/.fbbootflag
  100. fi
  101. if [ "`cat /root/.fbbootflag`" = "0" ];then
  102. if [ "`readlink /usr/X11R7/bin/X`" = "Xfbdev" ];then
  103. if [ -f /etc/videofb ];then #precaution
  104. VIDEOFB="`cat /etc/videofb`"
  105. VIDEOMODULE="`echo -n "$VIDEOFB" | tr " " "\n" | grep "module=" | cut -f 2 -d '='`"
  106. FBRATE="`echo -n "$VIDEOFB" | tr " " "\n" | grep "rate=" | cut -f 2 -d '='`"
  107. RESXYB="`echo -n "$VIDEOFB" | tr " " "\n" | grep "mode=" | cut -f 2 -d '='`"
  108. FBMEM="`echo -n "$VIDEOFB" | tr " " "\n" | grep "mem=" | cut -f 2 -d '='`"
  109. RESXYN="`echo -n "$RESXYB" | cut -f 1-2 -d 'x'`"
  110. RESBPP="`echo -n "$RESXYB" | cut -f 3 -d 'x'`"
  111. loadfbfunc
  112. sleep 1
  113. if [ ! $RETVAL -eq 0 ];then
  114. ln -sf Xvesa /usr/X11R7/bin/X
  115. fi
  116. else #precaution
  117. ln -sf Xvesa /usr/X11R7/bin/X
  118. fi
  119. else
  120. #well, do not need the fb modules...
  121. rm -rf /lib/modules/2.4/video/*/*fb.* 2> /dev/null
  122. rm -rf /lib/modules/2.4/video/*fb.* 2> /dev/null
  123. rm -rf /lib/modules/2.6/video/*/*fb.* 2> /dev/null
  124. rm -rf /lib/modules/2.6/video/*fb.* 2> /dev/null
  125. fi
  126. exit #use Xvesa, or whatever X points to.
  127. fi
  128. ###############################################
  129. #okay, this is the wizard part of the script...
  130. if [ -f /usr/X11R7/bin/Xvesa ];then
  131. Xvesa -listmodes > /tmp/Xmodes.txt 2>&1
  132. else
  133. echo -n "" > /tmp/Xmodes.txt
  134. fi
  135. FBMODE=""
  136. MSG0=""
  137. FBMODE="1024x768x16"
  138. FBMODULE=""
  139. FBMEM=""
  140. VIDEOFB=""
  141. if [ -f /etc/videofb ];then
  142. VIDEOFB="`cat /etc/videofb`"
  143. FBMODULE="`echo -n "$VIDEOFB" | tr " " "\n" | grep "module=" | cut -f 2 -d '='`"
  144. FBRATE="`echo -n "$VIDEOFB" | tr " " "\n" | grep "rate=" | cut -f 2 -d '='`"
  145. FBMODE="`echo -n "$VIDEOFB" | tr " " "\n" | grep "mode=" | cut -f 2 -d '='`"
  146. FBMEM="`echo -n "$VIDEOFB" | tr " " "\n" | grep "mem=" | cut -f 2 -d '='`"
  147. #MSG0="(Note, your last choice was the $FBMODULE module)
  148. MSG0="(Previous: $VIDEOFB)
  149. "
  150. fi
  151. if [ ! "$FBRATE" ];then
  152. FBRATE="60"
  153. fi
  154. #VIDEOINFO="`cat /proc/pci | grep --ignore-case --extended-regexp "vga|video"`"
  155. VIDEOINFO="`cat /proc/pci | grep "VGA" | cut -f 2-4 -d ':'`"
  156. VIDEOMODULE=""
  157. if [ ! "`echo "$VIDEOINFO" | grep "SiS"`" = "" ];then
  158. VIDEOCHIP="SiS"
  159. VIDEOMODULE="sisfb"
  160. #FBDESCRIPTION="SiS 300/540/630/730/315/550/65x/661/74x/330/760 framebuffer device"
  161. fi
  162. if [ ! "`echo "$VIDEOINFO" | grep "Trident"`" = "" ];then
  163. VIDEOCHIP="Trident"
  164. VIDEOMODULE="tridentfb"
  165. #FBDESCRIPTION="Framebuffer driver for Trident cards"
  166. fi
  167. if [ ! "`echo "$VIDEOINFO" | grep "Intel"`" = "" ];then
  168. VIDEOCHIP="Intel"
  169. VIDEOMODULE="intelfb"
  170. #FBDESCRIPTION="Framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G chipset"
  171. fi
  172. if [ ! "`echo "$VIDEOINFO" | grep -i "NeoMagic"`" = "" ];then
  173. VIDEOCHIP="NeoMagic"
  174. VIDEOMODULE="neofb"
  175. fi
  176. if [ ! "`echo "$VIDEOINFO" | grep -i "nVidia"`" = "" ];then
  177. VIDEOCHIP="nVidia"
  178. VIDEOMODULE="rivafb"
  179. fi
  180. if [ -f /usr/X11R7/bin/Xvesa ];then
  181. MSGXVESA=" Puppy will default to using the Xvesa Kdrive X server,
  182. which works on most PCs and is usually best choice."
  183. DEFLABEL="Xvesa"
  184. else
  185. MSGXVESA=" Puppy would like to fall back to the Xvesa Kdrive X server,
  186. but it is not installed. So, cannot run X with Xvesa."
  187. DEFLABEL="Default"
  188. fi
  189. #okay to run modinfo as /usr/sbin is available...
  190. FBDESCRIPTION="`modinfo $VIDEOMODULE | grep "description:" | cut -f 2-4 -d ':' | cut -b 1-68`"
  191. if [ "$VIDEOMODULE" ];then
  192. MSG1="Your PC has a $VIDEOCHIP video chip, described as:
  193. $VIDEOINFO
  194. The $VIDEOMODULE framebuffer driver module description:
  195. $FBDESCRIPTION
  196. ...so perhaps will work with your video chip?
  197. $MSG0
  198. If you just press the ENTER key, Puppy will default to not using
  199. a framebuffer driver and the default will be:
  200. $MSGXVESA
  201. Note: you can try both. Choose the default now maybe, later you
  202. will be able to run the Video Wizard and make a different choice.
  203. Press ENTER key while \"${DEFLABEL}\" highlighted for default, else TAB or
  204. ARROW-KEY to highlight \"Framebuffer\" then ENTER for framebuffer..."
  205. else
  206. #framebuffer option not currently supported.
  207. dialog --title "Xfbdev Video Wizard" --msgbox "This version of Puppy does not seem to have any suitable
  208. kernel framebuffer driver module for the video hardware.
  209. So, defaulting to:
  210. $MSGXVESA
  211. Press ENTER key to continue..."
  212. rm -f /etc/videofb
  213. if [ -f /usr/X11R7/bin/Xvesa ];then
  214. ln -sf Xvesa /usr/X11R7/bin/X #precaution.
  215. fi
  216. #to prevent wizard from running in setup mode at next entry...
  217. echo -n "0" > /root/.fbbootflag #precaution.
  218. #well, do not need the fb modules...
  219. rm -rf /lib/modules/2.4/video/*/*fb.* 2> /dev/null
  220. rm -rf /lib/modules/2.4/video/*fb.* 2> /dev/null
  221. rm -rf /lib/modules/2.6/video/*/*fb.* 2> /dev/null
  222. rm -rf /lib/modules/2.6/video/*fb.* 2> /dev/null
  223. exit
  224. fi
  225. dialog --title "Xfbdev Video Wizard" --yes-label "$DEFLABEL" --no-label "Framebuffer" --yesno "$MSG1" 0 0
  226. if [ $? -eq 0 ];then
  227. #rm -f /etc/videofb
  228. if [ -f /usr/X11R7/bin/Xvesa ];then
  229. ln -sf Xvesa /usr/X11R7/bin/X
  230. fi
  231. #to prevent wizard from running in setup mode at next entry...
  232. echo -n "0" > /root/.fbbootflag
  233. #well, do not need the fb modules...
  234. rm -rf /lib/modules/2.4/video/*/*fb.* 2> /dev/null
  235. rm -rf /lib/modules/2.4/video/*fb.* 2> /dev/null
  236. rm -rf /lib/modules/2.6/video/*/*fb.* 2> /dev/null
  237. rm -rf /lib/modules/2.6/video/*fb.* 2> /dev/null
  238. exit
  239. fi
  240. ALLVIDCHOICES="640x480x16
  241. 640x480x24
  242. 800x600x16
  243. 800x600x24
  244. 1024x768x16
  245. 1024x768x24
  246. 1280x960x16
  247. 1280x1024x16
  248. 1280x1024x24
  249. 1600x1200x16
  250. 1600x1200x24
  251. 1920x1440x16
  252. 1920x1440x24"
  253. VIDEOCHOICES="`cat /tmp/Xmodes.txt | grep --extended-regexp "640x480x16|640x480x24|800x600x16|800x600x24|1024x768x16|1024x768x24|1280x960x16|1280x1024x16|1280x1024x24|1600x1200x16|1600x1200x24|1920x1440x16|1920x1440x24" | tr ':' ' ' | tr -s ' ' | cut -f 2 -d " " | sort`"
  254. NEWCHOICES="`echo -n "$VIDEOCHOICES" | grep -v "$FBMODE" | tr "\n" "V" | sed -e 's/V/_supported off V/g' | tr "V" "\n"`"
  255. OLDCHOICE=""
  256. if [ "$FBMODE" ];then
  257. if [ "`echo -n "$VIDEOCHOICES" | grep "$FBMODE"`" = "" ];then
  258. OLDCHOICE="${FBMODE}_unknown on
  259. "
  260. else
  261. OLDCHOICE="${FBMODE}_supported on
  262. "
  263. fi
  264. fi
  265. #find unsupported modes...
  266. #and insert column 1 with a tag number...
  267. BADCHOICES=""
  268. FINALCHOICES=""
  269. for ONEMODE in `echo -n "$ALLVIDCHOICES" | tr "\n" " "`
  270. do
  271. TAGCNT="$ONEMODE"
  272. if [ "`echo -n "$OLDCHOICE$NEWCHOICES" | grep "$ONEMODE"`" = "" ];then
  273. FINALCHOICES="${FINALCHOICES} ${TAGCNT} ${ONEMODE}_unknown off "
  274. else
  275. ONEMODE="`echo -n "$OLDCHOICE$NEWCHOICES" | grep "$ONEMODE"`"
  276. FINALCHOICES="${FINALCHOICES} ${TAGCNT} ${ONEMODE}"
  277. fi
  278. done
  279. dialog --title "Xfbdev Video Wizard" --radiolist "Please choose a video mode. The format is widthxheightxbits.
  280. Width and height are in pixels, 16/24 bits = 65,536/16,777,216 colors.
  281. Note: _supported means mode confirmed supported by the video card.
  282. _unknown will not work with Xvesa but may work with framebuffer.
  283. Use DOWN-ARROW then press SPACEBAR on desired choice then
  284. press ENTER key..." 0 0 0 $FINALCHOICES 2>/tmp/tag.txt
  285. CHOSENTAG="`cat /tmp/tag.txt 2>/dev/null`"
  286. if [ "$CHOSENTAG" ];then
  287. FBMODE="$CHOSENTAG"
  288. else
  289. if [ ! "$FBMODE" ];then
  290. FBMODE="1024x768x16"
  291. fi
  292. fi
  293. RATES='56 Hertz_for_very_low_quality_monitor
  294. 60 Hertz_for_low_quality_monitor_or_high_res
  295. 72 Hertz
  296. 75 Hertz
  297. 85 Hertz
  298. 90 Hertz'
  299. NEWRATES="`echo "$RATES" | grep -v "$FBRATE" | tr "\n" "W" | sed -e 's/W/ off /g'`"
  300. OLDRATE="`echo "$FBRATE" | tr "\n" "W" | sed -e 's/W/ Hertz on /g'`"
  301. dialog --title "Xfbdev Video Wizard" --radiolist "You have chosen $FBMODE.
  302. Now you need to choose the screen refresh frequency.
  303. Please be very careful about this -- choosing a higher rate
  304. than your monitor is specified for can damage the monitor.
  305. IF IN DOUBT, CHOOSE 60Hz.
  306. (a really old 14 inch monitor may be limited to 800x600-56)
  307. NOTE: If make wrong choice, there is opportunity to try again.
  308. Use DOWN-ARROW then press SPACEBAR on desired choice then
  309. press ENTER key..." 0 0 0 $OLDRATE$NEWRATES 2>/tmp/tag.txt
  310. CHOSENTAG="`cat /tmp/tag.txt 2>/dev/null`"
  311. if [ "$CHOSENTAG" ];then
  312. FBRATE="$CHOSENTAG"
  313. fi
  314. #so far we have these. examples:
  315. #VIDEOMODULE="sisfb" FBMODE="0x0117 1024x768x16" FBRATE="60"
  316. #now need to decide on a mem= allocation for each mode.
  317. #1024x768x16 needs 12288K ...maybe we can leave this out, let it auto-assign.
  318. #then compose the /etc/videofb line:
  319. # sisfb mode=1024x768x16 rate=60 mem=12288
  320. #this can be executed as a postfix to modprobe.
  321. RESXYB="`echo -n "$FBMODE" | cut -f 2 -d " "`"
  322. RESXYN="`echo -n "$RESXYB" | cut -f 1-2 -d 'x'`"
  323. RESBPP="`echo -n "$RESXYB" | cut -f 3 -d 'x'`"
  324. if [ -f /etc/videofb ];then
  325. cp -f /etc/videofb /etc/videofb.old
  326. fi
  327. echo "module=$VIDEOMODULE mode=$RESXYB rate=$FBRATE mem=" > /etc/videofb
  328. dialog --title "Xfbdev Video Wizard" --msgbox "Okay, just about to take the plunge.
  329. Here are the choices you have made:
  330. `cat /etc/videofb`
  331. If the next screen shows a nice dialog box, like this one, then the
  332. video mode change was successful. If the screen is blank or garbage,
  333. then failure.
  334. If successful, press ENTER key within 30 seconds.
  335. If failure, either hit CTRL-ALT-DEL to cause immediate reboot, or
  336. wait for 30 seconds and timeout will assume failure.
  337. REMEMBER, Garbage screen: CTRL-ALT-DEL or wait 30 second timeout!
  338. Press ENTER key now to switch to new video mode..." 0 0
  339. #load fb module...
  340. loadfbfunc
  341. sleep 3
  342. #if loading of fb modules succeeds, relink /usr/X11R7/bin/X to Xfbdev,
  343. #otherwise to Xvesa.
  344. if [ $RETVAL -eq 0 ];then
  345. dialog --timeout 30 --title "Xfbdev Video Wizard" --msgbox "Okay, have loaded framebuffer driver with this command:
  346. $MODEXEC
  347. which seems to have been successful.
  348. X graphics mode will run with the Xfbdev Kdrive X server.
  349. NOTE: framebufferwizard can run from the console if X not work.
  350. PLEASE PRESS ENTER KEY WITHIN 30 SECONDS OF THIS WINDOW APPEARING
  351. OTHERWISE FAILURE WILL BE ASSUMED!
  352. Press the ENTER key to continue..." 0 0
  353. if [ $? -eq 0 ];then
  354. #works.
  355. ln -sf Xfbdev /usr/X11R7/bin/X
  356. else
  357. #failure
  358. if [ -f /usr/X11R7/bin/Xvesa ];then
  359. ln -sf Xvesa /usr/X11R7/bin/X #precaution.
  360. fi
  361. sync
  362. exec reboot
  363. #...wizard will start again on reboot.
  364. fi
  365. else
  366. MSGFIN1=""
  367. if [ -f /usr/X11R7/bin/Xvesa ];then
  368. MSGFIN1="Note, if you choose \"Quit\", Puppy will use the Xvesa server.
  369. "
  370. fi
  371. dialog --title "Xfbdev Video Wizard" --yes-label "Rerun" --no-label "Quit" --yesno "Attempted to load framebuffer driver with this command:
  372. $MODEXEC
  373. but it was unsuccessful. This is the error message:
  374. `cat /tmp/fbmnterr.txt | head -n 5`
  375. Select \"Rerun\" button to rerun the Framebuffer Wizard and
  376. try again, or \"Quit\" to quit.
  377. $MSGFIN1
  378. NOTE: framebufferwizard can run from the console if X not work." 0 0
  379. if [ $? -eq 0 ];then
  380. sync
  381. exec /usr/sbin/framebufferwizard
  382. #...exits from script.
  383. else
  384. if [ -f /etc/videofb.old ];then
  385. cp -f /etc/videofb.old /etc/videofb
  386. fi
  387. if [ -f /usr/X11R7/bin/Xvesa ];then
  388. ln -sf Xvesa /usr/X11R7/bin/X #precaution.
  389. fi
  390. fi
  391. fi
  392. sync
  393. #to prevent wizard from running in setup mode at next entry...
  394. echo -n "0" > /root/.fbbootflag
  395. #END#