├── README.md └── bootrec ├── busybox ├── extract_elf_ramdisk ├── init.sh └── keycheck /README.md: -------------------------------------------------------------------------------- 1 | # Sony recovery boot script 2 | 3 | This script will chain load an Android recovery from the FOTAKernel partition. 4 | 5 | ## Instructions to kernel developer 6 | 7 | * Put **bootrec** folder in the root of your ramdisk. 8 | * If not on ARM64, replace **busybox** and **extract_elf_ramdisk** binaries. 9 | * Move your **/init** to **/init.real** 10 | * Symlink **/init** to **/bootrec/init.sh** 11 | * ??? 12 | * Profit. 13 | 14 | The **init.sh** script is setup for Xperia Z5/Z5C. 15 | On other devices you might have to change some paths at the top of the script file. 16 | -------------------------------------------------------------------------------- /bootrec/busybox: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackfagner/twrp-sony-recovery-boot-script/beca072234caa7ab9916fb541cda8e774e292aa1/bootrec/busybox -------------------------------------------------------------------------------- /bootrec/extract_elf_ramdisk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackfagner/twrp-sony-recovery-boot-script/beca072234caa7ab9916fb541cda8e774e292aa1/bootrec/extract_elf_ramdisk -------------------------------------------------------------------------------- /bootrec/init.sh: -------------------------------------------------------------------------------- 1 | #!/bootrec/busybox sh 2 | 3 | ######################################## 4 | # Sony FOTAKernel Recovery Boot Script # 5 | # Author: github.com/jackfagner # 6 | # Version: 1.2 # 7 | ######################################## 8 | 9 | # Disable printing/echo of commands 10 | set +x 11 | 12 | ############ 13 | # SETTINGS # 14 | ############ 15 | 16 | REAL_INIT="/init.real" 17 | 18 | DEV_FOTA_NODE="/dev/block/mmcblk0p32 b 259 0" 19 | DEV_FOTA="/dev/block/mmcblk0p32" 20 | 21 | LOG_FILE="/bootrec/boot-log.txt" 22 | RECOVERY_CPIO="/bootrec/recovery.cpio" 23 | 24 | KEY_EVENT_DELAY=3 25 | WARMBOOT_RECOVERY=0x77665502 26 | 27 | LED_RED="/sys/class/leds/led:rgb_red/brightness" 28 | LED_GREEN="/sys/class/leds/led:rgb_green/brightness" 29 | LED_BLUE="/sys/class/leds/led:rgb_blue/brightness" 30 | 31 | 32 | ############ 33 | # CODE # 34 | ############ 35 | 36 | # Save current PATH variable, then change it 37 | _PATH="$PATH" 38 | export PATH=/bootrec:/sbin 39 | 40 | # Use root as base dir 41 | busybox cd / 42 | 43 | # Log current date/time 44 | busybox date >> ${LOG_FILE} 45 | 46 | # Redirect stdout and stderr to log file 47 | exec >> ${LOG_FILE} 2>&1 48 | 49 | # Re-enable printing commands 50 | set -x 51 | 52 | # Delete this script 53 | busybox rm -f /init 54 | 55 | # Create directories 56 | busybox mkdir -m 755 -p /dev/input 57 | busybox mkdir -m 555 -p /proc 58 | busybox mkdir -m 755 -p /sys 59 | 60 | # Create device nodes 61 | # Per linux Documentation/devices.txt 62 | for i in $(busybox seq 0 12); do 63 | busybox mknod -m 600 /dev/input/event${i} c 13 $(busybox expr 64 + ${i}) 64 | done 65 | busybox mknod -m 666 /dev/null c 1 3 66 | 67 | # Mount filesystems 68 | busybox mount -t proc proc /proc 69 | busybox mount -t sysfs sysfs /sys 70 | 71 | # Methods for controlling LED 72 | led_amber() { 73 | busybox echo 255 > ${LED_RED} 74 | busybox echo 255 > ${LED_GREEN} 75 | busybox echo 0 > ${LED_BLUE} 76 | } 77 | led_orange() { 78 | busybox echo 255 > ${LED_RED} 79 | busybox echo 100 > ${LED_GREEN} 80 | busybox echo 0 > ${LED_BLUE} 81 | } 82 | led_off() { 83 | busybox echo 0 > ${LED_RED} 84 | busybox echo 0 > ${LED_GREEN} 85 | busybox echo 0 > ${LED_BLUE} 86 | } 87 | 88 | # Set LED to amber to indicate it's time to press keys 89 | led_amber 90 | 91 | # Keycheck will exit with code 42 if vol up/down is pressed 92 | busybox timeout -t ${KEY_EVENT_DELAY} keycheck 93 | 94 | # Check if we detected volume key pressing or the user rebooted into recovery mode 95 | if [ $? -eq 42 ] || busybox grep -q warmboot=${WARMBOOT_RECOVERY} /proc/cmdline; then 96 | echo "Entering Recovery Mode" >> ${LOG_FILE} 97 | 98 | # Set LED to orange to indicate recovery mode 99 | led_orange 100 | 101 | # Create directory and device node for FOTA partition 102 | busybox mkdir -m 755 -p /dev/block 103 | busybox mknod -m 600 ${DEV_FOTA_NODE} 104 | 105 | # Make sure root is in read-write mode 106 | busybox mount -o remount,rw / 107 | 108 | # extract_elf_ramdisk needs sh in PATH 109 | # FIXME: unconfirmed! We can probably skip sh 110 | busybox ln -sf /bootrec/busybox /bootrec/sh 111 | 112 | # Extract recovery ramdisk 113 | extract_elf_ramdisk -i ${DEV_FOTA} -o ${RECOVERY_CPIO} -t / 114 | 115 | # Remove sh again (if we created it) 116 | busybox rm -f /bootrec/sh 117 | 118 | # Clean up rc scripts in root to avoid problems 119 | busybox rm -f /init*.rc /init*.sh 120 | 121 | # Unpack ramdisk to root 122 | busybox cpio -i -u < ${RECOVERY_CPIO} 123 | 124 | # Delete recovery ramdisk 125 | busybox rm -f ${RECOVERY_CPIO} 126 | else 127 | echo "Booting Normally" >> ${LOG_FILE} 128 | 129 | # Move real init script into position 130 | busybox mv ${REAL_INIT} /init 131 | fi 132 | 133 | # Clean up, start with turning LED off 134 | led_off 135 | 136 | # Remove folders and devices 137 | busybox umount /proc 138 | busybox umount /sys 139 | busybox rm -rf /dev/* 140 | 141 | # Remove dangerous files to avoid security problems 142 | busybox rm -f /bootrec/extract_elf_ramdisk /bootrec/init.sh /bootrec/busybox /bootrec/keycheck 143 | 144 | # Reset PATH 145 | export PATH="${_PATH}" 146 | 147 | # All done, now boot 148 | exec /init $@ 149 | -------------------------------------------------------------------------------- /bootrec/keycheck: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackfagner/twrp-sony-recovery-boot-script/beca072234caa7ab9916fb541cda8e774e292aa1/bootrec/keycheck --------------------------------------------------------------------------------