1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
diff --git a/rbutil/mkamsboot/mkamsboot.c b/rbutil/mkamsboot/mkamsboot.c
index 2897e48..4e0e293 100644
--- a/rbutil/mkamsboot/mkamsboot.c
+++ b/rbutil/mkamsboot/mkamsboot.c
@@ -475,6 +475,17 @@ void patch_firmware(
 
     /* Insert vectors, they won't overwrite the OF version string */
 
+    /* Let's find what the reset vector points to */
+    uint32_t reset = get_uint32le(&buf[0x400]);
+    if ((reset & 0xfffff000) == 0xe59ff000) { /* reset vector is ldr pc, =XXX */
+        uint32_t offset = (reset&0xfff) + 8;
+        if (!(offset % 4)) {
+            uint32_t dest = get_uint32le(&buf[0x400 + offset]);
+            if (dest < 0x200 && !(dest% 4))
+                put_uint32le(&buf[0x400 + dest], 0xe3a0fc02 ); // mov pc, #0x200
+        }
+    }
+
     /* Reset vector: branch 0x200 bytes away, to our dualboot code */
     static const uint8_t b_0x200[4] = { 0x7e, 0x00, 0x00, 0xea }; // b 0x200
     memcpy(buf + 0x400, b_0x200, sizeof(b_0x200));