build 5.0 KB

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