Makefile 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. SOURCES_common=\
  18. start.S \
  19. console.c \
  20. led.c \
  21. mini-printf.c \
  22. spi.c \
  23. utils.c \
  24. registers.c
  25. HEADERS_app=\
  26. #usb_str_app.gen.h \
  27. $(NULL)
  28. SOURCES_app=\
  29. fw_app.c \
  30. #usb_desc_app.c \
  31. $(NULL)
  32. all: boot.hex fw_app.bin
  33. boot.elf: lnk-boot.lds boot.S
  34. $(CC) $(CFLAGS) -Wl,-Bstatic,-T,lnk-boot.lds,--strip-debug -DFLASH_APP_ADDR=0x000a0000 -o $@ boot.S
  35. fw_app.elf: lnk-app.lds $(HEADERS_app) $(SOURCES_app) $(HEADERS_common) $(SOURCES_common)
  36. $(CC) $(CFLAGS) -Wl,-Bstatic,-T,lnk-app.lds,--strip-debug -o $@ $(SOURCES_common) $(SOURCES_app)
  37. %.hex: %.bin
  38. python ./bin2hex.py $< $@
  39. %.bin: %.elf
  40. $(OBJCOPY) -O binary $< $@
  41. prog: fw_app.bin
  42. $(ICEPROG) -o 640k $<
  43. dfuprog: fw_app.bin
  44. ifeq ($(DFU_SERIAL),)
  45. $(DFU_UTIL) -R -a 1 -D $<
  46. else
  47. $(DFU_UTIL) -R -S $(DFU_SERIAL) -a 1 -D $<
  48. endif
  49. clean:
  50. rm -f *.bin *.hex *.elf *.o *.gen.h
  51. .PHONY: prog_app clean