mkinitrd-6.0.93-tuxonice.patch 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. diff -up mkinitrd-6.0.93/mkinitrd.tuxonice mkinitrd-6.0.93/mkinitrd
  2. --- mkinitrd-6.0.93/mkinitrd.tuxonice 2010-03-18 13:27:18.000000000 +0900
  3. +++ mkinitrd-6.0.93/mkinitrd 2010-03-18 14:37:24.000000000 +0900
  4. @@ -74,6 +74,8 @@ LD_SO_CONF=/etc/ld.so.conf
  5. LD_SO_CONF_D=/etc/ld.so.conf.d/
  6. [ -e /etc/sysconfig/mkinitrd ] && . /etc/sysconfig/mkinitrd
  7. +[ -e /etc/sysconfig/mkinitrd-suspend2 ] && . /etc/sysconfig/mkinitrd-suspend2
  8. +[ -e /etc/sysconfig/mkinitrd-tuxonice ] && . /etc/sysconfig/mkinitrd-tuxonice
  9. CONFMODS="$MODULES"
  10. MODULES=""
  11. @@ -91,7 +93,18 @@ modulefile=/etc/modules.conf
  12. rc=0
  13. nolvm=""
  14. nodmraid=""
  15. -
  16. +tuxoniceuserui="none"
  17. +tuxoniceversion="30001"
  18. +tuxonicefwtarget=""
  19. +splashtheme="suspend2"
  20. +
  21. +DSDT="/boot/DSDT.aml"
  22. +SWSUSPPROC="/proc/suspend2"
  23. +USERUIPROC="userui_program"
  24. +FWLOCPROC="filewriter_target"
  25. +RESUMETAR="resume2"
  26. +FWIDENT="Suspend2"
  27. +UIPREFIX="suspend2"
  28. IMAGESIZE=8000
  29. PRESCSIMODS=""
  30. fstab="/etc/fstab"
  31. @@ -111,6 +124,9 @@ usage () {
  32. $cmd " [--image-version] [--force-raid-probe | --omit-raid-modules]"
  33. $cmd " [--with=<module>] [--force-lvm-probe | --omit-lvm-modules]"
  34. $cmd " [--builtin=<module>] [--omit-dmraid] [--net-dev=<interface>]"
  35. + $cmd " [--tuxonice-userui=<none | auto | text | fb>]"
  36. + $cmd " [--tuxonice-version=<version-string>] [--splash=<theme>]"
  37. + $cmd " [--dsdt-location=<location of DSDT-file>]"
  38. $cmd " [--fstab=<fstab>] [--nocompress] <initrd-image> <kernel-version>"
  39. $cmd ""
  40. $cmd " (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)"
  41. @@ -745,6 +761,125 @@ handlegraphics() {
  42. qpopd
  43. }
  44. +IsANumber() {
  45. + case "$1" in *[!0-9]*|"") return 1 ;; esac
  46. + return 0
  47. +}
  48. +
  49. +check_filewriter() {
  50. + # Filewriterhandling for Software Suspend 2
  51. + # we will check for /etc/hibernate/hibernate.conf and the filewriter
  52. + # settings there
  53. + local resume2 fwlocopt fwloc fwsize oldtarget newresume2
  54. +
  55. + if [ -e $1/$RESUMETAR ]; then
  56. + resume2=$(cat $1/$RESUMETAR)
  57. + # if filewriter is already active use that information
  58. + if [ $(echo "$resume2"X | dd bs=5 count=1 2>/dev/null) = "file:" ]; then tuxonicefwtarget=$resume2; return; fi
  59. + else
  60. + # if resume2 does not exist the current kernel is not Suspend 2 enabled,
  61. + # so there is no way to determine filewriters target information anyway
  62. + return
  63. + fi
  64. +
  65. + if [ ! -e $1/$2 ]; then return; fi
  66. + if [ -e /etc/hibernate/tuxonice.conf ]; then
  67. + fwlocopt=$(egrep ^FilewriterLocation /etc/hibernate/tuxonice.conf|tail -n 1)
  68. + elif [ -e /etc/hibernate/suspend2.conf ]; then
  69. + fwlocopt=$(egrep ^FilewriterLocation /etc/hibernate/suspend2.conf|tail -n 1)
  70. + elif [ ! -e /etc/hibernate/hibernate.conf ]; then
  71. + return;
  72. + else
  73. + fwlocopt=$(egrep ^FilewriterLocation /etc/hibernate/hibernate.conf|tail -n 1)
  74. + fi
  75. +
  76. + if [ ! "$fwlocopt" ]; then return; fi
  77. + fwloc=$(echo $fwlocopt | awk '{ print $2 }')
  78. + fwsize=$(echo $fwlocopt | awk '{ print $3 }')
  79. +
  80. + if [ ! -e "$fwloc" ]; then
  81. + if ! IsANumber "$fwsize"; then return; fi
  82. + {
  83. + echo "$FWIDENT"
  84. + dd if=/dev/zero bs=1M count=$fwsize 2>/dev/null
  85. +
  86. + } > "$fwloc"
  87. + fi
  88. +
  89. + oldtarget=$(cat $1/$2)
  90. + sync
  91. + echo "$fwloc" > $1/$2
  92. + newresume2=$(cat $1/$RESUMETAR)
  93. + echo "$oldtarget" > $1/$2
  94. + echo "$resume2" > $1/$RESUMETAR
  95. +
  96. + if [ $(echo $newresume2 | dd bs=5 count=1 2>/dev/null) = "file:" ]; then tuxonicefwtarget=$newresume2; fi
  97. +}
  98. +
  99. +inst_tuxonice() {
  100. + # TuxOnIce stuff
  101. + emit "echo Activating tux on ice"
  102. + userui="$tuxoniceuserui";
  103. + if [ "x$tuxoniceuserui" == "xauto" ]; then
  104. + if [ -f /sbin/${UIPREFIX}ui_fbsplash ]; then
  105. + userui="fb";
  106. + elif [ -f /sbin/${UIPREFIX}ui_text ]; then
  107. + userui="text";
  108. + else
  109. + userui="none";
  110. + fi
  111. + fi
  112. + if [ "x$userui" != "xnone" ]; then
  113. + if [ "x$userui" == "xfb" ]; then
  114. + if [ -f /sbin/${UIPREFIX}ui_fbsplash ]; then
  115. + inst /sbin/${UIPREFIX}ui_fbsplash "$2" /bin/${UIPREFIX}ui_fbsplash
  116. + if [ -e /etc/splash/${splashtheme} ]; then
  117. + mkdir "$2/etc/splash"
  118. + cp -prH /etc/splash/${splashtheme}/ "$2/etc/splash/"
  119. + fi
  120. + # check if splashtheme is a symlink and add one to initrd if that is the case
  121. + if [ -L /etc/splash/${splashtheme} ]; then
  122. + dlink=` find /etc/splash/${splashtheme} -printf '%l' `
  123. + dlink=$(basename $dlink)
  124. + ln -sf ${splashtheme} "$2/etc/splash/$dlink"
  125. + fi
  126. + if [ -e $2/etc/splash/{$splashtheme} ]; then
  127. + if [ ! -e $2/etc/splash/TuxOnIce ]; then
  128. + ln -sf ${splashtheme} "$2/etc/splash/TuxOnIce"
  129. + fi
  130. + if [ ! -e $2/etc/splash/suspend2 ]; then
  131. + ln -sf ${splashtheme} "$2/etc/splash/suspend2"
  132. + fi
  133. + fi
  134. + if [ -f /sbin/splash_helper ]; then
  135. + inst /sbin/splash_helper "$2" /bin/splash_helper
  136. + fi
  137. + emit "echo /bin/${UIPREFIX}ui_fbsplash > $1/$4"
  138. + else
  139. + error "WARNING: framebuffer UI for suspend not found, skipping."
  140. + fi
  141. + elif [ "x$userui" == "xtext" ]; then
  142. + if [ -f /sbin/${UIPREFIX}ui_text ]; then
  143. + inst /sbin/${UIPREFIX}ui_text "$2" /bin/${UIPREFIX}ui_text
  144. + emit "echo /bin/${UIPREFIX}ui_text > $1/$4"
  145. + else
  146. + error "WARNING: text UI for suspend not found, skipping."
  147. + fi
  148. + else
  149. + error "WARNING: unknown UI \"$userui\" specified."
  150. + fi
  151. + fi
  152. +
  153. + # First try to resume with the parameter present on the kernel commandline
  154. + emit "echo Trying to resume from target specified as $RESUMETAR on cmdline."
  155. + emit "echo 1 > $1/do_resume"
  156. +
  157. + # Then we will try the swapdevice/filetarget that was present while creating the initrd
  158. + emit "echo Trying to resume from $3."
  159. + emit "echo $3 > $1/$RESUMETAR"
  160. + emit "echo 1 > $1/do_resume"
  161. +}
  162. +
  163. savedargs=$*
  164. while [ $# -gt 0 ]; do
  165. case $1 in
  166. @@ -945,6 +1080,54 @@ while [ $# -gt 0 ]; do
  167. shift
  168. fi
  169. ;;
  170. + --splash*)
  171. + if echo $1 | grep -q '=' ; then
  172. + splashtheme=`echo $1 | sed 's/^--splash=//'`
  173. + else
  174. + splashtheme=$2
  175. + shift
  176. + fi
  177. + ;;
  178. + --tuxonice-userui*)
  179. + if echo $1 | grep -q '=' ; then
  180. + tuxoniceuserui=`echo $1 | sed 's/^--tuxonice-userui=//'`
  181. + else
  182. + tuxoniceuserui=$2
  183. + shift
  184. + fi
  185. + ;;
  186. + --tuxonice-version*)
  187. + if echo $1 | grep -q '=' ; then
  188. + tuxoniceversion=`echo $1 | sed 's/^--tuxonice-version=//'`
  189. + else
  190. + tuxoniceversion=$2
  191. + shift
  192. + fi
  193. + ;;
  194. + --suspend2-userui*)
  195. + if echo $1 | grep -q '=' ; then
  196. + tuxoniceuserui=`echo $1 | sed 's/^--suspend2-userui=//'`
  197. + else
  198. + tuxoniceuserui=$2
  199. + shift
  200. + fi
  201. + ;;
  202. + --suspend2-version*)
  203. + if echo $1 | grep -q '=' ; then
  204. + tuxoniceversion=`echo $1 | sed 's/^--suspend2-version=//'`
  205. + else
  206. + tuxoniceversion=$2
  207. + shift
  208. + fi
  209. + ;;
  210. + --dsdt-location*)
  211. + if echo $1 | grep -q '=' ; then
  212. + DSDT=`echo $1 | sed 's/^--dsdt-location=//'`
  213. + else
  214. + DSDT=$2
  215. + shift
  216. + fi
  217. + ;;
  218. --help)
  219. usage -n
  220. ;;
  221. @@ -962,6 +1145,22 @@ while [ $# -gt 0 ]; do
  222. shift
  223. done
  224. +if [ "$tuxoniceversion" -lt "20108" ]; then
  225. + SWSUSPPROC="/proc/software_suspend"
  226. +elif [ "$tuxoniceversion" -ge "20208" ]; then
  227. + SWSUSPPROC="/sys/power/suspend2"
  228. + USERUIPROC="user_interface/program"
  229. + FWLOCPROC="filewriter/target"
  230. +fi
  231. +if [ "$tuxoniceversion" -ge "20211" ]; then
  232. + RESUMETAR="resume"
  233. +fi
  234. +if [ "$tuxoniceversion" -ge "20212" ]; then
  235. + SWSUSPPROC="/sys/power/tuxonice"
  236. + FWIDENT="TuxOnIce"
  237. + UIPREFIX="tuxonice"
  238. +fi
  239. +
  240. if [ -z "$target" -o -z "$kernel" ]; then
  241. usage
  242. fi
  243. @@ -1186,6 +1385,7 @@ fi
  244. mkdir -p $MNTIMAGE
  245. mkdir -p $MNTIMAGE/lib/firmware
  246. mkdir -p $MNTIMAGE/lib/modules/$kernel
  247. +mkdir -p $MNTIMAGE/lib/splash
  248. mkdir -p $MNTIMAGE/bin
  249. mkdir -p $MNTIMAGE/etc
  250. mkdir -p $MNTIMAGE/dev
  251. @@ -1220,6 +1420,10 @@ excludemods() {
  252. echo $output
  253. }
  254. +if [ -e "$DSDT" ]; then
  255. + inst "$DSDT" "$MNTIMAGE/DSDT.aml"
  256. +fi
  257. +
  258. if [ -n "$excludemodules" ]; then
  259. MODULES=$(excludemods $MODULES)
  260. availmodules=$(excludemods $availmodules)
  261. @@ -1253,6 +1457,7 @@ done
  262. mknod $MNTIMAGE/dev/tty c 5 0
  263. mknod $MNTIMAGE/dev/console c 5 1
  264. mknod $MNTIMAGE/dev/ptmx c 5 2
  265. +mknod $MNTIMAGE/dev/fb0 c 29 0
  266. if [ -n "$raiddevices" ]; then
  267. inst /sbin/mdadm "$MNTIMAGE"
  268. @@ -1496,6 +1701,7 @@ mknod /dev/console c 5 1
  269. mknod /dev/ptmx c 5 2
  270. mknod /dev/fb c 29 0
  271. mknod /dev/hvc0 c 229 0
  272. +mknod /dev/fb0 c 29 0
  273. EOF
  274. # XXX really we need to openvt too, in case someting changes the
  275. @@ -1628,8 +1834,21 @@ for cryptdev in ${!cryptolv@} ; do
  276. emitcrypto `eval echo '$'$cryptdev`
  277. done
  278. -if [ -z "$noresume" -a -n "$thawdev" ]; then
  279. - emit "resume $thawdev"
  280. +if [ -z "$noresume" ]; then
  281. + if [ -n "$thawdev" ]; then
  282. + emit "resume $thawdev"
  283. + fi
  284. + check_filewriter $SWSUSPPROC $FWLOCPROC
  285. + swsuspdev="$thawdev"
  286. + if [ -n "$tuxonicefwtarget" ]; then
  287. + inst_tuxonice $SWSUSPPROC $MNTIMAGE $tuxonicefwtarget $USERUIPROC
  288. + elif [ -n "$swsuspdev" ]; then
  289. + if [[ "$swsuspdev" =~ ^(UUID=|LABEL=) ]]; then
  290. + swsuspdev=$(resolve_device_name "$swsuspdev")
  291. + fi
  292. +
  293. + inst_tuxonice $SWSUSPPROC $MNTIMAGE swap:$swsuspdev $USERUIPROC
  294. + fi
  295. fi
  296. if [ -n "$loopfs" ]; then