MAKEFLAGS += -R -r PROJECT := max80 SUBDIRS := esp32 tools rv32 fpga REVISIONS := v1 v2 bypass GIT_DIR ?= .git TEMP ?= /tmp MAX80_IP ?= max80 CURL = curl PERL = perl PYTHON = python ESPTOOL ?= esptool.py export ESPTOOL all clean spotless : $(MAKE) local.$@ $(SUBDIRS) goal=$@ prefpga: $(MAKE) local.all $(filter-out fpga,$(SUBDIRS)) goal=all $(REVISIONS): prefpga $(MAKE) -C fpga $@ .PHONY: $(SUBDIRS) $(SUBDIRS): $(MAKE) -C $@ $(goal) .PHONY: version.mk version.mk: if git log -n 1 --date=iso --pretty="format:\ PROJECT=$(PROJECT)%n\ COMMIT_VERSION=%(describe:abbrev=6)%n\ COMMIT_ID=%H%nCOMMIT_MAGIC=%h%n\ COMMIT_DATE=%ci%n\ COMMIT_TIME=%ct%n\ COMMIT_AUTHOR=%an <%ae>%n\ " > '$@.tmp' 2>/dev/null && \ ! cmp -s '$@' '$@.tmp' 2>/dev/null; then \ mv -f '$@.tmp' '$@'; else rm -f '$@.tmp'; fi version.%: version.mk version.%.sed sed -f $@.sed $< > $@ .PHONY: version version: version.mk version.h version.vh $(SUBDIRS): version.mk esp32: version.h rv32: version.h | tools fpga: version.vh | rv32 esp32 local.all: local.clean: rm -f *~ ./\#* \# *.bak *.tmp stamp_*.bin local.spotless: local.clean rm -f version.h version.vh if [ -d .git ]; then rm -f version.mk; fi # Obsolete target, need version program flash: @echo 'Please specify one of: $(foreach rev,$(REVISIONS),$@-$(rev))' 1>&2 @false # FPGA-specific targets program-% flash-%: prefpga $(MAKE) -C fpga $@ # ESP update by USB or serial port using esptool directly upload-esp: $(MAKE) -C esp32 upload ip = $(MAX80_IP) ifeq ($(PORT),) # --- Upload via HTTP --- # Generic upload for newer firmware upload: $(CURL) -v --data-binary @fpga/output/$(PROJECT).fw 'http://$(ip)/sys/fwupdate' # Version-specific uploads for older firmware upload-v%: $(CURL) -v --data-binary @fpga/output/v$*.fw 'http://$(ip)/sys/fwupdate' # setver is not supported via HTTP setver-v%: @echo 'make $@ requires PORT= to be specified' @exit 1 else # --- Upload via serial port/USB # Generic upload for newer firmware upload: $(PERL) ./tools/flashmax.pl fpga/output/$(PROJECT).fw '$(PORT)' $(FLASHOPT) # Version-specific uploads for older firmware upload-v%: $(PERL) ./tools/flashmax.pl fpga/output/v$*.fw '$(PORT)' $(FLASHOPT) # Write board ID/revision to flash WRITEFLASH = $(ESPTOOL) --before default_reset --after hard_reset --port '$(PORT)' write_flash -z stamp_max80_v%.bin: $(PERL) -e '$$m = "MAX80 v$*\0"; print $$m, "\xff" x (4096 - length ($$m));' > $@ # esptool is unreliable, so retry several times with a brief break in between setver-v%: stamp_max80_v%.bin for i in `seq 1 5`; do \ $(WRITEFLASH) 0 $< && break; \ sleep 1; \ done endif