platform.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. REQUIRE_IMAGE_METADATA=1
  2. RAMFS_COPY_BIN='fitblk'
  3. asus_initial_setup()
  4. {
  5. # initialize UBI if it's running on initramfs
  6. [ "$(rootfs_type)" = "tmpfs" ] || return 0
  7. ubirmvol /dev/ubi0 -N rootfs
  8. ubirmvol /dev/ubi0 -N rootfs_data
  9. ubirmvol /dev/ubi0 -N jffs2
  10. ubimkvol /dev/ubi0 -N jffs2 -s 0x3e000
  11. }
  12. xiaomi_initial_setup()
  13. {
  14. # initialize UBI and setup uboot-env if it's running on initramfs
  15. [ "$(rootfs_type)" = "tmpfs" ] || return 0
  16. local mtdnum="$( find_mtd_index ubi )"
  17. if [ ! "$mtdnum" ]; then
  18. echo "unable to find mtd partition ubi"
  19. return 1
  20. fi
  21. local kern_mtdnum="$( find_mtd_index ubi_kernel )"
  22. if [ ! "$kern_mtdnum" ]; then
  23. echo "unable to find mtd partition ubi_kernel"
  24. return 1
  25. fi
  26. ubidetach -m "$mtdnum"
  27. ubiformat /dev/mtd$mtdnum -y
  28. ubidetach -m "$kern_mtdnum"
  29. ubiformat /dev/mtd$kern_mtdnum -y
  30. if ! fw_printenv -n flag_try_sys2_failed &>/dev/null; then
  31. echo "failed to access u-boot-env. skip env setup."
  32. return 0
  33. fi
  34. fw_setenv boot_wait on
  35. fw_setenv uart_en 1
  36. fw_setenv flag_boot_rootfs 0
  37. fw_setenv flag_last_success 1
  38. fw_setenv flag_boot_success 1
  39. fw_setenv flag_try_sys1_failed 8
  40. fw_setenv flag_try_sys2_failed 8
  41. local board=$(board_name)
  42. case "$board" in
  43. xiaomi,mi-router-ax3000t|\
  44. xiaomi,mi-router-wr30u-stock)
  45. fw_setenv mtdparts "nmbm0:1024k(bl2),256k(Nvram),256k(Bdata),2048k(factory),2048k(fip),256k(crash),256k(crash_log),34816k(ubi),34816k(ubi1),32768k(overlay),12288k(data),256k(KF)"
  46. ;;
  47. xiaomi,redmi-router-ax6000-stock)
  48. fw_setenv mtdparts "nmbm0:1024k(bl2),256k(Nvram),256k(Bdata),2048k(factory),2048k(fip),256k(crash),256k(crash_log),30720k(ubi),30720k(ubi1),51200k(overlay)"
  49. ;;
  50. esac
  51. }
  52. platform_do_upgrade() {
  53. local board=$(board_name)
  54. case "$board" in
  55. acer,predator-w6|\
  56. smartrg,sdg-8612|\
  57. smartrg,sdg-8614|\
  58. smartrg,sdg-8622|\
  59. smartrg,sdg-8632)
  60. CI_KERNPART="kernel"
  61. CI_ROOTPART="rootfs"
  62. emmc_do_upgrade "$1"
  63. ;;
  64. asus,rt-ax59u|\
  65. asus,tuf-ax4200|\
  66. asus,tuf-ax6000)
  67. CI_UBIPART="UBI_DEV"
  68. CI_KERNPART="linux"
  69. nand_do_upgrade "$1"
  70. ;;
  71. bananapi,bpi-r3|\
  72. bananapi,bpi-r3-mini|\
  73. bananapi,bpi-r4|\
  74. bananapi,bpi-r4-poe|\
  75. mediatek,mt7988a-rfb|\
  76. jdcloud,re-cp-03|\
  77. tplink,tl-xdr4288|\
  78. tplink,tl-xdr6086|\
  79. tplink,tl-xdr6088|\
  80. xiaomi,redmi-router-ax6000-ubootmod)
  81. [ -e /dev/fit0 ] && fitblk /dev/fit0
  82. [ -e /dev/fitrw ] && fitblk /dev/fitrw
  83. bootdev="$(fitblk_get_bootdev)"
  84. case "$bootdev" in
  85. mmcblk*)
  86. EMMC_KERN_DEV="/dev/$bootdev"
  87. emmc_do_upgrade "$1"
  88. ;;
  89. mtdblock*)
  90. PART_NAME="/dev/mtd${bootdev:8}"
  91. default_do_upgrade "$1"
  92. ;;
  93. ubiblock*)
  94. CI_KERNPART="fit"
  95. nand_do_upgrade "$1"
  96. ;;
  97. esac
  98. ;;
  99. cmcc,rax3000m)
  100. case "$(cmdline_get_var root)" in
  101. /dev/mmc*)
  102. CI_KERNPART="production"
  103. emmc_do_upgrade "$1"
  104. ;;
  105. *)
  106. CI_KERNPART="fit"
  107. nand_do_upgrade "$1"
  108. ;;
  109. esac
  110. ;;
  111. cudy,re3000-v1|\
  112. cudy,wr3000-v1|\
  113. yuncore,ax835)
  114. default_do_upgrade "$1"
  115. ;;
  116. glinet,gl-mt2500|\
  117. glinet,gl-mt6000|\
  118. glinet,gl-x3000|\
  119. glinet,gl-xe3000)
  120. CI_KERNPART="kernel"
  121. CI_ROOTPART="rootfs"
  122. emmc_do_upgrade "$1"
  123. ;;
  124. h3c,magic-nx30-pro|\
  125. jcg,q30-pro|\
  126. mediatek,mt7981-rfb|\
  127. netcore,n60|\
  128. qihoo,360t7|\
  129. xiaomi,mi-router-ax3000t-ubootmod|\
  130. xiaomi,mi-router-wr30u-ubootmod)
  131. CI_KERNPART="fit"
  132. nand_do_upgrade "$1"
  133. ;;
  134. mercusys,mr90x-v1)
  135. CI_UBIPART="ubi0"
  136. nand_do_upgrade "$1"
  137. ;;
  138. ubnt,unifi-6-plus)
  139. CI_KERNPART="kernel0"
  140. EMMC_ROOT_DEV="$(cmdline_get_var root)"
  141. emmc_do_upgrade "$1"
  142. ;;
  143. xiaomi,mi-router-ax3000t|\
  144. xiaomi,mi-router-wr30u-stock|\
  145. xiaomi,redmi-router-ax6000-stock)
  146. CI_KERN_UBIPART=ubi_kernel
  147. CI_ROOT_UBIPART=ubi
  148. nand_do_upgrade "$1"
  149. ;;
  150. zyxel,ex5601-t0-ubootmod)
  151. CI_KERNPART="fit"
  152. CI_ROOTPART="ubi_rootfs"
  153. nand_do_upgrade "$1"
  154. ;;
  155. unielec,u7981-01*)
  156. local rootdev="$(cmdline_get_var root)"
  157. rootdev="${rootdev##*/}"
  158. rootdev="${rootdev%p[0-9]*}"
  159. case "$rootdev" in
  160. mmc*)
  161. CI_ROOTDEV="$rootdev"
  162. CI_KERNPART="kernel"
  163. CI_ROOTPART="rootfs"
  164. emmc_do_upgrade "$1"
  165. ;;
  166. *)
  167. CI_KERNPART="fit"
  168. nand_do_upgrade "$1"
  169. ;;
  170. esac
  171. ;;
  172. *)
  173. nand_do_upgrade "$1"
  174. ;;
  175. esac
  176. }
  177. PART_NAME=firmware
  178. platform_check_image() {
  179. local board=$(board_name)
  180. local magic="$(get_magic_long "$1")"
  181. [ "$#" -gt 1 ] && return 1
  182. case "$board" in
  183. bananapi,bpi-r3|\
  184. bananapi,bpi-r4|\
  185. bananapi,bpi-r4-poe|\
  186. cmcc,rax3000m)
  187. [ "$magic" != "d00dfeed" ] && {
  188. echo "Invalid image type."
  189. return 1
  190. }
  191. return 0
  192. ;;
  193. *)
  194. nand_do_platform_check "$board" "$1"
  195. return $?
  196. ;;
  197. esac
  198. return 0
  199. }
  200. platform_copy_config() {
  201. case "$(board_name)" in
  202. cmcc,rax3000m)
  203. case "$(cmdline_get_var root)" in
  204. /dev/mmc*)
  205. emmc_copy_config
  206. ;;
  207. esac
  208. ;;
  209. bananapi,bpi-r3|\
  210. bananapi,bpi-r3-mini|\
  211. bananapi,bpi-r4|\
  212. bananapi,bpi-r4-poe)
  213. case "$(fitblk_get_bootdev)" in
  214. mmcblk*)
  215. emmc_copy_config
  216. ;;
  217. esac
  218. ;;
  219. acer,predator-w6|\
  220. glinet,gl-mt2500|\
  221. glinet,gl-mt6000|\
  222. glinet,gl-x3000|\
  223. glinet,gl-xe3000|\
  224. jdcloud,re-cp-03|\
  225. ubnt,unifi-6-plus)
  226. emmc_copy_config
  227. ;;
  228. esac
  229. }
  230. platform_pre_upgrade() {
  231. local board=$(board_name)
  232. case "$board" in
  233. asus,rt-ax59u|\
  234. asus,tuf-ax4200|\
  235. asus,tuf-ax6000)
  236. asus_initial_setup
  237. ;;
  238. xiaomi,mi-router-ax3000t|\
  239. xiaomi,mi-router-wr30u-stock|\
  240. xiaomi,redmi-router-ax6000-stock)
  241. xiaomi_initial_setup
  242. ;;
  243. esac
  244. }