build 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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"
  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. ;;
  113. aarch64)
  114. defconfig=qemu_aarch64_virt_defconfig
  115. ;;
  116. mips64)
  117. defconfig=qemu_mips64r6_malta_defconfig
  118. ;;
  119. esac
  120. config_fragments="${config_fragments} ${root_dir}/br2_qemu ${br2_cli_file}"
  121. # Configure.
  122. if "$configure"; then
  123. cd "${buildroot_dir}"
  124. for p in $(find "${root_dir}/buildroot_patches/" -maxdepth 1 -name '*.patch' -print); do
  125. patch -N -r - -p 1 < "$p" || :
  126. done
  127. make O="$buildroot_out_dir" BR2_EXTERNAL="../kernel_module:../gem5:../parsec-benchmark:../sample_package" "$defconfig"
  128. # TODO Can't get rid of these for now.
  129. # http://stackoverflow.com/questions/44078245/is-it-possible-to-use-config-fragments-with-buildroots-config
  130. for config_fragment in $config_fragments; do
  131. cat "$config_fragment" >> "$config_file"
  132. done
  133. printf "
  134. BR2_JLEVEL=${j}
  135. BR2_DL_DIR=\"${common_dir}/dl\"
  136. BR2_ROOTFS_POST_SCRIPT_ARGS=\"${post_script_args}\"
  137. " >> "$config_file"
  138. if "$gem5"; then
  139. printf "BR2_PACKAGE_GEM5=y\n" >> "${config_file}"
  140. fi
  141. kernel_config_fragment_dir=../kernel_config_fragment
  142. if [ -n "$linux_kernel_custom_config_file" ]; then
  143. if [ -f "$linux_kernel_custom_config_file" ]; then
  144. printf "BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y\nBR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=\"${linux_kernel_custom_config_file}\"\n" >> "$config_file"
  145. if "${linux_reconfigure}"; then
  146. touch "${linux_kernel_custom_config_file}"
  147. fi
  148. else
  149. echo "error: -K: file does not exist: ${linux_kernel_custom_config_file}" 1>&2
  150. exit 1
  151. fi
  152. default_config_fragments=
  153. else
  154. default_config_fragments="${kernel_config_fragment_dir}/min ${kernel_config_fragment_dir}/default"
  155. fi
  156. printf "BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES=\"${default_config_fragments} ${kernel_config_fragments} ${kernel_config_fragment_cli_file}\"\n" >> "$config_file"
  157. if "${linux_reconfigure}"; then
  158. # https://stackoverflow.com/questions/49260466/why-when-i-change-br2-linux-kernel-custom-config-file-and-run-make-linux-reconfi
  159. touch "${kernel_config_fragment_dir}/min"
  160. fi
  161. if [ "$arch" = 'mips64' ]; then
  162. # Workaround for: https://bugs.busybox.net/show_bug.cgi?id=10276
  163. sed -Ei 's/^BR2_PACKAGE_LINUX_TOOLS_GPIO/BR2_PACKAGE_LINUX_TOOLS_GPIO=n/' "$config_file"
  164. fi
  165. make O="$buildroot_out_dir" olddefconfig
  166. if [ "$arch" = 'mips64' ]; then
  167. # Workaround for: https://bugs.busybox.net/show_bug.cgi?id=10276
  168. sed -Ei 's/^BR2_PACKAGE_LINUX_TOOLS_GPIO/BR2_PACKAGE_LINUX_TOOLS_GPIO=n/' "$config_file"
  169. fi
  170. make O="$buildroot_out_dir" olddefconfig
  171. fi
  172. mkdir -p \
  173. "$gem5_out_dir" \
  174. "$qemu_out_dir" \
  175. "$p9_dir" \
  176. ;
  177. cd "$buildroot_dir"
  178. # HOST_QEMU_OPTS is a hack that happens to work because the QEMU package luckly uses += at all times.
  179. # It shouldn't be necessary in the first place: https://bugs.busybox.net/show_bug.cgi?id=9936
  180. #
  181. # Even if were an autotools package, there is no general way currently to pass extra configs to it:
  182. # https://stackoverflow.com/questions/44341188/how-to-pass-extra-custom-configure-autotools-options-to-a-buildroot-package/44341225#44341225
  183. #
  184. # BR2_ options may be given on the command line here, and they do have direct "define" effects.
  185. # But this is generally bad, as it skips the Kconfig mechanism, e.g. it does not set defaults properly.
  186. cmd="time \\
  187. env \\
  188. -u LD_LIBRARY_PATH \\
  189. make \\
  190. O='${buildroot_out_dir}' \\
  191. HOST_QEMU_OPTS='--enable-debug --enable-trace-backends=simple ${qemu_sdl}' \\
  192. V='${v}' \\
  193. ${extra_make_args} \
  194. all \\
  195. "
  196. "${root_dir}/eeval" "$cmd" "${out_arch_dir}/build.sh"