Makefile.conf 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # Toolchain related settings
  2. TOOLCHAIN ?= nuclei_gnu
  3. # Overwrite NEWLIB when STDCLIB is defined
  4. ifdef STDCLIB
  5. override NEWLIB := $(STDCLIB)
  6. endif
  7. include $(NUCLEI_SDK_BUILD)/Makefile.files
  8. include $(NUCLEI_SDK_NMSIS)/build.mk
  9. include $(NUCLEI_SDK_BUILD)/Makefile.soc
  10. # Set your remote bitbang port
  11. RBB_PORT ?= 9824
  12. # Set your GDB port using variable GDB_PORT
  13. GDB_PORT ?= 3333
  14. ## Makefile Variable GDBREMOTE
  15. # You can change GDBREMOTE to other gdb remotes
  16. ## eg. if you have started openocd server with (bindto 0.0.0.0 defined in openocd.cfg)
  17. ## make sure your machine can connect to remote machine
  18. ## in remote machine(ipaddr 192.168.43.199, port 3333) which connect the hardware board,
  19. ## then you can change the GDBREMOTE to 192.168.43.199:3333
  20. ## GDBREMOTE ?= 192.168.43.199:3333
  21. GDBREMOTE ?= | $(OPENOCD) $(OPENOCD_OPT) -c \"$(OPENOCD_CMD_ARGS); gdb_port pipe; log_output openocd.log\" -f $(OPENOCD_CFG)
  22. GDB_UPLOAD_ARGS ?= --batch
  23. GDB_UPLOAD_CMDS += -ex 'thread apply all monitor reset halt'
  24. GDB_UPLOAD_CMDS += -ex 'thread apply all info reg pc'
  25. GDB_UPLOAD_CMDS += -ex 'thread 1'
  26. GDB_UPLOAD_CMDS += -ex 'load $<'
  27. GDB_UPLOAD_CMDS += $(GDB_UPLOAD_EXTRA_CMDS)
  28. GDB_UPLOAD_CMDS += -ex 'file $<'
  29. # $$pc is for $pc in gdb, but need to do this in makefile
  30. # please make sure the _start label is provided in your startup code
  31. # and is the entry of the startup of cpu
  32. # make sure pc is set to _start after load
  33. # when load program to flash, the cpu will do reset init
  34. # before flash erase and do reset halt after flash write end
  35. # so we need to manually set pc to _start
  36. # see https://openocd.org/doc/html/CPU-Configuration.html#Target-Events
  37. GDB_UPLOAD_CMDS += -ex 'thread apply all set $$pc=_start'
  38. GDB_UPLOAD_CMDS += -ex 'thread apply all info reg pc'
  39. GDB_UPLOAD_CMDS += -ex 'thread 1'
  40. GDB_UPLOAD_CMDS += -ex 'monitor resume'
  41. GDB_UPLOAD_CMDS += -ex 'quit'
  42. OPENOCD_PORT_ARGS = -c "$(OPENOCD_CMD_ARGS); gdb_port $(GDB_PORT)"
  43. OPENOCD_ARGS += $(OPENOCD_OPT) -f $(OPENOCD_CFG)
  44. GDB_CMDS += -ex "set remotetimeout 240"
  45. GDB_CMDS += -ex "target extended-remote localhost:$(GDB_PORT)"
  46. DOWNLOAD_UPPER = $(call uc, $(DOWNLOAD))
  47. DEFAULT_RISCV_ARCH ?= rv32imac
  48. DEFAULT_RISCV_ABI ?= ilp32
  49. ifeq ($(RISCV_ARCH),)
  50. $(warning RISCV_ARCH is not defined, use $(DEFAULT_RISCV_ARCH) as default)
  51. RISCV_ARCH := $(DEFAULT_RISCV_ARCH)
  52. endif
  53. ifeq ($(RISCV_ABI),)
  54. $(warning RISCV_ABI is not defined, use $(DEFAULT_RISCV_ABI) as default)
  55. RISCV_ABI := $(DEFAULT_RISCV_ABI)
  56. endif
  57. # Adjust CPU_SERIES according to passed CORE
  58. ifneq ($(findstring n100,$(CORE)),)
  59. # N100 with ECLIC enabled is supported in Nuclei SDK master/develop branch
  60. # N100 with IRQC enabled is supported in Nuclei N100 SDK master_n100/develop_n100 branch
  61. # N100 cycleh/timeh/instreth dont present
  62. $(warning You are choosing n100 series cpu on Nuclei SDK, please make sure your N100 CPU configured with ECLIC, see https://doc.nucleisys.com/nuclei_sdk/develop/buildsystem.html#n100-support-limitation)
  63. CPU_SERIES ?= 100
  64. # For N100, access must be strict alignment, unaligned access is not supported
  65. # So we must pass -mstrict-align, see https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html
  66. COMMON_FLAGS += -mstrict-align
  67. else ifneq ($(findstring 20,$(CORE)),)
  68. CPU_SERIES ?= 200
  69. else ifneq ($(findstring 30,$(CORE)),)
  70. CPU_SERIES ?= 300
  71. else ifneq ($(findstring 60,$(CORE)),)
  72. CPU_SERIES ?= 600
  73. else ifneq ($(findstring 90,$(CORE)),)
  74. CPU_SERIES ?= 900
  75. else ifneq ($(findstring 1000,$(CORE)),)
  76. CPU_SERIES ?= 1000
  77. LDSPEC_EN := 1
  78. else
  79. CPU_SERIES ?= 0
  80. endif
  81. # Set default RISC_CMODEL=medlow for rv32, otherwise medany
  82. ifeq ($(RISCV_CMODEL),)
  83. ifneq ($(findstring 32,$(RISCV_ABI)),)
  84. override RISCV_CMODEL := medlow
  85. else
  86. override RISCV_CMODEL := medany
  87. endif
  88. endif
  89. XLSPIKE := xl_spike
  90. XLMODEL := xl_cpumodel
  91. # QEMU settings
  92. ifneq ($(findstring 32,$(RISCV_ABI)),)
  93. QEMU := qemu-system-riscv32
  94. else
  95. QEMU := qemu-system-riscv64
  96. endif
  97. ## QEMU/XLSPIKE options
  98. QEMU_OPT += -icount shift=0
  99. # Include RTOS and Components Makefiles
  100. include $(NUCLEI_SDK_BUILD)/Makefile.rtos
  101. include $(NUCLEI_SDK_BUILD)/Makefile.components
  102. XLSPIKE_ARCH ?= $(RISCV_ARCH)
  103. MKDEP_OPT = -MMD -MT $@ -MF $@.d
  104. C_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(C_INCDIRS)),-I$(dir))
  105. CXX_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(CXX_INCDIRS)),-I$(dir))
  106. ASM_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(ASM_INCDIRS)),-I$(dir))
  107. ifeq ($(NOGC),1)
  108. GC_CFLAGS =
  109. GC_LDFLAGS =
  110. else
  111. GC_CFLAGS = -ffunction-sections -fdata-sections
  112. GC_LDFLAGS = -Wl,--gc-sections -Wl,--check-sections
  113. endif
  114. ifeq ($(SIMULATION),1)
  115. COMMON_FLAGS += -DCFG_SIMULATION
  116. endif
  117. ifeq ($(BANNER),0)
  118. COMMON_FLAGS += -DNUCLEI_BANNER=0
  119. endif
  120. include $(NUCLEI_SDK_BUILD)/Makefile.toolchain
  121. COMMON_FLAGS += -g -fno-common
  122. # For Nuclei N200/NS200 series CPU, unaligned access feature is configurable, if this feature is not enabled
  123. # then unaligned access is not supported, so we must pass -mstrict-align, see https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html
  124. #COMMON_FLAGS += -mstrict-align
  125. # Recommend to disable strict aliasing to avoid unexpected optimization, linux enabled it https://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg01647.html
  126. #COMMON_FLAGS += -fno-strict-aliasing
  127. COMMON_FLAGS += $(APP_COMMON_FLAGS) $(GC_CFLAGS) \
  128. -DDOWNLOAD_MODE=DOWNLOAD_MODE_$(DOWNLOAD_UPPER) \
  129. -DDOWNLOAD_MODE_STRING=\"$(DOWNLOAD_UPPER)\" \
  130. -DCPU_SERIES=$(CPU_SERIES)
  131. CFLAGS += $(COMMON_FLAGS) $(APP_CFLAGS) $(C_INCLUDE_OPT)
  132. CXXFLAGS += $(COMMON_FLAGS) $(APP_CXXFLAGS) $(CXX_INCLUDE_OPT)
  133. ASMFLAGS += -x assembler-with-cpp $(COMMON_FLAGS) $(APP_ASMFLAGS) $(ASM_INCLUDE_OPT)
  134. LIB_OPT = $(addprefix -L, $(sort $(LIBDIRS)))
  135. # filter out -lm library when using libncrt library
  136. # since libncrt also provided math library feature
  137. # it is used to avoid issue like undefined reference to `__errno'`
  138. ifneq ($(findstring libncrt,$(STDCLIB)),)
  139. LDLIBS := $(filter-out -lm,$(LDLIBS))
  140. endif
  141. LDFLAGS += -T $(LINKER_SCRIPT) -nostartfiles -Wl,-Map=$(TARGET).map \
  142. $(APP_LDFLAGS) $(GC_LDFLAGS) $(STDCLIB_LDFLAGS) \
  143. $(LIB_OPT) -Wl,--start-group $(LDLIBS) -Wl,--end-group
  144. # Prerequesties
  145. MAKEFILE_PREREQS += $(wildcard $(NUCLEI_SDK_BUILD)/Makefile.*)
  146. MAKEFILE_PREREQS += $(EXTRA_MKS)
  147. MAKEFILE_PREREQS += $(wildcard makefile Makefile *.mk)
  148. LINK_PREREQS += $(LINKER_SCRIPT)
  149. COMMON_PREREQS = $(MAKEFILE_PREREQS) $(LINK_PREREQS)