Makefile.rules 7.8 KB

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