Makefile.rules 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. TARGET_ELF = $(TARGET).elf
  2. ALL_CSRCS = $(filter-out $(wildcard $(EXCLUDE_SRCS)), $(sort $(wildcard $(C_SRCS)) $(call get_csrcs, $(SRCDIRS) $(C_SRCDIRS))))
  3. ALL_CXXSRCS = $(filter-out $(wildcard $(EXCLUDE_SRCS)), $(sort $(wildcard $(CXX_SRCS)) $(call get_cxxsrcs, $(SRCDIRS) $(CXX_SRCDIRS))))
  4. ALL_ASMSRCS = $(filter-out $(wildcard $(EXCLUDE_SRCS)), $(sort $(wildcard $(ASM_SRCS)) $(call get_asmsrcs, $(SRCDIRS) $(ASM_SRCDIRS))))
  5. ALL_ASM_OBJS := $(ALL_ASMSRCS:=.o)
  6. ALL_C_OBJS := $(ALL_CSRCS:=.o)
  7. ALL_CXX_OBJS := $(ALL_CXXSRCS:=.o)
  8. ALL_OBJS += $(ALL_ASM_OBJS) $(ALL_C_OBJS) $(ALL_CXX_OBJS)
  9. ALL_DEPS := $(ALL_OBJS:=.d)
  10. CLEAN_OBJS += $(TARGET).elf $(TARGET).map $(TARGET).bin $(TARGET).dump $(TARGET).dasm \
  11. $(TARGET).srec $(TARGET).hex $(TARGET).verilog openocd.log $(ALL_OBJS) $(ALL_DEPS)
  12. REAL_CLEAN_OBJS = $(subst /,$(PS), $(CLEAN_OBJS))
  13. # Default goal, placed before dependency includes
  14. all: info $(TARGET).elf
  15. # include dependency files of application
  16. ifneq ($(MAKECMDGOALS),clean)
  17. -include $(ALL_DEPS)
  18. endif
  19. .PHONY: all info showflags showtoolver help bin size dasm upload run_openocd run_gdb run_qemu run_xlspike run_qemu_debug run_xlspike_rbb run_xlspike_openocd clean debug
  20. info:
  21. @$(ECHO) Current Configuration: RISCV_ARCH=$(RISCV_ARCH) RISCV_ABI=$(RISCV_ABI) RISCV_TUNE=$(RISCV_TUNE) RISCV_CMODEL=$(RISCV_CMODEL) SOC=$(SOC) BOARD=$(BOARD) CORE=$(CORE) DOWNLOAD=$(DOWNLOAD) STDCLIB=$(STDCLIB) SMP=$(SMP)
  22. showflags:
  23. @$(ECHO) TARGET: $(TARGET)
  24. @$(ECHO) NUCLEI_SDK_ROOT: $(NUCLEI_SDK_ROOT)
  25. @$(ECHO) NUCLEI_SDK_NMSIS: $(NUCLEI_SDK_NMSIS)
  26. @$(ECHO) OPENOCD_CFG: $(OPENOCD_CFG)
  27. @$(ECHO) LINKER_SCRIPT: $(LINKER_SCRIPT)
  28. @$(ECHO) ASMFLAGS: $(ASMFLAGS)
  29. @$(ECHO) CFLAGS: $(CFLAGS)
  30. @$(ECHO) CXXFLAGS: $(CXXFLAGS)
  31. @$(ECHO) LDFLAGS: $(LDFLAGS)
  32. showtoolver:
  33. @$(ECHO) Show $(CC) version
  34. @$(CC) -v
  35. @$(ECHO) Show $(OPENOCD) version
  36. @$(OPENOCD) -v
  37. @$(ECHO) Show $(QEMU) version
  38. -@$(QEMU) --version
  39. help:
  40. @$(ECHO) "Nuclei N/NX-series RISC-V Embedded Processor Software Development Kit "
  41. @$(ECHO) "== For detailed user guide, please check https://doc.nucleisys.com/nuclei_sdk/"
  42. @$(ECHO) "== Make variables used in Nuclei SDK =="
  43. @$(ECHO) "SOC: Select SoC built in Nuclei SDK, will select demosoc by default"
  44. @$(ECHO) "BOARD: Select SoC's Board built in Nuclei SDK, will select nuclei_fpga_eval by default"
  45. @$(ECHO) "CORE: Not required for all SoCs, currently only demosoc require it, n307fd by default"
  46. @$(ECHO) "ARCH_EXT: Not required for all SoCs, currently only demosoc require it, such as ARCH_EXT=bp, means B, P extension"
  47. @$(ECHO) "DOWNLOAD: Not required for all SoCs, use ilm by default, optional flashxip/ilm/flash/ddr"
  48. @$(ECHO) "V: V=1 verbose make, will print more information, by default V=0"
  49. @$(ECHO) "== How to Use with Make =="
  50. @$(ECHO) "1. Build Application:"
  51. @$(ECHO) "all [PROGRAM=flash/flashxip/ilm/ddr]"
  52. @$(ECHO) " Build a software program to load with the debugger."
  53. @$(ECHO) "2. Upload Application to Board using OpenOCD and GDB:"
  54. @$(ECHO) "upload [PROGRAM=flash/flashxip/ilm/ddr]"
  55. @$(ECHO) " Launch OpenOCD to flash your program to the on-board Flash."
  56. @$(ECHO) "3:(Option 1) Debug Application using OpenOCD and GDB"
  57. @$(ECHO) " 3.1: run_openocd"
  58. @$(ECHO) " 3.2: run_gdb [PROGRAM=flash/flashxip/ilm/ddr]"
  59. @$(ECHO) " Step 1: Launch OpenOCD for Debugger connection: make run_openocd"
  60. @$(ECHO) " Step 2: Launch GDB to connect openocd server, you can set breakpoints using gdb and debug it."
  61. @$(ECHO) " If you want to load your application, you need to run load in gdb command terminal"
  62. @$(ECHO) " to load your program, then use gdb to debug it."
  63. @$(ECHO) "3:(Option 2) Debug Application using OpenOCD and GDB"
  64. @$(ECHO) "debug [PROGRAM=flash/flashxip/ilm/ddr]"
  65. @$(ECHO) " Launch GDB and OpenOCD to debug your application on-board, you can set breakpoints using gdb and debug it."
  66. @$(ECHO) " If you want to load your application, you need to run load in gdb command terminal"
  67. @$(ECHO) " to load your program, then use gdb to debug it."
  68. @$(ECHO) ""
  69. @$(ECHO) "== Example Usage =="
  70. @$(ECHO) "1. cd <NUCLEI_SDK_ROOT>/application/helloworld"
  71. @$(ECHO) "2. Build for ILM download mode: make DOWNLOAD=ilm all"
  72. @$(ECHO) "3. Download application to board: make DOWNLOAD=ilm upload"
  73. @$(ECHO) "4.(Option 1) Debug application:"
  74. @$(ECHO) " 4.1 Terminal One: make DOWNLOAD=ilm run_openocd"
  75. @$(ECHO) " 4.2 Terminal Two: make DOWNLOAD=ilm run_gdb"
  76. @$(ECHO) "4.(Option 2) Debug application: make DOWNLOAD=ilm debug"
  77. @$(ECHO) ""
  78. $(TARGET).elf: $(ALL_OBJS)
  79. $(TRACE_LINK)
  80. $(Q)$(CC) $(CFLAGS) $(ALL_OBJS) -o $@ $(LDFLAGS)
  81. $(Q)$(SIZE) $@
  82. $(ALL_ASM_OBJS): %.o: % $(COMMON_PREREQS)
  83. $(TRACE_ASSEMBLE)
  84. $(Q)$(CC) $(ASMFLAGS) $(MKDEP_OPT) -c -o $@ $<
  85. $(ALL_C_OBJS): %.o: % $(COMMON_PREREQS)
  86. $(TRACE_COMPILE)
  87. $(Q)$(CC) $(CFLAGS) $(MKDEP_OPT) -c -o $@ $<
  88. $(ALL_CXX_OBJS): %.o: % $(COMMON_PREREQS)
  89. $(TRACE_COMPILE)
  90. $(Q)$(CXX) $(CXXFLAGS) $(MKDEP_OPT) -c -o $@ $<
  91. dasm: $(TARGET).elf
  92. -$(OBJDUMP) -S -d $< > $(TARGET).dump
  93. -$(OBJDUMP) -d $< > $(TARGET).dasm
  94. -$(OBJCOPY) $< -O ihex $(TARGET).hex
  95. -$(OBJCOPY) $< -O srec $(TARGET).srec
  96. -$(OBJCOPY) $< -O verilog $(TARGET).verilog
  97. bin: $(TARGET).elf
  98. $(OBJCOPY) $< -O binary $(TARGET).bin
  99. size: $(TARGET).elf
  100. $(Q)$(SIZE) $<
  101. upload: $(TARGET).elf
  102. @$(ECHO) "Download and run $<"
  103. $(GDB) $< -ex "set remotetimeout 240" \
  104. -ex "target remote $(GDBREMOTE)" \
  105. $(GDB_UPLOAD_ARGS) $(GDB_UPLOAD_CMDS)
  106. run_openocd:
  107. @$(ECHO) "Start openocd server"
  108. $(OPENOCD) $(OPENOCD_PORT_ARGS) $(OPENOCD_ARGS)
  109. run_gdb: $(TARGET).elf
  110. @$(ECHO) "Run gdb to connect openocd server and debug"
  111. $(GDB) $< $(GDB_ARGS) $(GDB_CMDS)
  112. debug: $(TARGET).elf
  113. @$(ECHO) "Download and debug $<"
  114. $(GDB) $< -ex "set remotetimeout 240" \
  115. -ex "target remote $(GDBREMOTE)"
  116. # just for demosoc purpose
  117. run_qemu: $(TARGET).elf
  118. @$(ECHO) "Run program $< on $(QEMU)"
  119. $(QEMU) -M $(QEMU_MACHINE) -cpu $(QEMU_CPU) $(QEMU_OPT) \
  120. -nodefaults -nographic -serial stdio -kernel $<
  121. # just for demosoc purpose
  122. run_qemu_debug: $(TARGET).elf
  123. @$(ECHO) "Run program $< on $(QEMU), and waiting for gdb connection on port $(GDB_PORT)"
  124. @$(ECHO) "Then you can open a new terminal in the same directory and run make target: run_gdb to connect to this gdb connection"
  125. $(QEMU) -M $(QEMU_MACHINE) -cpu $(QEMU_CPU) $(QEMU_OPT) \
  126. -nodefaults -nographic -serial stdio -kernel $< -S -gdb tcp::$(GDB_PORT)
  127. # just works on demosoc purpose, experimental support
  128. run_xlspike: $(TARGET).elf
  129. @$(ECHO) "Run program $< on $(XLSPIKE)"
  130. $(XLSPIKE) $(XLSPIKE_OPT) --isa $(RISCV_ARCH) $<
  131. run_xlspike_rbb: $(TARGET).elf
  132. @$(ECHO) "Run program $< on $(XLSPIKE), and waiting for remote bitbang connection on port $(RBB_PORT)"
  133. @$(ECHO) "Then you need open a new terminal in the same directory and run make target: run_xlspike_openocd to connect to this remote bitbang connection"
  134. $(XLSPIKE) $(XLSPIKE_OPT) --rbb-port=$(RBB_PORT) -H --isa $(RISCV_ARCH) $<
  135. run_xlspike_openocd:
  136. @$(ECHO) "Run openocd to connect to remote bitbang connection"
  137. @$(ECHO) "Then you can open a new terminal in the same directory and run make target: run_gdb to connect to this gdb connection"
  138. $(OPENOCD) $(OPENOCD_PORT_ARGS) -f $(OPENOCD_XLSPIKE_CFG)
  139. clean:
  140. @$(ECHO) "Clean all build objects"
  141. $(Q)$(RM) $(REAL_CLEAN_OBJS)