Difference between revisions of "Eject Bug Hack"

From Exploitee.rs
Jump to navigationJump to search
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
Here is a git patch 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.  Nothing about this install process is automatic, though once installed it runs fully automatic.  If you don't know how to read a git patch, you'd best learn how.  Improper application of the contents of this patch to your system could certainly brick it.
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 [[Patchloader|here]] and used for deploying other fixes or updates.


Description of what follows, to clarify why it is this way:
<pre>#!/bin/sh
The patch can only be applied to a GTV by manually reading the patch and making the changes described within it by hand. It's merely packaged as a git patch because, well, git is damn awesome and if you can read a git patch it's impossible for the meaning of it to be misunderstood. Git patches are a detailed documenting of additions, deletions, and context.
busybox tr -d '\r' <$0 | busybox sed '1,/^PATCHLOADER BEGIN$/ d; s|PATCHLOADER_SCRIPT=.*|PATCHLOADER_SCRIPT='$0'|' | /bin/sh 2>&1 | busybox tr -d '\r' | busybox sed '/^ *$/ d' # Keep comment here.
exit # Do not change or delete these first two lines or their comments, or DOS breaks.


The patch is divided into sections, the top being a basic email header that serves to identify who, when, and what; following that is a list of files affected, including a line of +/- indicating quantity of insertions and deletions, and note of any new files added or old files deleted along with standard UNIX permissions for those files; following this, the diff of each file affected is included with the format described aboveWithin the diff, any line that begins with a "+" is an inserted lineAny line that begins with a "-" is a removed line (there are none here). Lines around those lines are context. The lines that begin with "@@" indicate which line numbers the context included in the patch should be found at, and what the line numbers should be after the changes.
# patchloader, by Catrane
# Bluray disc eject workaround, by Catrane
#
# USER INSTRUCTIONS
# -----------------
# The patch developer should move these instructions to directly above the
# "DEVELOPER INSTRUCTIONS" line atop this file, deleting these three
# developer instructions lines.
# 1) Save the full contents of this patchloader file to your computerThis may
#    involve copying and pasting, or just downloading.
# 2) Connect to your device using adbadb 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 /tmp/patchloader.sh
# 4) Execute the patchloader by running the following command via adb.
#    adb shell /bin/sh /tmp/patchloader.sh
# 5) Follow any instructions printed out by the patchloader.


It was packaged this way for convenience of publishing the information. I'm told it can be applied via the patch command included in busybox on the rooted GTV. Super cool.  Hopefully someone can fix up my crappy documentation with something a little more usable.
# 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.


Unformatted patch follows:
# NECESSARY LINE
# -----------------
# Don't move or delete this line.  The second line of the file needs it.
PATCHLOADER BEGIN


<pre>From f5b9194ad7865bfdaf43ad676965ff77c5895465 Mon Sep 17 00:00:00 2001
# PRE PATCH
From: Catrane <catrane@gtvhacker>
# -----------------
Date: Mon, 12 Mar 2012 23:21:14 -0500
# Add any commands below which should be run prior to applying the patch.
Subject: [PATCH] Hack workaround to make disc eject work on rooted NSZ-GT1.
Includes 60 second delay before activating as a safety
window.


# END PRE PATCH
# -----------------
# PATCH MD5
# -----------------
# Calculate the MD5 hash of the patch file and set here for validation.
# The easiest 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="7fc5242685822432b8220b4e760629bf  -" # PATCH_MD5="f7be3e1337c0d37b2850fabed5469d34  -"
# MD5 VALIDATION
# -----------------
PATCHLOADER_SCRIPT=$0
extractPatch ()
{
busybox tr -d '\r' <$PATCHLOADER_SCRIPT | busybox sed '1,/^PATCHLOADER PAYLOAD START$/ d; /^PATCHLOADER PAYLOAD END$/,$ d'
}
MD5_CALC="`extractPatch | busybox md5sum`"
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"
echo "A copy of your extracted patch is located at /tmp/extract.patch for verification."
extractPatch > /tmp/extract.patch
fi
exit
fi
# PATCH APPLICATION
# -----------------
extractPatch | busybox patch -p1
if [ "$?" != "0" ]
then
echo "FATAL: Error patching.  Please redownload and try again."
exit
fi
# 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 $PATCHLOADER_SCRIPT
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
# -----------------
# END OF SCRIPT.  DO NOT MOVE OR REMOVE
# -----------------
exit
# PATCH PAYLOAD
# -----------------
# Add patch content after the "PATCHLOADER PAYLOAD START" line here.
PATCHLOADER PAYLOAD START
---
---
  init.eagle.rc                      |    5 +++
  init.eagle.rc                      |    5 +++
Line 90: Line 177:
+if [ ! -z "$1" ]
+if [ ! -z "$1" ]
+then
+then
+   sleep $1
+ sleep $1
+fi
+fi
+
+
Line 97: Line 184:
+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}'
+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
+do
+   if [ "$LASTDECT" != "$(date)" ]
+ if [ "$LASTDECT" != "$(date)" ]
+   then
+ then
+       echo Detected eject failure.
+ echo Detected eject failure.
+       setprop com.sony.btv.discplayer.enable 0
+ setprop com.sony.btv.discplayer.enable 0
+       busybox eject /dev/block/sr0
+ busybox eject /dev/block/sr0
+       setprop com.sony.btv.discplayer.enable 1
+ setprop com.sony.btv.discplayer.enable 1
+       echo Eject failure repair complete.
+ echo Eject failure repair complete.
+       LASTDECT=$(date)
+ LASTDECT=$(date)
+   fi
+ fi
+done
+done
+
+
--  
--  
1.7.6.1</pre>
1.7.6.1
 
PATCHLOADER PAYLOAD END
 
</pre>
=== Using busybox patch to apply this for you ===
 
First off, make sure you have a good copy of the above patch saved in a file with UNIX end of line characters.  Google lead me to http://wiki.secondlife.com/wiki/How_to_avoid_DOS_line_endings_in_Windows_tools which may be of use to you non-Linux folks.  Once you have the patch saved as eject.patch, then follow these steps:


# adb push eject.patch eject.patch
[[Category:Google TV]]
# adb shell
## busybox patch -p1 < eject.patch
## chmod 755 /system/bin/eject_bug_workaround.sh

Latest revision as of 02:21, 4 January 2017

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
busybox tr -d '\r' <$0 | busybox sed '1,/^PATCHLOADER BEGIN$/ d; s|PATCHLOADER_SCRIPT=.*|PATCHLOADER_SCRIPT='$0'|' | /bin/sh 2>&1 | busybox tr -d '\r' | busybox sed '/^ *$/ d' # Keep comment here.
exit # Do not change or delete these first two lines or their comments, or DOS breaks.

# patchloader, by Catrane
# Bluray disc eject workaround, by Catrane
#
# USER INSTRUCTIONS
# -----------------
# The patch developer should move these instructions to directly above the
# "DEVELOPER INSTRUCTIONS" line atop this file, deleting these three
# developer instructions lines.
# 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 /tmp/patchloader.sh
# 4) Execute the patchloader by running the following command via adb.
#    adb shell /bin/sh /tmp/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.

# NECESSARY LINE
# -----------------
# Don't move or delete this line.  The second line of the file needs it.
PATCHLOADER BEGIN

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

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

# PATCH MD5
# -----------------
# Calculate the MD5 hash of the patch file and set here for validation.
# The easiest 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="7fc5242685822432b8220b4e760629bf  -" # PATCH_MD5="f7be3e1337c0d37b2850fabed5469d34  -"

# MD5 VALIDATION
# -----------------
PATCHLOADER_SCRIPT=$0
extractPatch ()
{
	busybox tr -d '\r' <$PATCHLOADER_SCRIPT | busybox sed '1,/^PATCHLOADER PAYLOAD START$/ d; /^PATCHLOADER PAYLOAD END$/,$ d'
}
MD5_CALC="`extractPatch | busybox md5sum`"
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"
		echo "A copy of your extracted patch is located at /tmp/extract.patch for verification."
		extractPatch > /tmp/extract.patch
	fi
	exit
fi

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

# 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 $PATCHLOADER_SCRIPT
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
# -----------------

# END OF SCRIPT.  DO NOT MOVE OR REMOVE
# -----------------
exit

# PATCH PAYLOAD
# -----------------
# Add patch content after the "PATCHLOADER PAYLOAD START" line here.
PATCHLOADER PAYLOAD START
---
 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
PATCHLOADER PAYLOAD END