Makefile 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. BOARD ?= icebreaker
  2. CROSS ?= riscv-none-elf-
  3. CC = $(CROSS)gcc
  4. OBJCOPY = $(CROSS)objcopy
  5. ICEPROG = iceprog
  6. DFU_UTIL = dfu-util
  7. BOARD_DEFINE=BOARD_$(shell echo $(BOARD) | tr a-z\- A-Z_)
  8. CFLAGS=-Wall -Os -march=rv32i -mabi=ilp32 -ffreestanding -flto -nostartfiles -fomit-frame-pointer -Wl,--gc-section -D$(BOARD_DEFINE) -I.
  9. HEADERS_common=\
  10. config.h \
  11. console.h \
  12. led.h \
  13. mini-printf.h \
  14. spi.h \
  15. utils.h \
  16. registers.h \
  17. generation.h
  18. SOURCES_common=\
  19. start.S \
  20. console.c \
  21. led.c \
  22. mini-printf.c \
  23. spi.c \
  24. utils.c \
  25. generation.c
  26. HEADERS_app=\
  27. #usb_str_app.gen.h \
  28. $(NULL)
  29. SOURCES_app=\
  30. fw_app.c \
  31. #usb_desc_app.c \
  32. $(NULL)
  33. all: boot.hex fw_app.bin
  34. boot.elf: lnk-boot.lds boot.S
  35. $(CC) $(CFLAGS) -Wl,-Bstatic,-T,lnk-boot.lds,--strip-debug -DFLASH_APP_ADDR=0x000a0000 -o $@ boot.S
  36. fw_app.elf: lnk-app.lds $(HEADERS_app) $(SOURCES_app) $(HEADERS_common) $(SOURCES_common)
  37. $(CC) $(CFLAGS) -Wl,-Bstatic,-T,lnk-app.lds,--strip-debug -o $@ $(SOURCES_common) $(SOURCES_app)
  38. %.hex: %.bin
  39. python ./bin2hex.py $< $@
  40. %.bin: %.elf
  41. $(OBJCOPY) -O binary $< $@
  42. prog: fw_app.bin
  43. $(ICEPROG) -o 640k $<
  44. dfuprog: fw_app.bin
  45. ifeq ($(DFU_SERIAL),)
  46. $(DFU_UTIL) -R -a 1 -D $<
  47. else
  48. $(DFU_UTIL) -R -S $(DFU_SERIAL) -a 1 -D $<
  49. endif
  50. clean:
  51. rm -f *.bin *.hex *.elf *.o *.gen.h
  52. .PHONY: prog_app clean