build.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. ubootclean() {
  25. cd ${UBOOT_OUTPUT_DIR}
  26. make distclean
  27. }
  28. linuxclean() {
  29. cd ${LINUX_OUTPUT_DIR}
  30. make distclean
  31. }
  32. brclean() {
  33. cd ${BR_OUTPUT_DIR}
  34. make clean
  35. #cd ${BR_OUTPUT_DR}
  36. #rm -rf target
  37. #find ${BR_OUTPUT_DR}/ -name ".stamp_target_installed" | xargs rm -rf
  38. }
  39. ubootbuild() {
  40. cd $SDK_DIR/u-boot
  41. make O=${UBOOT_OUTPUT_DIR} ${UBOOT_CONFIG_FILE}
  42. make O=${UBOOT_OUTPUT_DIR}
  43. make O=${UBOOT_OUTPUT_DIR} envtools
  44. if [ -f "${UBOOT_OUTPUT_DIR}/spl/u-boot-spl.bin" ]; then
  45. cp -rf ${UBOOT_OUTPUT_DIR}/spl/u-boot-spl.bin $IMAGES_DIR/ubootspl.bin
  46. fi
  47. if [ -f "${UBOOT_OUTPUT_DIR}/u-boot.img" ]; then
  48. cp -rf ${UBOOT_OUTPUT_DIR}/u-boot.img $IMAGES_DIR
  49. fi
  50. cp -rf ${UBOOT_OUTPUT_DIR}/u-boot.bin $IMAGES_DIR
  51. touch $IMAGES_DIR/update-magic
  52. echo "ada7f0c6-7c86-11e9-8f9e-2a86e4085a59" > $IMAGES_DIR/update-magic
  53. }
  54. linuxbuild() {
  55. cd $SDK_DIR/linux
  56. make O=${LINUX_OUTPUT_DIR} ${LINUX_CONFIG_FILE}
  57. make O=${LINUX_OUTPUT_DIR}
  58. cp -rf ${LINUX_OUTPUT_DIR}/arch/arm/boot/dts/${DTB_FILE_NAME} $IMAGES_DIR
  59. cp -rf ${LINUX_OUTPUT_DIR}/arch/arm/boot/zImage $IMAGES_DIR
  60. }
  61. brbuild() {
  62. cd $BR_DIR
  63. make BR2_EXTERNAL=${BR_EXTERNAL_DIR} ${BR_CONFIG_FILE} O=${BR_OUTPUT_DIR}
  64. make O=${BR_OUTPUT_DIR}
  65. if [ -f "${BR_OUTPUT_DIR}/images/rootfs.ubi" ]; then
  66. cp -rf ${BR_OUTPUT_DIR}/images/rootfs.ubi $IMAGES_DIR
  67. fi
  68. if [ -f "${BR_OUTPUT_DIR}/images/rootfs.ext2" ]; then
  69. cp -rf ${BR_OUTPUT_DIR}/images/rootfs.ext2 $IMAGES_DIR
  70. fi
  71. }
  72. ubootconfig() {
  73. cd $SDK_DIR/u-boot
  74. make O=${UBOOT_OUTPUT_DIR} ${UBOOT_CONFIG_FILE}
  75. cd ${UBOOT_OUTPUT_DIR}
  76. make menuconfig
  77. make savedefconfig
  78. cp defconfig $SDK_DIR/u-boot/configs/${UBOOT_CONFIG_FILE}
  79. }
  80. linuxconfig() {
  81. cd $SDK_DIR/linux
  82. make O=${LINUX_OUTPUT_DIR} ${LINUX_CONFIG_FILE}
  83. cd ${LINUX_OUTPUT_DIR}
  84. make menuconfig
  85. make savedefconfig
  86. cp defconfig $SDK_DIR/linux/arch/arm/configs/${LINUX_CONFIG_FILE}
  87. }
  88. brconfig() {
  89. cd $BR_DIR
  90. make BR2_EXTERNAL=${BR_EXTERNAL_DIR} ${BR_CONFIG_FILE} O=${BR_OUTPUT_DIR}
  91. cd ${BR_OUTPUT_DIR}
  92. make menuconfig
  93. make savedefconfig
  94. }
  95. if [ "$2" == "clean" ] ; then
  96. if [ "$3" == "" ] ; then
  97. echo "clean all..."
  98. ubootclean
  99. linuxclean
  100. brclean
  101. exit $?
  102. elif [ "$3" == "uboot" ] ; then
  103. echo "clean u-boot..."
  104. ubootclean
  105. exit $?
  106. elif [ "$3" == "linux" ] ; then
  107. echo "clean linux..."
  108. linuxclean
  109. exit $?
  110. elif [ "$3" == "buildroot" ] ; then
  111. echo "clean buildroot..."
  112. brclean
  113. exit $?
  114. fi
  115. elif [ "$2" == "build" ] ; then
  116. if [ ! -d $TOOLCHAIN_DIR/$TOOLCHAIN_NAME ] ; then
  117. mkdir -p $TOOLCHAIN_DIR
  118. xz -vkd $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar.xz
  119. tar -xvf $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar -C $TOOLCHAIN_DIR
  120. rm -rf $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar
  121. fi
  122. source $SDK_DIR/env.source
  123. mkdir -p $IMAGES_DIR
  124. cp -rf $SDK_DIR/bootstrap/${BOOTSTRAP_DIR}/* $IMAGES_DIR
  125. if [ "$3" == "" ] ; then
  126. echo "build all..."
  127. ubootbuild
  128. linuxbuild
  129. brbuild
  130. exit $?
  131. elif [ "$3" == "uboot" ] ; then
  132. echo "build u-boot..."
  133. ubootbuild
  134. exit $?
  135. elif [ "$3" == "linux" ] ; then
  136. echo "build linux..."
  137. linuxbuild
  138. exit $?
  139. elif [ "$3" == "buildroot" ] ; then
  140. echo "build buildroot..."
  141. brbuild
  142. exit $?
  143. fi
  144. elif [ "$2" == "config" ] ; then
  145. if [ ! -d $TOOLCHAIN_DIR/$TOOLCHAIN_NAME ] ; then
  146. mkdir -p $TOOLCHAIN_DIR
  147. xz -vkd $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar.xz
  148. tar -xvf $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar -C $TOOLCHAIN_DIR
  149. rm -rf $TOOLCHAIN_PACKAGE_DIR/$TOOLCHAIN_NAME.tar
  150. fi
  151. source $SDK_DIR/env.source
  152. if [ "$3" == "uboot" ] ; then
  153. echo "config u-boot..."
  154. ubootconfig
  155. exit $?
  156. elif [ "$3" == "linux" ] ; then
  157. echo "config linux..."
  158. linuxconfig
  159. exit $?
  160. elif [ "$3" == "buildroot" ] ; then
  161. echo "config buildroot..."
  162. brconfig
  163. exit $?
  164. fi
  165. fi