build-gekko_new.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #!/bin/bash
  2. # This is a script for build avalon controller image
  3. #
  4. # Copyright 2014-2015 Mikeqin <Fengling.Qin@gmail.com>
  5. # Copyright 2012-2015 Xiangfu <xiangfu@openmobilefree.com>
  6. #
  7. # OPENWRT_DIR is ${ROOT_DIR}/openwrt, build the image in it
  8. # Controller's image should include the following configurations:
  9. # ${AVA_MACHINE}_owrepo : OpenWrt repo, format: repo_url@repo_ver
  10. # feeds.${AVA_MACHINE}.conf : OpenWrt feeds, file locate in cgminer-openwrt-packages
  11. # ${AVA_TARGET_BOARD}_brdcfg : OpenWrt target and config, file locate in cgminer-openwrt-packages
  12. #
  13. # Learn bash: http://explainshell.com/
  14. set -e
  15. SCRIPT_VERSION=30092017
  16. # Support machine: avalon6, avalon4
  17. [ -z "${AVA_MACHINE}" ] && AVA_MACHINE=gekko
  18. # Support target board: rpi2-modelb, rpi1-modelb, tl-wr703n-v1, tl-mr3020-v1
  19. [ -z "${AVA_TARGET_BOARD}" ] && AVA_TARGET_BOARD=tl-mr3020-v1
  20. # OpenWrt repo
  21. gekko_owrepo="http://gogserver.dnsalias.com:3000/wareck/openwrt_chaos_calmer.git@master"
  22. if [ "${AVA_TARGET_BOARD}" == "rpi3" ]; then
  23. gekko_owrepo="https://github.com/openwrt/openwrt.git@e046500"
  24. fi
  25. # OpenWrt feeds
  26. FEEDS_CONF=feeds.${AVA_MACHINE}.conf
  27. # Board config: target(get it in the OpenWrt bin), config
  28. rpi3_modelb_brdcfg=("brcm2708" "config.${AVA_MACHINE}.rpi3")
  29. rpi2_modelb_brdcfg=("brcm2708" "config.${AVA_MACHINE}.rpi2")
  30. rpi1_modelb_brdcfg=("brcm2708" "config.${AVA_MACHINE}.raspberry-pi")
  31. tl_wr703n_v1_brdcfg=("ar71xx" "config.${AVA_MACHINE}.703n")
  32. tl_mr3020_v1_brdcfg=("ar71xx" "config.${AVA_MACHINE}.mr3020")
  33. wrt1200ac_brdcfg=("mvebu" "config.${AVA_MACHINE}.wrt1200ac")
  34. zedboard_brdcfg=("zynq" "config.${AVA_MACHINE}.zedboard")
  35. orangepi_2_brdcfg=("sunxi" "config.${AVA_MACHINE}.orangepi2")
  36. which wget > /dev/null && DL_PROG=wget && DL_PARA="-nv -O"
  37. which curl > /dev/null && DL_PROG=curl && DL_PARA="-L -o"
  38. # According to http://wiki.openwrt.org/doc/howto/build
  39. unset SED
  40. unset GREP_OPTIONS
  41. [ "`id -u`" == "0" ] && echo "[ERROR]: Please use non-root user" && exit 1
  42. # Adjust CORE_NUM by yourself
  43. [ -z "${CORE_NUM}" ] && CORE_NUM="$(expr $(nproc) + 1)"
  44. DATE=`date +%Y%m%d`
  45. SCRIPT_FILE="$(readlink -f $0)"
  46. SCRIPT_DIR=`dirname ${SCRIPT_FILE}`
  47. ROOT_DIR=${SCRIPT_DIR}/avalon
  48. OPENWRT_DIR=${ROOT_DIR}/openwrt
  49. prepare_version() {
  50. cd ${OPENWRT_DIR}
  51. GIT_VERSION=`git ls-remote https://github.com/wareck/cgminer-gekko master | cut -f1 | cut -c1-7`
  52. LUCI_GIT_VERSION=`git --git-dir=./feeds/luci/.git rev-parse HEAD | cut -c1-7`
  53. OW_GIT_VERSION=`git --git-dir=./feeds/cgminer/.git rev-parse HEAD | cut -c1-7`
  54. cat > ./files/etc/avalon_version << EOL
  55. Firmware - $DATE
  56. luci: $LUCI_GIT_VERSION
  57. cgminer: $GIT_VERSION
  58. cgminer-packages: $OW_GIT_VERSION
  59. EOL
  60. }
  61. prepare_config() {
  62. cd ${OPENWRT_DIR}
  63. eval OPENWRT_CONFIG=\${"`echo ${AVA_TARGET_BOARD//-/_}`"_brdcfg[1]} && cp ./feeds/cgminer/cgminer/data/${OPENWRT_CONFIG} .config
  64. }
  65. prepare_feeds() {
  66. cd ${OPENWRT_DIR}
  67. $DL_PROG https://raw.github.com/wareck/gekko-openwrt-packages/master/cgminer/data/${FEEDS_CONF} $DL_PARA feeds.conf && \
  68. ./scripts/feeds update -a && \
  69. ./scripts/feeds install -a
  70. if [ ! -e files ]; then
  71. ln -s feeds/cgminer/cgminer/root-files files
  72. fi
  73. }
  74. prepare_source() {
  75. echo "Gen firmware for ${AVA_TARGET_BOARD}:${AVA_MACHINE}"
  76. echo "TARGET BOARD :${AVA_TARGET_BOARD}"
  77. echo "TARGET MACHINE :${AVA_MACHINE}"
  78. cd ${SCRIPT_DIR}
  79. [ ! -d avalon ] && mkdir -p avalon/bin
  80. cd avalon
  81. if [ ! -d openwrt ]; then
  82. eval OPENWRT_URL=\${${AVA_MACHINE}_owrepo}
  83. PROTOCOL="`echo ${OPENWRT_URL} | cut -d : -f 1`"
  84. case "${PROTOCOL}" in
  85. git)
  86. GITBRANCH="`echo ${OPENWRT_URL} | cut -d @ -f 2`"
  87. GITREPO="`echo ${OPENWRT_URL} | cut -d @ -f 1`"
  88. git clone -b ${GITBRANCH} ${GITREPO} openwrt
  89. ;;
  90. svn)
  91. SVNVER="`echo ${OPENWRT_URL} | cut -d @ -f 2`"
  92. SVNREPO="`echo ${OPENWRT_URL} | cut -d @ -f 1`"
  93. svn co ${SVNREPO}@${SVNVER} openwrt
  94. ;;
  95. http)
  96. GITBRANCH="`echo ${OPENWRT_URL} | cut -d @ -f 2`"
  97. GITREPO="`echo ${OPENWRT_URL} | cut -d @ -f 1`"
  98. git clone ${GITREPO} openwrt
  99. ;;
  100. *)
  101. echo "Protocol not supported"; exit 1;
  102. ;;
  103. esac
  104. fi
  105. sed -i -e "s/git:\/\/github.com/https:\/\/github.com/g" openwrt/package/network/services/odhcpd/Makefile
  106. [ ! -e dl ] && mkdir dl
  107. cd ${OPENWRT_DIR}
  108. ln -sf ../dl
  109. }
  110. build_image() {
  111. cd ${OPENWRT_DIR}
  112. yes "" | make oldconfig > /dev/null
  113. # clean before build
  114. make -j${CORE_NUM} clean world
  115. #make -j${CORE_NUM} world V=s
  116. }
  117. build_cgminer() {
  118. cd ${OPENWRT_DIR}
  119. rm -f ./dl/cgminer-*.tar.bz2
  120. yes "" | make oldconfig > /dev/null
  121. make -j${CORE_NUM} package/cgminer/{clean,compile}
  122. if [ "$?" == "0" ]; then
  123. eval AVA_TARGET_PLATFORM=\${"`echo ${AVA_TARGET_BOARD//-/_}`"_brdcfg[0]}
  124. cd ..
  125. mkdir -p ./bin/${AVA_TARGET_BOARD}
  126. cp ./openwrt/bin/${AVA_TARGET_PLATFORM}/packages/cgminer/cgminer*.ipk ./bin/${AVA_TARGET_BOARD}
  127. fi
  128. }
  129. do_release() {
  130. cd ${ROOT_DIR}
  131. eval AVA_TARGET_PLATFORM=\${"`echo ${AVA_TARGET_BOARD//-/_}`"_brdcfg[0]}
  132. mkdir -p ./bin/${DATE}/${AVA_TARGET_BOARD}/
  133. cp -a ./openwrt/bin/${AVA_TARGET_PLATFORM}/* ./bin/${DATE}/${AVA_TARGET_BOARD}/
  134. }
  135. cleanup() {
  136. cd ${ROOT_DIR}
  137. rm -rf openwrt/ > /dev/null
  138. }
  139. show_help() {
  140. echo "\
  141. Usage: $0 [--version] [--help] [--build] [--cgminer] [--cleanup]
  142. --version
  143. --help Display help message
  144. --build Get .config file and build firmware
  145. --cgminer Re-compile only cgminer openwrt package
  146. --test Dowload and prebuild files
  147. --cleanup Remove all files
  148. AVA_TARGET_BOARD Environment variable, available target:
  149. tl-wr703n-v1, pi-modelb-v1
  150. pi-modelb-v2, tl-mr3020-v1
  151. use pi-modelb-v2 if unset
  152. AVA_MACHINE Environment variable, available machine:
  153. avalon6, avalon4, gekko, rockminer
  154. use avalon6 if unset
  155. Written by: Xiangfu <xiangfu@openmobilefree.net>
  156. Fengling <Fengling.Qin@gmail.com>
  157. wareck <wareck@gmail.com>
  158. Version: ${SCRIPT_VERSION}"
  159. }
  160. if [ "$#" == "0" ]; then
  161. $0 --help
  162. exit 0
  163. fi
  164. for i in "$@"
  165. do
  166. case $i in
  167. --version|--help)
  168. show_help
  169. exit
  170. ;;
  171. --build)
  172. prepare_source && prepare_feeds && prepare_config && prepare_version && build_image && do_release
  173. ;;
  174. --cgminer)
  175. prepare_source && prepare_feeds && prepare_config && prepare_version && build_cgminer
  176. ;;
  177. --test)
  178. prepare_source && prepare_feeds && prepare_config && prepare_version
  179. ;;
  180. --cleanup)
  181. cleanup
  182. ;;
  183. *)
  184. show_help
  185. exit
  186. ;;
  187. esac
  188. done