source: projects/specs/trunk/m/mkinitrd/mkinitrd-6.0.93-tuxonice.patch @ 806

Revision 806, 9.5 KB checked in by daisuke, 14 years ago (diff)

mkinitrd: remove bash4ism (patch21), add vine patches to repo

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