serprog 2.0 KB

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