CloneNum3

Copy_Script_all-in-one.sh

Jun 12th, 2016
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.13 KB | None | 0 0
  1. #!/bin/bash
  2. function boot_mode {
  3. echo "Boot Mode"
  4. echo "0=Normal"
  5. echo "1=Recovery"
  6. echo "2=Easy-Recovery"
  7. echo "3=Re-Easy-Recovery"
  8. echo "Chooses the mode in which to boot the device"
  9. echo -n "Choice [0-3]:"
  10. read response
  11. if [ $response -ge 0 ] && [ $response -le 3 ]
  12. then
  13.   boot_mode=${response}
  14.   echo "Confirmed: boot_mode=[${boot_mode}]"
  15. else
  16.   echo "Invalid response, exiting"
  17.   exit 1
  18. fi
  19. }
  20.  
  21. function launch_mode {
  22. echo "Launch Mode"
  23. echo "0=APL"
  24. echo "1=TestMode.apk"
  25. echo "2=Slave TestMode"
  26. echo "3=Boot Error"
  27. echo "Chooses the mode in which to boot the device"
  28. echo -n "Choice [0-3]:"
  29. read response
  30. if [ $response -ge 0 ] && [ $response -le 3 ]
  31. then
  32.   launch_mode=${response}
  33.   echo "Confirmed: launch_mode=[${launch_mode}]"
  34. else
  35.   echo "Invalid response, exiting"
  36.   exit 1
  37. fi
  38. }
  39.  
  40. function test_sub_mode {
  41. echo "Test Sub Mode"
  42. echo "0=Tech Mode"
  43. echo "1=TestMode_A.key"
  44. echo "2=Serv"
  45. echo "Chooses the mode in which to boot the device"
  46. echo -n "Choice [0-2]:"
  47. read response
  48. if [ $response -ge 0 ] && [ $response -le 2 ]
  49. then
  50.   test_sub_mode=${response}
  51.   echo "Confirmed: test_sub_mode=[${test_sub_mode}]"
  52. else
  53.   echo "Invalid response, exiting"
  54.   exit 1
  55. fi
  56. }
  57.  
  58. function boot_image_flag {
  59. echo "Boot Image Flag"
  60. echo "0=SideA"
  61. echo "1=SideB"
  62. echo "Chooses the mode in which to boot the device"
  63. echo -n "Choice [0-1]:"
  64. read response
  65. if [ $response -ge 0 ] && [ $response -le 1 ]
  66. then
  67.   boot_image_flag=${response}
  68.   echo "Confirmed: boot_image_flag=[${boot_image_flag}]"
  69. else
  70.   echo "Invalid response, exiting"
  71.   exit 1
  72. fi
  73. }
  74.  
  75. function recovery_image_flag {
  76. echo "Recovery Image Flag"
  77. echo "0=SideA"
  78. echo "1=SideB"
  79. echo "Chooses the mode in which to recovery the device"
  80. echo -n "Choice [0-1]:"
  81. read response
  82. if [ $response -ge 0 ] && [ $response -le 1 ]
  83. then
  84.   recovery_image_flag=${response}
  85.   echo "Confirmed: recovery_image_flag=[${recovery_image_flag}]"
  86. else
  87.   echo "Invalid response, exiting"
  88.   exit 1
  89. fi
  90. }
  91.  
  92. function debug_flag {
  93. echo "Debug Flag"
  94. echo "0=Disabled"
  95. echo "1=Debug"
  96. echo "2=Debug+Console"
  97. echo "Chooses the mode in which to recovery the device"
  98. echo -n "Choice [0-2]:"
  99. read response
  100. if [ $response -ge 0 ] && [ $response -le 2 ]
  101. then
  102.   debug_flag=${response}
  103.   echo "Confirmed: debug_flag=[${debug_flag}]"
  104. else
  105.   echo "Invalid response, exiting"
  106.   exit 1
  107. fi
  108. }
  109.  
  110. function otg_switch {
  111. echo "OTG Switch"
  112. echo "0=Host Mode"
  113. echo "1=Device Mode"
  114. echo "Chooses the mode in which to recovery the device"
  115. echo -n "Choice [0-1]:"
  116. read response
  117. if [ $response -ge 0 ] && [ $response -le 1 ]
  118. then
  119.   otg_switch=${response}
  120.   echo "Confirmed: otg_switch=[${otg_switch}]"
  121. else
  122.   echo "Invalid response, exiting"
  123.   exit 1
  124. fi
  125. }
  126.  
  127. function mem_check_flag {
  128. echo "Memory Check"
  129. echo "0=No"
  130. echo "1=Yes"
  131. echo "Chooses the mode in which to recovery the device"
  132. echo -n "Choice [0-1]:"
  133. read response
  134. if [ $response -ge 0 ] && [ $response -le 1 ]
  135. then
  136.   mem_check_flag=${response}
  137.   echo "Confirmed: mem_check_flag=[${mem_check_flag}]"
  138. else
  139.   echo "Invalid response, exiting"
  140.   exit 1
  141. fi
  142. }
  143.  
  144. function warp_boot {
  145. echo "Warp Boot"
  146. echo "0=SideA"
  147. echo "1=SideB"
  148. echo "Chooses the mode in which to recovery the device"
  149. echo -n "Choice [0-1]:"
  150. read response
  151. if [ $response -ge 0 ] && [ $response -le 1 ]
  152. then
  153.   warp_boot=${response}
  154.   echo "Confirmed: warp_boot=[${warp_boot}]"
  155. else
  156.   echo "Invalid response, exiting"
  157.   exit 1
  158. fi
  159. }
  160.  
  161. function sub_boot_mode {
  162. echo "Sub Boot Mode"
  163. echo "0=Enable WARP!"
  164. echo "1=Disable WARP!"
  165. echo "2=Snapshot"
  166. echo "Chooses the mode in which to recovery the device"
  167. echo -n "Choice [0-2]:"
  168. read response
  169. if [ $response -ge 0 ] && [ $response -le 2 ]
  170. then
  171.   sub_boot_mode=${response}
  172.   echo "Confirmed: sub_boot_mode=[${sub_boot_mode}]"
  173. else
  174.   echo "Invalid response, exiting"
  175.   exit 1
  176. fi
  177. }
  178.  
  179. function choice_password {
  180. echo "Choice Password"
  181. echo "0=LKPFeD4BcVzESR2Y"
  182. echo "1=<No Password>"
  183. echo "Chooses the mode in which to boot the device"
  184. echo -n "Choice [0-1]:"
  185. read response
  186. if [ $response -ge 0 ] && [ $response -le 1 ]
  187. then
  188.   choice_password=${response}
  189.   echo "Confirmed: choice_password=[${choice_password}]"
  190. else
  191.   echo "Invalid response, exiting"
  192.   exit 1
  193. fi
  194. }
  195.  
  196. function update_selection {
  197. echo "Update Selection"
  198. echo "0=Recovery-Update"
  199. echo "1=uboot update"
  200. echo "2=boot update"
  201. echo "3=boot.img update"
  202. echo "4=recovery.img update"
  203. echo "5=system.img update"
  204. echo "6=opening data update"
  205. echo "7=UI update"
  206. echo "8=All image update"
  207. echo "9=TESTMODE_N.KEY"
  208. echo "a=easyrecovery copy"
  209. echo "b=easyrecovery copy&verify"
  210. echo "c=password key copy&verify"
  211. echo "d=easyrecovery mode change"
  212. echo "Chooses the mode in which to boot the device"
  213. echo -n "Choice [0-9,a-d]"
  214. read response
  215. echo "$response" | grep -q '^[0-9a-d]$'
  216. if [[ $? -eq 0 ]]
  217. then
  218.   update_selection=${response}
  219.   echo "Confirmed: update_selection=[${update_selection}]"
  220. else
  221.   echo "Invalid response, exiting"
  222.   exit 1
  223. fi
  224. }
  225.  
  226. function update_sub_device {
  227. echo "Update Sub Device"
  228. echo "0=SD Card"
  229. echo "1=USB1"
  230. echo "2=USB2"
  231. echo "Chooses the mode in which to recovery the device"
  232. echo -n "Choice [0-2]:"
  233. read response
  234. if [ $response -ge 0 ] && [ $response -le 2 ]
  235. then
  236.   update_sub_device=${response}
  237.   echo "Confirmed: update_sub_device=[${update_sub_device}]"
  238. else
  239.   echo "Invalid response, exiting"
  240.   exit 1
  241. fi
  242. }
  243.  
  244. function ui_update_flag {
  245. echo "UI Update Flag"
  246. echo "0=Non-Updating"
  247. echo "1=Updating"
  248. echo "Chooses the mode in which to recovery the device"
  249. echo -n "Choice [0-1]:"
  250. read response
  251. if [ $response -ge 0 ] && [ $response -le 1 ]
  252. then
  253.   ui_update_flag=${response}
  254.   echo "Confirmed: ui_update_flag=[${ui_update_flag}]"
  255. else
  256.   echo "Invalid response, exiting"
  257.   exit 1
  258. fi
  259. }
  260.  
  261. [ -f /tmp/bsp_image ] && rm -Rf /tmp/bsp_image
  262. mkdir -p /tmp/bsp_image
  263.  
  264. bsp_image_file=/tmp/bsp_image/newbsp.img
  265. sd_password_file=/tmp/bsp_image/warpdisabledbsp.img
  266. testmode_a_key_file=/tmp/bsp_image/testmode_a.key
  267. sdunlock_file=/tmp/bsp_image/sdunlock
  268.  
  269. echo -ne "\x44\x44\x44\x45\x44\x47\x44\x6c\x47\x6c\x46\x68\x45\x59\x44\x57" > ${testmode_a_key_file}
  270. echo -ne "\x46\x5c\x44\x62\x46\x5d\x4c\x57\x44\x55\x44\x60\x45\x6c\x44\x6c" >> ${testmode_a_key_file}
  271. echo -ne "\x45\x44\x44\x44\x47\x47\x45\x55\x44\x60\x46\x60\x4c\x44\x44\x44" >> ${testmode_a_key_file}
  272. echo -ne "\x44\x4c\x6c\x47\x6c\x47\x60\x47\x55\x47\x57\x47\x5d\x47\x62\x47" >> ${testmode_a_key_file}
  273. echo -ne "\x5c\x47\x57\x44\x59\x45\x68\x47\x6c\x6c" >> ${testmode_a_key_file}
  274.  
  275. echo -ne "\x41\x41\x41\x41\x41\x41\x41\x41\x41" > /tmp/bsp_image/SDCardDataVersion.txt
  276. echo -ne "\x41\x41\x41\x41\x41\x41\x41\x41"     > /tmp/bsp_image/SDCardCWWVersion.txt
  277. echo -ne "\x41\x41\x41\x41\x41\x41\x41\x41"     > /tmp/bsp_image/SDCardCVJVersion.txt
  278.  
  279. #boot_mode=0
  280. #launch_mode=0
  281. #test_sub_mode=0
  282. #boot_image_flag=0
  283. #debug_flag=1
  284. #otg_switch=0
  285. #mem_check_flag=0
  286. #warp_boot=0
  287. #sub_boot_mode=0
  288. #update_selection=0
  289. #update_sub_device=0
  290. #choice_password=1
  291. #ui_update_flag=0
  292.  
  293. # 00 Signature
  294. echo -ne "\xa5\x5a\x5a\xa5" > ${bsp_image_file}
  295.  
  296. # 04 Boot Mode
  297. [ -z $boot_mode ] && boot_mode
  298. echo -ne "\x0${boot_mode}\0\0\0" >> ${bsp_image_file}
  299.  
  300. # 08 Launch Mode
  301. [ -z $launch_mode ] && launch_mode
  302. echo -ne "\x0${launch_mode}\0\0\0" >> ${bsp_image_file}
  303.  
  304. # 12 Test Sub Mode
  305. [ -z $test_sub_mode ] && test_sub_mode
  306. echo -ne "\x0${test_sub_mode}\0\0\0" >> ${bsp_image_file}
  307.  
  308. # 16 Boot Image Flag
  309. [ -z $boot_image_flag ] && boot_image_flag
  310. echo -ne "\x0${boot_image_flag}\0\0\0" >> ${bsp_image_file}
  311.  
  312. # 20 Recovery Image Flag
  313. [ -z $boot_image_flag ] && boot_image_flag
  314. echo -ne "\x0${boot_image_flag}\0\0\0" >> ${bsp_image_file}
  315.  
  316. # 24 Debug Flag
  317. [ -z $debug_flag ] && debug_flag
  318. echo -ne "\x0${debug_flag}\0\0\0" >> ${bsp_image_file}
  319.  
  320. # 28 OTG Switch
  321. [ -z $otg_switch ] && otg_switch
  322. echo -ne "\x0${otg_switch}\0\0\0" >> ${bsp_image_file}
  323.  
  324. # 32 Memory Check
  325. [ -z $mem_check_flag ] && mem_check_flag
  326. echo -ne "\x0${mem_check_flag}\0\0\0" >> ${bsp_image_file}
  327.  
  328. # 36 Warp Boot
  329. [ -z $warp_boot ] && warp_boot
  330. echo -ne "\x0${warp_boot}\0\0\0" >> ${bsp_image_file}
  331.  
  332. # 40 Sub Boot Mode
  333. [ -z $sub_boot_mode ] && sub_boot_mode
  334. echo -ne "\x0${sub_boot_mode}\0\0\0" >> ${bsp_image_file}
  335.  
  336. # 44 Update Selection
  337. [ -z $update_selection ] && update_selection
  338. echo -ne "\x0${update_selection}\0\0\0" >> ${bsp_image_file}
  339.  
  340. # 48 Update Sub Device
  341. [ -z $update_sub_device ] && update_sub_device
  342. echo -ne "\x0${update_sub_device}\0\0\0" >> ${bsp_image_file}
  343.  
  344. # Choice Password
  345. [ -z $choice_password ] && choice_password
  346.  
  347. cat <<EOF > /tmp/bsp_image/Copy_Script.sh
  348. #!/system/bin/sh
  349. ioctl -l 8 -a 4 /dev/mtd/mtd0 1074285826 2424832 65536 &>/mnt/udisk/ioctllog
  350. dd if=/mnt/udisk/newbsp.img of=/dev/block/mtdblock0 seek=2424832 count=84 bs=1 &>>/mnt/udisk/ioctllog
  351. sync
  352. echo done
  353. EOF
  354.  
  355. echo "choice_password=[${choice_password}]"
  356. if [ $choice_password == '1' ]
  357. then
  358.   cat >> /tmp/bsp_image/Copy_Script.sh << EOF
  359. cat /mnt/udisk/sdunlock>/data/local/tmp/sdunlock
  360. chmod 777 /data/local/tmp/sdunlock
  361. /data/local/tmp/sdunlock
  362. EOF
  363. fi
  364.  
  365. echo "### [/tmp/bsp_image/Copy_Script.sh] ###"
  366. [ $choice_password == '0' ] && choice_password="LKPFeD4BcVzESR2Y"
  367. [ $choice_password == '1' ] && choice_password="\x2a\x2a\x2a\x2a\x2a\x2a\x2a\x2a\x2a\x2a\x2a\x2a\x2a\x2a\x2a\x2a"
  368. #[ $choice_password == '1' ] && choice_password="\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
  369. echo -ne "${choice_password}" >> ${bsp_image_file}
  370. echo -ne "${choice_password}" > ${sd_password_file}
  371.  
  372. # 68 ui_update_flag
  373. [ -z $ui_update_flag ] && ui_update_flag
  374. echo -ne "\x0${ui_update_flag}\0\0\0" >> ${bsp_image_file}
  375.  
  376. echo -ne "\xff\xff\xff\xff\xff\xff\xff\xff" >> ${bsp_image_file}
  377.  
  378. crc32 ${bsp_image_file}
  379. bsp_image_crc=`crc32 ${bsp_image_file} | tr -d '\n'`
  380. echo -ne "\x${bsp_image_crc:6:2}\x${bsp_image_crc:4:2}\x${bsp_image_crc:2:2}\x${bsp_image_crc:0:2}" >> ${bsp_image_file}
  381. echo -e "bsp_image_crc=[${bsp_image_crc}]"
  382.  
  383. echo "### bsp_image_file [${bsp_image_file}] ###"
  384. hexdump -C ${bsp_image_file}
  385. echo "### sd_password_file [${sd_password_file}] ###"
  386. hexdump -C ${sd_password_file}
  387.  
  388. echo "### [/tmp/bsp_image/Copy_Script.sh] ###"
  389. cat /tmp/bsp_image/Copy_Script.sh
  390.  
  391. echo "Finished with [$0]"
Advertisement
Add Comment
Please, Sign In to add comment