Makefile.conf 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 20,$(CORE)),)
  59. CPU_SERIES ?= 200
  60. else ifneq ($(findstring 30,$(CORE)),)
  61. CPU_SERIES ?= 300
  62. else ifneq ($(findstring 60,$(CORE)),)
  63. CPU_SERIES ?= 600
  64. else ifneq ($(findstring 90,$(CORE)),)
  65. CPU_SERIES ?= 900
  66. else ifneq ($(findstring 100,$(CORE)),)
  67. CPU_SERIES ?= 1000
  68. LDSPEC_EN := 1
  69. else
  70. CPU_SERIES ?= 0
  71. endif
  72. # Set default RISC_CMODEL=medlow for rv32, otherwise medany
  73. ifeq ($(RISCV_CMODEL),)
  74. ifneq ($(findstring 32,$(RISCV_ABI)),)
  75. override RISCV_CMODEL := medlow
  76. else
  77. override RISCV_CMODEL := medany
  78. endif
  79. endif
  80. XLSPIKE := xl_spike
  81. # QEMU settings
  82. ifneq ($(findstring 32,$(RISCV_ABI)),)
  83. QEMU := qemu-system-riscv32
  84. else
  85. QEMU := qemu-system-riscv64
  86. endif
  87. ## QEMU/XLSPIKE options
  88. QEMU_OPT += -icount shift=0
  89. # Include RTOS and Components Makefiles
  90. include $(NUCLEI_SDK_BUILD)/Makefile.rtos
  91. include $(NUCLEI_SDK_BUILD)/Makefile.components
  92. XLSPIKE_ARCH ?= $(RISCV_ARCH)
  93. MKDEP_OPT = -MMD -MT $@ -MF $@.d
  94. C_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(C_INCDIRS)),-I$(dir))
  95. CXX_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(CXX_INCDIRS)),-I$(dir))
  96. ASM_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(ASM_INCDIRS)),-I$(dir))
  97. ifeq ($(NOGC),1)
  98. GC_CFLAGS =
  99. GC_LDFLAGS =
  100. else
  101. GC_CFLAGS = -ffunction-sections -fdata-sections
  102. GC_LDFLAGS = -Wl,--gc-sections -Wl,--check-sections
  103. endif
  104. ifeq ($(SIMULATION),1)
  105. COMMON_FLAGS += -DCFG_SIMULATION
  106. endif
  107. ifeq ($(BANNER),0)
  108. COMMON_FLAGS += -DNUCLEI_BANNER=0
  109. endif
  110. include $(NUCLEI_SDK_BUILD)/Makefile.toolchain
  111. COMMON_FLAGS += -g -fno-common
  112. # For Nuclei N200/NS200 series CPU, unaligned access feature is configurable, if this feature is not enabled
  113. # then unaligned access is not supported, so we must pass -mstrict-align, see https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html
  114. #COMMON_FLAGS += -mstrict-align
  115. # Recommend to disable strict aliasing to avoid unexpected optimization, linux enabled it https://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg01647.html
  116. #COMMON_FLAGS += -fno-strict-aliasing
  117. COMMON_FLAGS += $(APP_COMMON_FLAGS) $(GC_CFLAGS) \
  118. -DDOWNLOAD_MODE=DOWNLOAD_MODE_$(DOWNLOAD_UPPER) \
  119. -DDOWNLOAD_MODE_STRING=\"$(DOWNLOAD_UPPER)\" \
  120. -DCPU_SERIES=$(CPU_SERIES)
  121. CFLAGS += $(COMMON_FLAGS) $(APP_CFLAGS) $(C_INCLUDE_OPT)
  122. CXXFLAGS += $(COMMON_FLAGS) $(APP_CXXFLAGS) $(CXX_INCLUDE_OPT)
  123. ASMFLAGS += -x assembler-with-cpp $(COMMON_FLAGS) $(APP_ASMFLAGS) $(ASM_INCLUDE_OPT)
  124. LIB_OPT = $(addprefix -L, $(sort $(LIBDIRS)))
  125. # filter out -lm library when using libncrt library
  126. # since libncrt also provided math library feature
  127. # it is used to avoid issue like undefined reference to `__errno'`
  128. ifneq ($(findstring libncrt,$(STDCLIB)),)
  129. LDLIBS := $(filter-out -lm,$(LDLIBS))
  130. endif
  131. LDFLAGS += -T $(LINKER_SCRIPT) -nostartfiles -Wl,-Map=$(TARGET).map \
  132. $(APP_LDFLAGS) $(GC_LDFLAGS) $(STDCLIB_LDFLAGS) \
  133. $(LIB_OPT) -Wl,--start-group $(LDLIBS) -Wl,--end-group
  134. # Prerequesties
  135. MAKEFILE_PREREQS += $(wildcard $(NUCLEI_SDK_BUILD)/Makefile.*)
  136. MAKEFILE_PREREQS += $(EXTRA_MKS)
  137. MAKEFILE_PREREQS += $(wildcard makefile Makefile *.mk)
  138. LINK_PREREQS += $(LINKER_SCRIPT)
  139. COMMON_PREREQS = $(MAKEFILE_PREREQS) $(LINK_PREREQS)