platform.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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_get_bootdev() {
  53. local rootdisk="$(cat /sys/firmware/devicetree/base/chosen/rootdisk)"
  54. local handle bootdev
  55. for handle in /sys/class/block/*/of_node/phandle /sys/class/block/*/device/of_node/phandle; do
  56. [ ! -e "$handle" ] && continue
  57. if [ "$rootdisk" = "$(cat $handle)" ]; then
  58. bootdev="${handle%/of_node/phandle}"
  59. bootdev="${bootdev%/device}"
  60. bootdev="${bootdev#/sys/class/block/}"
  61. echo "$bootdev"
  62. break
  63. fi
  64. done
  65. }
  66. platform_do_upgrade() {
  67. local board=$(board_name)
  68. case "$board" in
  69. acer,predator-w6|\
  70. smartrg,sdg-8612|\
  71. smartrg,sdg-8614|\
  72. smartrg,sdg-8622|\
  73. smartrg,sdg-8632)
  74. CI_KERNPART="kernel"
  75. CI_ROOTPART="rootfs"
  76. emmc_do_upgrade "$1"
  77. ;;
  78. asus,rt-ax59u|\
  79. asus,tuf-ax4200|\
  80. asus,tuf-ax6000)
  81. CI_UBIPART="UBI_DEV"
  82. CI_KERNPART="linux"
  83. nand_do_upgrade "$1"
  84. ;;
  85. bananapi,bpi-r3|\
  86. bananapi,bpi-r3-mini|\
  87. bananapi,bpi-r4)
  88. [ -e /dev/fit0 ] && fitblk /dev/fit0
  89. [ -e /dev/fitrw ] && fitblk /dev/fitrw
  90. bootdev="$(platform_get_bootdev)"
  91. case "$bootdev" in
  92. mmcblk*)
  93. EMMC_KERN_DEV="/dev/$bootdev"
  94. emmc_do_upgrade "$1"
  95. ;;
  96. mtdblock*)
  97. PART_NAME="/dev/mtd${bootdev:8}"
  98. default_do_upgrade "$1"
  99. ;;
  100. ubiblock*)
  101. CI_KERNPART="fit"
  102. nand_do_upgrade "$1"
  103. ;;
  104. esac
  105. ;;
  106. cmcc,rax3000m)
  107. case "$(cmdline_get_var root)" in
  108. /dev/mmc*)
  109. CI_KERNPART="production"
  110. emmc_do_upgrade "$1"
  111. ;;
  112. *)
  113. CI_KERNPART="fit"
  114. nand_do_upgrade "$1"
  115. ;;
  116. esac
  117. ;;
  118. cudy,wr3000-v1|\
  119. yuncore,ax835)
  120. default_do_upgrade "$1"
  121. ;;
  122. glinet,gl-mt2500|\
  123. glinet,gl-mt6000)
  124. CI_KERNPART="kernel"
  125. CI_ROOTPART="rootfs"
  126. emmc_do_upgrade "$1"
  127. ;;
  128. h3c,magic-nx30-pro|\
  129. jcg,q30-pro|\
  130. mediatek,mt7981-rfb|\
  131. qihoo,360t7|\
  132. tplink,tl-xdr4288|\
  133. tplink,tl-xdr6086|\
  134. tplink,tl-xdr6088|\
  135. xiaomi,mi-router-ax3000t-ubootmod|\
  136. xiaomi,mi-router-wr30u-ubootmod|\
  137. xiaomi,redmi-router-ax6000-ubootmod)
  138. CI_KERNPART="fit"
  139. nand_do_upgrade "$1"
  140. ;;
  141. jdcloud,re-cp-03)
  142. CI_KERNPART="production"
  143. emmc_do_upgrade "$1"
  144. ;;
  145. mercusys,mr90x-v1)
  146. CI_UBIPART="ubi0"
  147. nand_do_upgrade "$1"
  148. ;;
  149. ubnt,unifi-6-plus)
  150. CI_KERNPART="kernel0"
  151. EMMC_ROOT_DEV="$(cmdline_get_var root)"
  152. emmc_do_upgrade "$1"
  153. ;;
  154. xiaomi,mi-router-ax3000t|\
  155. xiaomi,mi-router-wr30u-stock|\
  156. xiaomi,redmi-router-ax6000-stock)
  157. CI_KERN_UBIPART=ubi_kernel
  158. CI_ROOT_UBIPART=ubi
  159. nand_do_upgrade "$1"
  160. ;;
  161. zyxel,ex5601-t0-ubootmod)
  162. CI_KERNPART="fit"
  163. CI_ROOTPART="ubi_rootfs"
  164. nand_do_upgrade "$1"
  165. ;;
  166. *)
  167. nand_do_upgrade "$1"
  168. ;;
  169. esac
  170. }
  171. PART_NAME=firmware
  172. platform_check_image() {
  173. local board=$(board_name)
  174. local magic="$(get_magic_long "$1")"
  175. [ "$#" -gt 1 ] && return 1
  176. case "$board" in
  177. bananapi,bpi-r3|\
  178. bananapi,bpi-r4|\
  179. cmcc,rax3000m)
  180. [ "$magic" != "d00dfeed" ] && {
  181. echo "Invalid image type."
  182. return 1
  183. }
  184. return 0
  185. ;;
  186. *)
  187. nand_do_platform_check "$board" "$1"
  188. return $?
  189. ;;
  190. esac
  191. return 0
  192. }
  193. platform_copy_config() {
  194. case "$(board_name)" in
  195. cmcc,rax3000m)
  196. case "$(cmdline_get_var root)" in
  197. /dev/mmc*)
  198. emmc_copy_config
  199. ;;
  200. esac
  201. ;;
  202. bananapi,bpi-r3|\
  203. bananapi,bpi-r3-mini|\
  204. bananapi,bpi-r4)
  205. case "$(platform_get_bootdev)" in
  206. mmcblk*)
  207. emmc_copy_config
  208. ;;
  209. esac
  210. ;;
  211. acer,predator-w6|\
  212. glinet,gl-mt2500|\
  213. glinet,gl-mt6000|\
  214. jdcloud,re-cp-03|\
  215. ubnt,unifi-6-plus)
  216. emmc_copy_config
  217. ;;
  218. esac
  219. }
  220. platform_pre_upgrade() {
  221. local board=$(board_name)
  222. case "$board" in
  223. asus,rt-ax59u|\
  224. asus,tuf-ax4200|\
  225. asus,tuf-ax6000)
  226. asus_initial_setup
  227. ;;
  228. xiaomi,mi-router-ax3000t|\
  229. xiaomi,mi-router-wr30u-stock|\
  230. xiaomi,redmi-router-ax6000-stock)
  231. xiaomi_initial_setup
  232. ;;
  233. esac
  234. }