serprog 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # SPDX-FileCopyrightText: 2023 Riku Viitanen <riku.viitanen@protonmail.com>
  4. set -u -e
  5. . "include/err.sh"
  6. eval "$(setvars "" platform pico_sdk_dir pico_src_dir stm32_src_dir boards_dir)"
  7. pico_src_dir=src/pico-serprog
  8. pico_sdk_dir=src/pico-sdk
  9. stm32_src_dir=src/stm32-vserprog
  10. usage="usage: ./build firmware serprog <rp2040|stm32> [board]"
  11. main()
  12. {
  13. [ -z "${1+x}" ] && err "${usage}"
  14. if [ "${1}" = "rp2040" ]; then
  15. platform="rp2040"
  16. boards_dir=${pico_sdk_dir}/src/boards/include/boards
  17. [ -d "${pico_src_dir}/" ] || \
  18. x_ ./update trees -f "pico-serprog"
  19. elif [ "${1}" = "stm32" ]; then
  20. platform="stm32"
  21. boards_dir=${stm32_src_dir}/boards
  22. [ -d "${stm32_src_dir}/" ] || \
  23. x_ ./update trees -f "stm32-vserprog"
  24. else
  25. err "${usage}"
  26. fi
  27. x_ mkdir -p "bin/serprog_${platform}"
  28. if [ $# -gt 1 ] ; then
  29. if [ "${2}" = "list" ]; then
  30. print_boards ${boards_dir}
  31. return 0
  32. fi
  33. build_${platform}_rom "${2}"
  34. else
  35. printf "Building all serprog targets\n"
  36. list_boards "${boards_dir}" | while read board; do
  37. build_${platform}_rom "${board}"
  38. done
  39. fi
  40. }
  41. build_rp2040_rom()
  42. {
  43. board=${1}
  44. printf "Building pico-serprog for %s\n" "${board}"
  45. x_ cmake -DPICO_BOARD="${board}" -DPICO_SDK_PATH="${pico_sdk_dir}" \
  46. -B "${pico_src_dir}/build" "${pico_src_dir}"
  47. x_ cmake --build "${pico_src_dir}/build"
  48. x_ mv ${pico_src_dir}/build/pico_serprog.uf2 \
  49. bin/serprog_rp2040/serprog_${board}.uf2
  50. printf "output to bin/serprog_rp2040/serprog_%s.uf2\n" "${board}"
  51. }
  52. build_stm32_rom()
  53. {
  54. board=${1}
  55. printf "Building stm32-vserprog for %s\n" "${board}"
  56. x_ make -C ${stm32_src_dir} libopencm3-just-make BOARD=${board}
  57. x_ make -C ${stm32_src_dir} BOARD=${board}
  58. x_ mv ${stm32_src_dir}/stm32-vserprog.hex \
  59. bin/serprog_stm32/serprog_${board}.hex
  60. printf "output to bin/serprog_stm32/serprog_%s.hex\n" "${board}"
  61. }
  62. print_boards()
  63. {
  64. printf "Available boards:\n"
  65. list_boards "${1}"
  66. }
  67. list_boards()
  68. {
  69. basename -a -s .h "${1}/"*.h
  70. }
  71. main $@