2
0

Makefile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. MAKEFLAGS += -R -r
  2. PROJECT := max80
  3. SUBDIRS := esp32 tools rv32 fpga
  4. REVISIONS := v1 v2 bypass
  5. GIT_DIR ?= .git
  6. TEMP ?= /tmp
  7. MAX80_IP ?= max80
  8. CURL = curl
  9. PERL = perl
  10. PYTHON = python
  11. ESPTOOL ?= esptool.py
  12. export ESPTOOL
  13. all clean spotless :
  14. $(MAKE) local.$@ $(SUBDIRS) goal=$@
  15. prefpga:
  16. $(MAKE) local.all $(filter-out fpga,$(SUBDIRS)) goal=all
  17. $(REVISIONS): prefpga
  18. $(MAKE) -C fpga $@
  19. .PHONY: $(SUBDIRS)
  20. $(SUBDIRS):
  21. $(MAKE) -C $@ $(goal)
  22. .PHONY: version.mk
  23. version.mk:
  24. if git log -n 1 --date=iso --pretty="format:\
  25. PROJECT=$(PROJECT)%n\
  26. COMMIT_VERSION=%(describe:abbrev=6)%n\
  27. COMMIT_ID=%H%nCOMMIT_MAGIC=%h%n\
  28. COMMIT_DATE=%ci%n\
  29. COMMIT_TIME=%ct%n\
  30. COMMIT_AUTHOR=%an <%ae>%n\
  31. " > '$@.tmp' 2>/dev/null && \
  32. ! cmp -s '$@' '$@.tmp' 2>/dev/null; then \
  33. mv -f '$@.tmp' '$@'; else rm -f '$@.tmp'; fi
  34. version.%: version.mk version.%.sed
  35. sed -f $@.sed $< > $@
  36. .PHONY: version
  37. version: version.mk version.h version.vh
  38. $(SUBDIRS): version.mk
  39. esp32: version.h
  40. rv32: version.h | tools
  41. fpga: version.vh | rv32 esp32
  42. local.all:
  43. local.clean:
  44. rm -f *~ ./\#* \# *.bak *.tmp stamp_*.bin
  45. local.spotless: local.clean
  46. rm -f version.h version.vh
  47. if [ -d .git ]; then rm -f version.mk; fi
  48. # Obsolete target, need version
  49. program flash:
  50. @echo 'Please specify one of: $(foreach rev,$(REVISIONS),$@-$(rev))' 1>&2
  51. @false
  52. # FPGA-specific targets
  53. program-% flash-%: prefpga
  54. $(MAKE) -C fpga $@
  55. # ESP update by USB or serial port using esptool directly
  56. upload-esp:
  57. $(MAKE) -C esp32 upload
  58. ip = $(MAX80_IP)
  59. ifeq ($(PORT),)
  60. # --- Upload via HTTP ---
  61. # Generic upload for newer firmware
  62. upload:
  63. @echo 'NOT IMPLEMENTED YET, should be:'
  64. @echo '$(CURL) -v --data-binary @fpga/output/$(PROJECT).fw http://$(ip)/sys/fwupdate'
  65. @exit 1
  66. # Version-specific uploads for older firmware
  67. upload-v%:
  68. $(CURL) -v --data-binary @fpga/output/v$*.fw 'http://$(ip)/sys/fwupdate'
  69. # setver is not supported via HTTP
  70. setver-v%:
  71. @echo 'make $@ requires PORT= to be specified'
  72. @exit 1
  73. else
  74. # --- Upload via serial port/USB
  75. # Generic upload for newer firmware
  76. upload:
  77. @echo 'NOT IMPLEMENTED YET, should be:'
  78. @echo '$(PERL) ./tools/flashmax.pl fpga/output/$(PROJECT).fw $(PORT) $(FLASHOPT)'
  79. @exit 1
  80. # Version-specific uploads for older firmware
  81. upload-v%:
  82. $(PERL) ./tools/flashmax.pl fpga/output/v$*.fw '$(PORT)' $(FLASHOPT)
  83. # Write board ID/revision to flash
  84. WRITEFLASH = $(ESPTOOL) --before default_reset --after hard_reset --port '$(PORT)' write_flash -z
  85. stamp_max80_v%.bin:
  86. $(PERL) -e '$$m = "MAX80 v$*\0"; print $$m, "\xff" x (4096 - length ($$m));' > $@
  87. # esptool is unreliable, so retry several times with a brief break in between
  88. setver-v%: stamp_max80_v%.bin
  89. for i in `seq 1 5`; do \
  90. $(WRITEFLASH) 0 $< && break; \
  91. sleep 1; \
  92. done
  93. endif