summaryrefslogtreecommitdiff
path: root/utils/hwpatcher/patch.S
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-06-24 18:04:17 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2014-06-24 18:07:56 +0200
commitc9a028cc183d638c16ca9a8858b783b1830be16f (patch)
tree1bd29843ec0b8d3eb80a6209d1c4e32144175dfe /utils/hwpatcher/patch.S
parent761f59c9e3be0ffd77d2dc1b8095a3b877badeda (diff)
downloadrockbox-c9a028cc183d638c16ca9a8858b783b1830be16f.zip
rockbox-c9a028cc183d638c16ca9a8858b783b1830be16f.tar.gz
rockbox-c9a028cc183d638c16ca9a8858b783b1830be16f.tar.bz2
rockbox-c9a028cc183d638c16ca9a8858b783b1830be16f.tar.xz
Introduce hwpatcher, a tool to patch binaries
This tool is a scriptable (lua) tool to patch binaries, it supports: - raw binary - ELF - SB(v1/v2) It also contains some basic routines to parse and generate useful arm/thumb code like jump or register load/store. This is very useful to take a firmware and patch an interrupt vector or some code to jump to an extra payload added to the binary. Examples are provided for several STMP based target which the payload is expected to be hwstub, and also for the Sansa View. A typical patcher usually requires three elements: - the lua patcher itself - the payload (hwstub for example) - (optional) a small stub either to jump properly to the payload or determine under which circumstance to do the jump (hold a key for example) Change-Id: I6d36020a3bc9e636615ac8221b7591ade5f251e3
Diffstat (limited to 'utils/hwpatcher/patch.S')
-rw-r--r--utils/hwpatcher/patch.S87
1 files changed, 87 insertions, 0 deletions
diff --git a/utils/hwpatcher/patch.S b/utils/hwpatcher/patch.S
new file mode 100644
index 0000000..6c27e29
--- /dev/null
+++ b/utils/hwpatcher/patch.S
@@ -0,0 +1,87 @@
+.text
+.global _start
+_start:
+ b exec
+branch_addr:
+ .word kill
+hw_power_sts:
+#if defined(CREATIVE_ZEN)
+ .word 0x800440b0 /* STMP3700 */
+#else
+ .word 0x800440c0 /* IMX233 */
+#endif
+hw_pinctrl_din0:
+ .word 0x80018600
+hw_pinctrl_din1:
+ .word 0x80018610
+hw_pinctrl_din2:
+ .word 0x80018620
+kill:
+ ldr pc, branch_addr
+exec:
+#if defined(SANSA_FUZEPLUS)
+ /* check PSWITCH=1 (power button pressed) */
+ ldr r0, hw_power_sts
+ ldr r0, [r0]
+ mov r0, r0, lsr #20
+ and r0, #3
+ cmp r0, #1
+ bne ret
+ /* check B1P30=0 (volume down pressed) */
+ ldr r0, hw_pinctrl_din1
+ ldr r0, [r0]
+ mov r0, r0, lsr #30
+ ands r0, #1
+ beq kill
+#elif defined(CREATIVE_ZENXFI3)
+ /* check PSWITCH=1 (power button pressed) */
+ ldr r0, hw_power_sts
+ ldr r0, [r0]
+ mov r0, r0, lsr #20
+ and r0, #3
+ cmp r0, #1
+ bne ret
+ /* check B2P07=0 (volume down pressed) */
+ ldr r0, hw_pinctrl_din2
+ ldr r0, [r0]
+ mov r0, r0, lsr #7
+ ands r0, #1
+ beq kill
+#elif defined(CREATIVE_ZENXFI2)
+ /* check B0P11=0 (power button pressed) and B0P14 (select button pressed) */
+ ldr r0, hw_pinctrl_din0
+ ldr r0, [r0]
+ mov r0, r0, lsr #11
+ tst r0, #1
+ bne ret
+ mov r0, r0, lsr #3
+ tst r0, #1
+ beq kill
+#elif defined(CREATIVE_ZEN)
+ /* check PSWITCH=1 (power button pressed) */
+ ldr r0, hw_power_sts
+ ldr r0, [r0]
+ mov r0, r0, lsr #18
+ and r0, #3
+ cmp r0, #0
+ bne kill
+#elif defined(SONY_NWZ)
+ /* check PSWITCH=3 (power button pressed) */
+ ldr r0, hw_power_sts
+ ldr r0, [r0]
+ mov r0, r0, lsr #20
+ and r0, #3
+ cmp r0, #3
+ beq kill
+#elif defined(CREATIVE_ZENXFISTYLE)
+ /* check PSWITCH=1 (power button pressed) */
+ ldr r0, hw_power_sts
+ ldr r0, [r0]
+ mov r0, r0, lsr #20
+ and r0, #3
+ cmp r0, #1
+ beq kill
+#else
+#error implement me
+#endif
+ret: \ No newline at end of file