build.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #!/bin/bash -e
  2. SCRIPTS_DIR=`cd $(dirname $0); pwd -P`
  3. if [ ! -f "$SCRIPTS_DIR/$1.config" ]; then
  4. echo "Error! No such board config file $1.config."
  5. exit -1
  6. fi
  7. source $SCRIPTS_DIR/$1.config
  8. SDK_DIR=${SCRIPTS_DIR}/..
  9. if [[ $BR_DIR == "" ]]; then
  10. BR_DIR=${SDK_DIR}/buildroot
  11. TOOLCHAIN_NAME=gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf
  12. else
  13. BR_DIR=${SDK_DIR}/$BR_DIR
  14. TOOLCHAIN_NAME=gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf
  15. fi
  16. BR_EXTERNAL_DIR=${SDK_DIR}/buildroot-external
  17. TOOLCHAIN_DIR=${BR_EXTERNAL_DIR}/toolchain
  18. TOOLCHAIN_PACKAGE_DIR=${BR_DIR}/dl/toolchain-external-linaro-arm
  19. OUTPUT_DIR=${SDK_DIR}/output/board/${BOARD_TYPE}
  20. UBOOT_OUTPUT_DIR=${OUTPUT_DIR}/u-boot
  21. LINUX_OUTPUT_DIR=${OUTPUT_DIR}/linux
  22. BR_OUTPUT_DIR=${OUTPUT_DIR}/buildroot
  23. IMAGES_DIR=${OUTPUT_DIR}/images
  24. ETC_DIR=${BR_EXTERNAL_DIR}/board/arkmicro/${BOARD_TYPE}/rootfs_overlay/etc/
  25. ubootclean() {
  26. cd ${UBOOT_OUTPUT_DIR}
  27. make distclean
  28. }
  29. linuxclean() {
  30. cd ${LINUX_OUTPUT_DIR}
  31. make distclean
  32. }
  33. brclean() {
  34. cd ${BR_OUTPUT_DIR}
  35. make clean
  36. #cd ${BR_OUTPUT_DR}
  37. #rm -rf target
  38. #find ${BR_OUTPUT_DR}/ -name ".stamp_target_installed" | xargs rm -rf
  39. }
  40. ubootbuild() {
  41. cd $SDK_DIR/u-boot
  42. make -j20 O=${UBOOT_OUTPUT_DIR} ${UBOOT_CONFIG_FILE}
  43. make -j20 O=${UBOOT_OUTPUT_DIR}
  44. make -j20 O=${UBOOT_OUTPUT_DIR} envtools
  45. if [ -f "${UBOOT_OUTPUT_DIR}/spl/u-boot-spl.bin" ]; then
  46. cp -rf ${UBOOT_OUTPUT_DIR}/spl/u-boot-spl.bin $IMAGES_DIR/ubootspl.bin
  47. fi
  48. if [ -f "${UBOOT_OUTPUT_DIR}/u-boot.img" ]; then
  49. cp -rf ${UBOOT_OUTPUT_DIR}/u-boot.img $IMAGES_DIR
  50. fi
  51. cp -rf ${UBOOT_OUTPUT_DIR}/u-boot.bin $IMAGES_DIR
  52. touch $IMAGES_DIR/update-magic
  53. echo "ada7f0c6-7c86-11e9-8f9e-2a86e4085a59" > $IMAGES_DIR/update-magic
  54. }
  55. linuxbuild() {
  56. cd $SDK_DIR/linux
  57. make -j20 O=${LINUX_OUTPUT_DIR} ${LINUX_CONFIG_FILE}
  58. make -j20 O=${LINUX_OUTPUT_DIR}
  59. cp -rf ${LINUX_OUTPUT_DIR}/arch/arm/boot/dts/${DTB_FILE_NAME} $IMAGES_DIR
  60. cp -rf ${LINUX_OUTPUT_DIR}/arch/arm/boot/zImage $IMAGES_DIR
  61. }
  62. brbuild() {
  63. echo "version=E230R_CN_KY_`date '+%y%m%d%H%M'`" > ${ETC_DIR}/version
  64. cd $BR_DIR
  65. make -j20 BR2_EXTERNAL=${BR_EXTERNAL_DIR} ${BR_CONFIG_FILE} O=${BR_OUTPUT_DIR}
  66. make -j20 O=${BR_OUTPUT_DIR}
  67. if [ -f "${BR_OUTPUT_DIR}/images/rootfs.ubi" ]; then
  68. cp -rf ${BR_OUTPUT_DIR}/images/rootfs.ubi $IMAGES_DIR
  69. fi
  70. if [ -f "${BR_OUTPUT_DIR}/images/rootfs.ext2" ]; then
  71. cp -rf ${BR_OUTPUT_DIR}/images/rootfs.ext2 $IMAGES_DIR
  72. fi
  73. }
  74. ubootconfig() {
  75. cd $SDK_DIR/u-boot
  76. make O=${UBOOT_OUTPUT_DIR} ${UBOOT_CONFIG_FILE}
  77. cd ${UBOOT_OUTPUT_DIR}
  78. make menuconfig
  79. make savedefconfig
  80. cp defconfig $SDK_DIR/u-boot/configs/${UBOOT_CONFIG_FILE}
  81. }
  82. linuxconfig() {
  83. cd $SDK_DIR/linux
  84. make O=${LINUX_OUTPUT_DIR} ${LINUX_CONFIG_FILE}
  85. cd ${LINUX_OUTPUT_DIR}
  86. make menuconfig
  87. make savedefconfig
  88. cp defconfig $SDK_DIR/linux/arch/arm/configs/${LINUX_CONFIG_FILE}
  89. }
  90. brconfig() {
  91. cd $BR_DIR
  92. make BR2_EXTERNAL=${BR_EXTERNAL_DIR} ${BR_CONFIG_FILE} O=${BR_OUTPUT_DIR}
  93. cd ${BR_OUTPUT_DIR}
  94. make menuconfig
  95. make savedefconfig
  96. }
  97. if [ "$2" == "clean" ] ; then
  98. if [ "$3" == "" ] ; then
  99. echo "clean all..."
  100. ubootclean
  101. linuxclean
  102. brclean
  103. exit $?
  104. elif [ "$3" == "uboot" ] ; then
  105. echo "clean u-boot..."
  106. ubootclean
  107. exit $?
  108. elif [ "$3" == "linux" ] ; then
  109. echo "clean linux..."
  110. linuxclean
  111. exit $?
  112. elif [ "$3" == "buildroot" ] ; then
  113. echo "clean buildroot..."
  114. brclean
  115. exit $?
  116. fi
  117. elif [ "$2" == "build" ] ; then
  118. if [ ! -d $TOOLCHAIN_DIR/$TOOLCHAIN_NAME ] ; then
  119. mkdir -p $TOOLCHAIN_DIR
  120. xz -vkd $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar.xz
  121. tar -xvf $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar -C $TOOLCHAIN_DIR
  122. rm -rf $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar
  123. fi
  124. source $SDK_DIR/env.source
  125. mkdir -p $IMAGES_DIR
  126. cp -rf $SDK_DIR/bootstrap/${BOOTSTRAP_DIR}/* $IMAGES_DIR
  127. if [ "$3" == "" ] ; then
  128. echo "build all..."
  129. ubootbuild
  130. linuxbuild
  131. brbuild
  132. exit $?
  133. elif [ "$3" == "uboot" ] ; then
  134. echo "build u-boot..."
  135. ubootbuild
  136. exit $?
  137. elif [ "$3" == "linux" ] ; then
  138. echo "build linux..."
  139. linuxbuild
  140. exit $?
  141. elif [ "$3" == "buildroot" ] ; then
  142. echo "build buildroot..."
  143. brbuild
  144. exit $?
  145. fi
  146. elif [ "$2" == "config" ] ; then
  147. if [ ! -d $TOOLCHAIN_DIR/$TOOLCHAIN_NAME ] ; then
  148. mkdir -p $TOOLCHAIN_DIR
  149. xz -vkd $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar.xz
  150. tar -xvf $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar -C $TOOLCHAIN_DIR
  151. rm -rf $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar
  152. fi
  153. source $SDK_DIR/env.source
  154. if [ "$3" == "" ] ; then
  155. echo "config all..."
  156. ubootconfig
  157. linuxconfig
  158. brconfig
  159. exit $?
  160. elif [ "$3" == "uboot" ] ; then
  161. echo "config u-boot..."
  162. ubootconfig
  163. exit $?
  164. elif [ "$3" == "linux" ] ; then
  165. echo "config linux..."
  166. linuxconfig
  167. exit $?
  168. elif [ "$3" == "buildroot" ] ; then
  169. echo "config buildroot..."
  170. brconfig
  171. exit $?
  172. fi
  173. fi