build 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #!/usr/bin/env bash
  2. set -eu
  3. . common
  4. set -- ${cli_build:-} "$@"
  5. mkdir -p "${out_dir}"
  6. br2_cli_file="${out_dir}/br2_cli"
  7. rm -f "$br2_cli_file"
  8. touch "$br2_cli_file"
  9. kernel_config_fragment_cli_file="${out_dir}/kernel_config_fragment_cli"
  10. rm -f "$kernel_config_fragment_cli_file"
  11. touch "$kernel_config_fragment_cli_file"
  12. configure=true
  13. config_fragments="${root_dir}/br2/default"
  14. extra_make_args=
  15. j="$(nproc)"
  16. linux_reconfigure=false
  17. linux_kernel_custom_config_file=
  18. kernel_config_fragments=
  19. post_script_args=
  20. qemu_sdl='--enable-sdl --with-sdlabi=2.0'
  21. suffix=
  22. v=0
  23. while getopts 'a:B:b:C:c:fGgj:hIiK:klp:qSs:v' OPT; do
  24. case "$OPT" in
  25. a)
  26. arch="$OPTARG"
  27. ;;
  28. B)
  29. echo "$OPTARG" >> "$br2_cli_file"
  30. ;;
  31. b)
  32. config_fragments="${config_fragments} $(common_abspath "${OPTARG}")"
  33. ;;
  34. C)
  35. echo "$OPTARG" >> "$kernel_config_fragment_cli_file"
  36. ;;
  37. c)
  38. kernel_config_fragments="${kernel_config_fragments} $(common_abspath "${OPTARG}")"
  39. ;;
  40. f)
  41. configure=false
  42. ;;
  43. g)
  44. extra_make_args="${extra_make_args} gem5-reconfigure \\
  45. "
  46. gem5=true
  47. ;;
  48. h)
  49. cat build-usage.adoc 1>&2
  50. exit
  51. ;;
  52. I)
  53. echo "
  54. BR2_TARGET_ROOTFS_CPIO=n
  55. BR2_TARGET_ROOTFS_EXT2=n
  56. BR2_TARGET_ROOTFS_INITRAMFS=y
  57. " >> "$br2_cli_file"
  58. ;;
  59. i)
  60. echo "
  61. BR2_TARGET_ROOTFS_CPIO=y
  62. BR2_TARGET_ROOTFS_EXT2=n
  63. BR2_TARGET_ROOTFS_INITRAMFS=n
  64. " >> "$br2_cli_file"
  65. ;;
  66. j)
  67. j="$OPTARG"
  68. ;;
  69. K)
  70. linux_kernel_custom_config_file="$(common_abspath "${OPTARG}")"
  71. ;;
  72. k)
  73. extra_make_args="${extra_make_args} kernel_module-reconfigure \\
  74. "
  75. ;;
  76. l)
  77. linux_reconfigure=true
  78. extra_make_args="${extra_make_args} linux-reconfigure \\
  79. "
  80. ;;
  81. p)
  82. post_script_args="$OPTARG"
  83. ;;
  84. q)
  85. extra_make_args="${extra_make_args} host-qemu-reconfigure \\
  86. "
  87. ;;
  88. S)
  89. qemu_sdl=
  90. ;;
  91. s)
  92. suffix="$OPTARG"
  93. ;;
  94. v)
  95. v=1
  96. ;;
  97. ?)
  98. exit 2
  99. ;;
  100. esac
  101. done
  102. shift $(($OPTIND - 1))
  103. extra_make_args="${extra_make_args} $@"
  104. set_common_vars "$arch" "$gem5" "$suffix"
  105. config_file="${buildroot_out_dir}/.config"
  106. case "$arch" in
  107. x86_64)
  108. defconfig=qemu_x86_64_defconfig
  109. ;;
  110. arm)
  111. defconfig=qemu_arm_vexpress_defconfig
  112. linux_kernel_custom_config_file="${root_dir}/linux/arch/arm/configs/gem5_defconfig"
  113. ;;
  114. aarch64)
  115. defconfig=qemu_aarch64_virt_defconfig
  116. linux_kernel_custom_config_file="${root_dir}/linux/arch/arm64/configs/gem5_defconfig"
  117. ;;
  118. mips64)
  119. defconfig=qemu_mips64r6_malta_defconfig
  120. ;;
  121. esac
  122. config_fragments="${config_fragments} ${root_dir}/br2/qemu ${br2_cli_file}"
  123. # Configure.
  124. if "$configure"; then
  125. cd "${buildroot_dir}"
  126. for p in $(find "${root_dir}/buildroot_patches/" -maxdepth 1 -name '*.patch' -print); do
  127. patch -N -r - -p 1 < "$p" || :
  128. done
  129. make O="$buildroot_out_dir" BR2_EXTERNAL="../kernel_module:../gem5:../parsec-benchmark:../sample_package" "$defconfig"
  130. # TODO Can't get rid of these for now.
  131. # http://stackoverflow.com/questions/44078245/is-it-possible-to-use-config-fragments-with-buildroots-config
  132. for config_fragment in $config_fragments; do
  133. cat "$config_fragment" >> "$config_file"
  134. done
  135. printf "
  136. BR2_JLEVEL=${j}
  137. BR2_DL_DIR=\"${common_dir}/dl\"
  138. BR2_ROOTFS_POST_SCRIPT_ARGS=\"${post_script_args}\"
  139. " >> "$config_file"
  140. if "$gem5"; then
  141. printf "BR2_PACKAGE_GEM5=y\n" >> "${config_file}"
  142. fi
  143. kernel_config_fragment_dir=../kernel_config_fragment
  144. if [ -n "$linux_kernel_custom_config_file" ]; then
  145. if [ -f "$linux_kernel_custom_config_file" ]; then
  146. printf "BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y\nBR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=\"${linux_kernel_custom_config_file}\"\n" >> "$config_file"
  147. if "${linux_reconfigure}"; then
  148. touch "${linux_kernel_custom_config_file}"
  149. fi
  150. else
  151. echo "error: -K: file does not exist: ${linux_kernel_custom_config_file}" 1>&2
  152. exit 1
  153. fi
  154. default_config_fragments=
  155. else
  156. default_config_fragments="${kernel_config_fragment_dir}/min ${kernel_config_fragment_dir}/default"
  157. fi
  158. printf "BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES=\"${default_config_fragments} ${kernel_config_fragments} ${kernel_config_fragment_cli_file}\"\n" >> "$config_file"
  159. if "${linux_reconfigure}"; then
  160. # https://stackoverflow.com/questions/49260466/why-when-i-change-br2-linux-kernel-custom-config-file-and-run-make-linux-reconfi
  161. touch "${kernel_config_fragment_dir}/min"
  162. fi
  163. if [ "$arch" = 'mips64' ]; then
  164. # Workaround for: https://bugs.busybox.net/show_bug.cgi?id=10276
  165. sed -Ei 's/^BR2_PACKAGE_LINUX_TOOLS_GPIO/BR2_PACKAGE_LINUX_TOOLS_GPIO=n/' "$config_file"
  166. fi
  167. make O="$buildroot_out_dir" olddefconfig
  168. fi
  169. common_mkdir
  170. cd "$buildroot_dir"
  171. # HOST_QEMU_OPTS is a hack that happens to work because the QEMU package luckly uses += at all times.
  172. # It shouldn't be necessary in the first place: https://bugs.busybox.net/show_bug.cgi?id=9936
  173. #
  174. # Even if were an autotools package, there is no general way currently to pass extra configs to it:
  175. # https://stackoverflow.com/questions/44341188/how-to-pass-extra-custom-configure-autotools-options-to-a-buildroot-package/44341225#44341225
  176. #
  177. # BR2_ options may be given on the command line here, and they do have direct "define" effects.
  178. # But this is generally bad, as it skips the Kconfig mechanism, e.g. it does not set defaults properly.
  179. cmd="time \\
  180. env \\
  181. -u LD_LIBRARY_PATH \\
  182. make \\
  183. O='${buildroot_out_dir}' \\
  184. HOST_QEMU_OPTS='--enable-debug --enable-trace-backends=simple ${qemu_sdl}' \\
  185. V='${v}' \\
  186. ${extra_make_args} \
  187. all \\
  188. "
  189. "${root_dir}/eeval" "$cmd" "${out_arch_dir}/build.sh"