build 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #!/usr/bin/env bash
  2. set -eu
  3. . common
  4. set -- ${cli_build:-} "$@"
  5. br2_cli_file="${out_dir}/br2_cli"
  6. mkdir -p "${out_dir}"
  7. rm -f "$br2_cli_file"
  8. touch "$br2_cli_file"
  9. configure=true
  10. config_fragments="${root_dir}/br2"
  11. extra_make_args=
  12. j="$(nproc)"
  13. linux_reconfigure=false
  14. linux_kernel_custom_config_file=
  15. post_script_args=
  16. qemu_sdl='--enable-sdl --with-sdlabi=2.0'
  17. v=0
  18. while getopts 'a:B:b:CGgj:hIiK:klp:qSv' OPT; do
  19. case "$OPT" in
  20. a)
  21. arch="$OPTARG"
  22. ;;
  23. b)
  24. config_fragments="${config_fragments} $(common_abspath "${OPTARG}")"
  25. ;;
  26. B)
  27. echo "$OPTARG" >> "$br2_cli_file"
  28. ;;
  29. C)
  30. configure=false
  31. ;;
  32. G)
  33. extra_make_args="${extra_make_args} gem5-reconfigure \\
  34. "
  35. gem5=true
  36. ;;
  37. g)
  38. gem5=true
  39. ;;
  40. h)
  41. cat build-usage.adoc 1>&2
  42. exit
  43. ;;
  44. I)
  45. echo "
  46. BR2_TARGET_ROOTFS_CPIO=n
  47. BR2_TARGET_ROOTFS_EXT2=n
  48. BR2_TARGET_ROOTFS_INITRAMFS=y
  49. " >> "$br2_cli_file"
  50. ;;
  51. i)
  52. echo "
  53. BR2_TARGET_ROOTFS_CPIO=y
  54. BR2_TARGET_ROOTFS_EXT2=n
  55. BR2_TARGET_ROOTFS_INITRAMFS=n
  56. " >> "$br2_cli_file"
  57. ;;
  58. j)
  59. j="$OPTARG"
  60. ;;
  61. K)
  62. linux_kernel_custom_config_file="$OPTARG"
  63. ;;
  64. k)
  65. extra_make_args="${extra_make_args} kernel_module-reconfigure \\
  66. "
  67. ;;
  68. l)
  69. linux_reconfigure=true
  70. extra_make_args="${extra_make_args} linux-reconfigure \\
  71. "
  72. ;;
  73. p)
  74. post_script_args="$OPTARG"
  75. ;;
  76. q)
  77. extra_make_args="${extra_make_args} host-qemu-reconfigure \\
  78. "
  79. ;;
  80. S)
  81. qemu_sdl=
  82. ;;
  83. v)
  84. v=1
  85. ;;
  86. ?)
  87. exit 2
  88. ;;
  89. esac
  90. done
  91. shift $(($OPTIND - 1))
  92. extra_make_args="${extra_make_args} $@"
  93. set_common_vars "$arch" "$gem5"
  94. config_file="${buildroot_out_dir}/.config"
  95. case "$arch" in
  96. x86_64)
  97. defconfig=qemu_x86_64_defconfig
  98. ;;
  99. arm)
  100. defconfig=qemu_arm_versatile_defconfig
  101. ;;
  102. aarch64)
  103. defconfig=qemu_aarch64_virt_defconfig
  104. ;;
  105. mips64)
  106. defconfig=qemu_mips64r6_malta_defconfig
  107. ;;
  108. esac
  109. if ! "$gem5"; then
  110. config_fragments="$config_fragments ${root_dir}/br2_qemu"
  111. fi
  112. config_fragments="${config_fragments} ${br2_cli_file}"
  113. # Configure.
  114. if "$configure"; then
  115. cd "${buildroot_dir}"
  116. for p in $(find "${root_dir}/buildroot_patches/" -maxdepth 1 -name '*.patch' -print); do
  117. patch -N -r - -p 1 < "$p" || :
  118. done
  119. make O="$buildroot_out_dir" BR2_EXTERNAL="../kernel_module:../gem5:../parsec-benchmark:../sample_package" "$defconfig"
  120. # TODO Can't get rid of these for now.
  121. # http://stackoverflow.com/questions/44078245/is-it-possible-to-use-config-fragments-with-buildroots-config
  122. for config_fragment in $config_fragments; do
  123. cat "$config_fragment" >> "$config_file"
  124. done
  125. printf "
  126. BR2_JLEVEL=${j}
  127. BR2_DL_DIR=\"${common_dir}/dl\"
  128. BR2_ROOTFS_POST_SCRIPT_ARGS=\"${post_script_args}\"
  129. " >> "$config_file"
  130. if "$gem5"; then
  131. printf "BR2_PACKAGE_GEM5=y\n" >> "${config_file}"
  132. if [ -z "$linux_kernel_custom_config_file" ] && [ ! "$arch" = aarch64 ]; then
  133. f="../kernel_config_${arch_dir}"
  134. if [ -f "$f" ]; then
  135. printf "BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=\"$f\"\n" >> "$config_file"
  136. fi
  137. fi
  138. fi
  139. if [ -n "$linux_kernel_custom_config_file" ]; then
  140. f="../${linux_kernel_custom_config_file}"
  141. if [ -f "$f" ]; then
  142. printf "BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=\"${f}\"\n" >> "$config_file"
  143. if "${linux_reconfigure}"; then
  144. touch "$f"
  145. fi
  146. else
  147. echo "error: -K: file does not exist: ${linux_kernel_custom_config_file}" 1>&2
  148. exit 1
  149. fi
  150. else
  151. f=../kernel_config_fragment
  152. printf "BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES=\"${f}\"\n" >> "$config_file"
  153. if "${linux_reconfigure}"; then
  154. # https://stackoverflow.com/questions/49260466/why-when-i-change-br2-linux-kernel-custom-config-file-and-run-make-linux-reconfi
  155. touch "$f"
  156. fi
  157. fi
  158. if [ "$arch" = 'mips64' ]; then
  159. # Workaround for:
  160. # http://lists.busybox.net/pipermail/buildroot/2017-August/201053.html
  161. sed -Ei 's/^BR2_PACKAGE_LINUX_TOOLS_GPIO/BR2_PACKAGE_LINUX_TOOLS_GPIO=n/' "$config_file"
  162. fi
  163. make O="$buildroot_out_dir" olddefconfig
  164. fi
  165. mkdir -p \
  166. "$gem5_out_dir" \
  167. "$qemu_out_dir" \
  168. "$p9_dir" \
  169. ;
  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 --extra-cflags=-DDEBUG_PL061=1 --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"