build 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/usr/bin/env bash
  2. set -eu
  3. arch=x86_64
  4. configure=true
  5. config_fragments=buildroot_config_fragment
  6. extra_make_args=''
  7. gem5=false
  8. j="$(($(nproc) - 2))"
  9. post_script_args=''
  10. qemu_sdl='--enable-sdl --with-sdlabi=2.0'
  11. v=0
  12. while getopts 'a:Cgj:i:klp:qS:v' OPT; do
  13. case "$OPT" in
  14. a)
  15. arch="$OPTARG"
  16. ;;
  17. C)
  18. configure=false
  19. ;;
  20. g)
  21. gem5=true
  22. ;;
  23. j)
  24. j="$OPTARG"
  25. ;;
  26. i)
  27. config_fragments="$config_fragments $OPTARG"
  28. ;;
  29. k)
  30. extra_make_args="$extra_make_args kernel_module-reconfigure"
  31. ;;
  32. l)
  33. extra_make_args="$extra_make_args linux-reconfigure"
  34. ;;
  35. p)
  36. post_script_args="$OPTARG"
  37. ;;
  38. q)
  39. extra_make_args="$extra_make_args host-qemu-reconfigure"
  40. ;;
  41. S)
  42. qemu_sdl=''
  43. ;;
  44. v)
  45. v=1
  46. ;;
  47. esac
  48. done
  49. shift $(($OPTIND - 1))
  50. extra_make_args="$extra_make_args $@"
  51. case "$arch" in
  52. x86_64)
  53. defconfig=qemu_x86_64_defconfig
  54. ;;
  55. arm)
  56. defconfig=qemu_arm_versatile_defconfig
  57. ;;
  58. aarch64)
  59. defconfig=qemu_aarch64_virt_defconfig
  60. ;;
  61. mips64)
  62. defconfig=qemu_mips64r6_malta_defconfig
  63. ;;
  64. esac
  65. arch_dir="$arch"
  66. if "$gem5"; then
  67. arch_dir="${arch}-gem5"
  68. # Networking was not working, so disable it to speed things up.
  69. post_script_args="$post_script_args -n"
  70. else
  71. config_fragments="$config_fragments buildroot_config_fragment_qemu"
  72. fi
  73. root_dir="$(pwd)"
  74. buildroot_dir="${root_dir}/buildroot"
  75. out_dir="${buildroot_dir}/output.${arch_dir}~"
  76. config_file="${out_dir}/.config"
  77. if "$configure"; then
  78. cd "${buildroot_dir}"
  79. for p in $(find "${root_dir}/buildroot_patches/" -maxdepth 1 -name '*.patch' -print); do
  80. patch -N -r - -p 1 <"$p" || :
  81. done
  82. make O="$out_dir" BR2_EXTERNAL="${root_dir}/kernel_module:${root_dir}/gem5:${root_dir}/parsec-benchmark" "$defconfig"
  83. # TODO Can't get rid of these for now.
  84. # http://stackoverflow.com/questions/44078245/is-it-possible-to-use-config-fragments-with-buildroots-config
  85. for config_fragment in $config_fragments; do
  86. cat "../$config_fragment" >> "${config_file}"
  87. done
  88. printf "
  89. BR2_JLEVEL=$j
  90. BR2_ROOTFS_POST_SCRIPT_ARGS=\"$post_script_args\"
  91. " >> "${config_file}"
  92. if "$gem5"; then
  93. printf "\
  94. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE=\"../kernel_config_${arch_dir}\"
  95. BR2_PACKAGE_GEM5=y
  96. " >> "${config_file}"
  97. else
  98. printf "\
  99. BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES=\"../kernel_config_fragment\"
  100. " >> "${config_file}"
  101. fi
  102. if [ "$arch" = 'mips64' ]; then
  103. # Workaround for:
  104. # http://lists.busybox.net/pipermail/buildroot/2017-August/201053.html
  105. sed -Ei 's/^BR2_PACKAGE_LINUX_TOOLS_GPIO/BR2_PACKAGE_LINUX_TOOLS_GPIO=n/' "${config_file}"
  106. fi
  107. make O="$out_dir" olddefconfig
  108. fi
  109. cd "${root_dir}/kernel_module"
  110. ./make-host.sh -j "$j" clean
  111. cd "${buildroot_dir}"
  112. # HOST_QEMU_OPTS is a hack that happens to work because the QEMU package luckly uses += at all times.
  113. # It shouldn't be necessary in the first place: https://bugs.busybox.net/show_bug.cgi?id=9936
  114. #
  115. # Even if were an autotools package, there is no general way currently to pass extra configs to it:
  116. # https://stackoverflow.com/questions/44341188/how-to-pass-extra-custom-configure-autotools-options-to-a-buildroot-package/44341225#44341225
  117. #
  118. # BR2_ options may be given on the command line here, and they do have direct "define" effects.
  119. # But this is generally bad, as it skips the Kconfig mechanism, e.g. it does not set defaults properly.
  120. cmd="time \
  121. env \
  122. -u LD_LIBRARY_PATH \
  123. make \
  124. O='$out_dir' \
  125. HOST_QEMU_OPTS='--enable-debug --extra-cflags=-DDEBUG_PL061=1 --enable-trace-backends=simple $qemu_sdl' \
  126. V='$v' \
  127. $extra_make_args \
  128. all \
  129. "
  130. echo "$cmd" | tee "${root_dir}/build.log"
  131. eval "$cmd"
  132. if "$gem5"; then
  133. cd "${root_dir}"
  134. ./build-gem5 -a "$arch"
  135. fi