build 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. post_script_args=
  19. qemu_sdl='--enable-sdl --with-sdlabi=2.0'
  20. suffix=
  21. v=0
  22. while getopts 'a:B:b:Cc:Ggj:hIiK:klp:qSs:v' OPT; do
  23. case "$OPT" in
  24. a)
  25. arch="$OPTARG"
  26. ;;
  27. B)
  28. echo "$OPTARG" >> "$br2_cli_file"
  29. ;;
  30. b)
  31. config_fragments="${config_fragments} $(common_abspath "${OPTARG}")"
  32. ;;
  33. C)
  34. configure=false
  35. ;;
  36. c)
  37. echo "$OPTARG" >> "$kernel_config_fragment_cli_file"
  38. ;;
  39. g)
  40. extra_make_args="${extra_make_args} gem5-reconfigure \\
  41. "
  42. gem5=true
  43. ;;
  44. h)
  45. cat build-usage.adoc 1>&2
  46. exit
  47. ;;
  48. I)
  49. echo "
  50. BR2_TARGET_ROOTFS_CPIO=n
  51. BR2_TARGET_ROOTFS_EXT2=n
  52. BR2_TARGET_ROOTFS_INITRAMFS=y
  53. " >> "$br2_cli_file"
  54. ;;
  55. i)
  56. echo "
  57. BR2_TARGET_ROOTFS_CPIO=y
  58. BR2_TARGET_ROOTFS_EXT2=n
  59. BR2_TARGET_ROOTFS_INITRAMFS=n
  60. " >> "$br2_cli_file"
  61. ;;
  62. j)
  63. j="$OPTARG"
  64. ;;
  65. K)
  66. linux_kernel_custom_config_file="$(common_abspath "${OPTARG}")"
  67. ;;
  68. k)
  69. extra_make_args="${extra_make_args} kernel_module-reconfigure \\
  70. "
  71. ;;
  72. l)
  73. linux_reconfigure=true
  74. extra_make_args="${extra_make_args} linux-reconfigure \\
  75. "
  76. ;;
  77. p)
  78. post_script_args="$OPTARG"
  79. ;;
  80. q)
  81. extra_make_args="${extra_make_args} host-qemu-reconfigure \\
  82. "
  83. ;;
  84. S)
  85. qemu_sdl=
  86. ;;
  87. s)
  88. suffix="$OPTARG"
  89. ;;
  90. v)
  91. v=1
  92. ;;
  93. ?)
  94. exit 2
  95. ;;
  96. esac
  97. done
  98. shift $(($OPTIND - 1))
  99. extra_make_args="${extra_make_args} $@"
  100. set_common_vars "$arch" "$gem5" "$suffix"
  101. config_file="${buildroot_out_dir}/.config"
  102. case "$arch" in
  103. x86_64)
  104. defconfig=qemu_x86_64_defconfig
  105. ;;
  106. arm)
  107. defconfig=qemu_arm_vexpress_defconfig
  108. ;;
  109. aarch64)
  110. defconfig=qemu_aarch64_virt_defconfig
  111. ;;
  112. mips64)
  113. defconfig=qemu_mips64r6_malta_defconfig
  114. ;;
  115. esac
  116. config_fragments="${config_fragments} ${root_dir}/br2_qemu ${br2_cli_file}"
  117. # Configure.
  118. if "$configure"; then
  119. cd "${buildroot_dir}"
  120. for p in $(find "${root_dir}/buildroot_patches/" -maxdepth 1 -name '*.patch' -print); do
  121. patch -N -r - -p 1 < "$p" || :
  122. done
  123. make O="$buildroot_out_dir" BR2_EXTERNAL="../kernel_module:../gem5:../parsec-benchmark:../sample_package" "$defconfig"
  124. # TODO Can't get rid of these for now.
  125. # http://stackoverflow.com/questions/44078245/is-it-possible-to-use-config-fragments-with-buildroots-config
  126. for config_fragment in $config_fragments; do
  127. cat "$config_fragment" >> "$config_file"
  128. done
  129. printf "
  130. BR2_JLEVEL=${j}
  131. BR2_DL_DIR=\"${common_dir}/dl\"
  132. BR2_ROOTFS_POST_SCRIPT_ARGS=\"${post_script_args}\"
  133. " >> "$config_file"
  134. if "$gem5"; then
  135. printf "BR2_PACKAGE_GEM5=y\n" >> "${config_file}"
  136. fi
  137. if [ -n "$linux_kernel_custom_config_file" ]; then
  138. if [ -f "$linux_kernel_custom_config_file" ]; then
  139. printf "BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y\nBR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=\"${linux_kernel_custom_config_file}\"\n" >> "$config_file"
  140. if "${linux_reconfigure}"; then
  141. touch "${linux_kernel_custom_config_file}"
  142. fi
  143. else
  144. echo "error: -K: file does not exist: ${linux_kernel_custom_config_file}" 1>&2
  145. exit 1
  146. fi
  147. default_config_fragments=
  148. else
  149. default_config_fragments="${d}/min ${d}/default"
  150. fi
  151. d=../kernel_config_fragment
  152. printf "BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES=\"${default_config_fragments} ${kernel_config_fragment_cli_file}\"\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 "${d}/min"
  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. "${root_dir}/eeval" "$cmd" "${out_arch_dir}/build.sh"