Difference between revisions of "Eject Bug Hack"

From Exploitee.rs
Jump to navigationJump to search
(Package the patch into a patchloader for end-user use.)
(Add link to Patchloader for developer reference.)
Line 2: Line 2:


The install procedure and the workaround itself are run as root, so there is of course the risk that the user could brick their system with no recourse for recovery.  As with any root-related activity, if you can't afford to lose it, don't do it.
The install procedure and the workaround itself are run as root, so there is of course the risk that the user could brick their system with no recourse for recovery.  As with any root-related activity, if you can't afford to lose it, don't do it.
Developers: The patchloader framework used for this can be found [[Patchloader|here]] and used for deploying other fixes or updates.


<pre>#!/bin/sh
<pre>#!/bin/sh

Revision as of 14:00, 16 March 2012

Here is a patchloader that consists of a script to detect and recover from the eject bug and the modification necessary to make that script be run as a service. The user can follow the instructions below to install this on their GTV.

The install procedure and the workaround itself are run as root, so there is of course the risk that the user could brick their system with no recourse for recovery. As with any root-related activity, if you can't afford to lose it, don't do it.

Developers: The patchloader framework used for this can be found here and used for deploying other fixes or updates.

#!/bin/sh

# patchloader, by Catrane
# Bluray disc eject workaround, by Catrane
#
# USER INSTRUCTIONS
# -----------------
# 1) Save the full contents of this patchloader file to your computer.  This may
#    involve copying and pasting, or just downloading.
# 2) Connect to your device using adb.  adb usage is outside the scope of this
#    document.
# 3) Transfer this patchloader file to your device via adb so that it exists as
#    /patchloader.sh on your device.
#    e.g. adb push patchloader.sh /patchloader.sh
# 4) Execute the patchloader by running the following command via adb.
#    adb shell /bin/sh /patchloader.sh
# 5) Follow any instructions printed out by the patchloader.

# DEVELOPER INSTRUCTIONS
# -----------------
# Search for these sections below:
#  PRE PATCH, PATCH PAYLOAD, PATCH MD5, POST PATCH, and USER INSTRUCTIONS.
# Follow directions in each section.
# Do not modify any other sections.

# PATCHLOADER TRUNCATION CHECK
# -----------------
busybox tail -5 $0 | grep -q "[P]ATCHLOADER END FILE SIGNATURE"
if [ "$?" != "0" ]
then
	echo "FATAL: Patchloader truncated.  Please redownload and try again."
	exit
fi

# PRE PATCH
# -----------------
# Add any commands below which should be run prior to applying the patch.

# END PRE PATCH
# -----------------

# PATCH PAYLOAD
# -----------------
# Add patch content after the "echo" line here.  Be sure to escape any
# characters as necessary and adjust dos2unix/unix2dos settings as appropriate.
echo '
---
 init.eagle.rc                      |    5 +++
 system/bin/eject_bug_workaround.sh |   53 ++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 system/bin/eject_bug_workaround.sh

diff --git a/init.eagle.rc b/init.eagle.rc
index 2004d8a..685ce6f 100644
--- a/init.eagle.rc
+++ b/init.eagle.rc
@@ -329,6 +329,7 @@ on init
     setprop com.sony.btv.discplayer.enable 1
     export DISCPLAYER_KEEP_DMIX_ASIS true
     export DISCPLAYER_LOG_VERBOSE true
+    start ejectworkaround
 
   ## for lighttpd
     mkdir /var/log/lighttpd 0750 system system
@@ -439,6 +440,10 @@ service discplayer /system/bin/discplayer
     user root
     group system
 
+service ejectworkaround /system/bin/eject_bug_workaround.sh 60
+    user root
+    group system
+
 on property:com.sony.btv.discplayer.enable=1
     start discplayer
     start discservice
diff --git a/system/bin/eject_bug_workaround.sh b/system/bin/eject_bug_workaround.sh
new file mode 100644
index 0000000..1f4f282
--- /dev/null
+++ b/system/bin/eject_bug_workaround.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# Reason:
+# There is a known problem that, for an unknown reason, disc eject fails on rooted NSZ-GT1 systems.
+# Side effects of this problem include the possibility that the disc is not ejected and in all cases
+# the problem that discs cannot be played after attempted eject.
+# Rebooting the system fixes the problem, but this solution eliminates the need for reboot.
+
+# Alternative solutions:
+# Restart the device via the power cord or ctrl-alt-del.
+
+# Caveats:
+# This fix does not detect the occurrence of any error, but rather occurrence of a known event which
+# reliably preceeds the error and is reliably followed by the error situation.
+# Error messages and odd behavior may be observed onscreen at the moment of eject, though none of
+# this causes any side-effects.
+
+# Stimulus:
+# From command: logcat -b main
+# Output: I DiscPlayerManager: onStartCommand: com.sony.btv.discplayer.EJECT_DISC
+
+# Response:
+# setprop com.sony.btv.discplayer.enable 0
+# busybox eject /dev/block/sr0
+# setprop com.sony.btv.discplayer.enable 1
+
+# Usage:
+#   eject_bug_workaround.sh &
+#   - Runs workaround in background.
+#   eject_bug_workaround.sh 600 &
+#   - Sleeps for 600 seconds before running, all in background.
+#   - Useful for ensuring a window of recovery in case any side-effects occur.
+
+if [ ! -z "$1" ]
+then
+	sleep $1
+fi
+
+LASTDECT=$(date)
+
+logcat -b main DiscPlayerManager:I *:S|busybox awk '"'"'/onStartCommand: com.sony.btv.discplayer.EJECT_DISC/ {system("echo onStartCommand: com.sony.btv.discplayer.EJECT_DISC")}'"'"'|while busybox awk '"'"'/onStartCommand: com.sony.btv.discplayer.EJECT_DISC/ {exit 0}'"'"'
+do
+	if [ "$LASTDECT" != "$(date)" ]
+	then
+		echo Detected eject failure.
+		setprop com.sony.btv.discplayer.enable 0
+		busybox eject /dev/block/sr0
+		setprop com.sony.btv.discplayer.enable 1
+		echo Eject failure repair complete.
+		LASTDECT=$(date)
+	fi
+done
+
-- 
1.7.6.1
' | busybox dos2unix -u > patchloader.patch

# PATCH MD5
# -----------------
# Calculate the MD5 hash of the patch file and set here for validation.
# Note that the script above starts and ends with a linefeed, so the best way to
# get the right value is to run the script with "GARBAGE" as the MD5 below and
# let it tell you the right value.
PATCH_MD5="023aa9d02d4ef49af781fc65215d4fc7  patchloader.patch"

# MD5 VALIDATION
# -----------------
MD5_CALC="`busybox md5sum patchloader.patch`"
if [ "$PATCH_MD5" != "$MD5_CALC" ]
then
	if [ "GARBAGE" != "$PATCH_MD5" ]
	then
		echo "FATAL: Failure to validate patch integrity.  Please redownload and try again."
	else
		echo "patchloader MD5 hash is as follows.  Users should not see this message."
		echo "$MD5_CALC"
	fi
	rm patchloader.patch
	exit
fi

# PATCH APPLICATION
# -----------------
busybox patch -p1 < patchloader.patch
if [ "$?" != "0" ]
then
	echo "FATAL: Error patching.  Please redownload and try again."
	rm patchloader.patch
	exit
fi
rm patchloader.patch

# POST PATCH
# -----------------
# Add any commands below which should be run prior to applying the patch.
# Include here any instructions for user to reboot if necessary.
chmod 755 /system/bin/eject_bug_workaround.sh
rm $0
echo Please reboot your GTV via the power cord or ctrl-alt-del for this patch
echo to take effect.
echo This patch has a 60 second safety when loaded, so it will not actually run
echo until the GTV has been fully booted for 60 seconds.

# END POST PATCH
# -----------------

# PATCHLOADER END FILE SIGNATURE
# -----------------
# Do not remove this PATCHLOADER END FILE SIGNATURE from the end of the file or
# place anything after it.  Pretty much, the text "PATCHLOADER END FILE SIGNATURE"
# needs to be in the last five lines so we can make sure nothing is missing.