Makefile.conf 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 += -ex 'file $<'
  28. # $$pc is for $pc in gdb, but need to do this in makefile
  29. # please make sure the _start label is provided in your startup code
  30. # and is the entry of the startup of cpu
  31. # make sure pc is set to _start after load
  32. # when load program to flash, the cpu will do reset init
  33. # before flash erase and do reset halt after flash write end
  34. # so we need to manually set pc to _start
  35. # see https://openocd.org/doc/html/CPU-Configuration.html#Target-Events
  36. GDB_UPLOAD_CMDS += -ex 'thread apply all set $$pc=_start'
  37. GDB_UPLOAD_CMDS += -ex 'thread apply all info reg pc'
  38. GDB_UPLOAD_CMDS += -ex 'thread 1'
  39. GDB_UPLOAD_CMDS += -ex 'monitor resume'
  40. GDB_UPLOAD_CMDS += -ex 'quit'
  41. OPENOCD_PORT_ARGS = -c "$(OPENOCD_CMD_ARGS); gdb_port $(GDB_PORT)"
  42. OPENOCD_ARGS += $(OPENOCD_OPT) -f $(OPENOCD_CFG)
  43. GDB_CMDS += -ex "set remotetimeout 240"
  44. GDB_CMDS += -ex "target extended-remote localhost:$(GDB_PORT)"
  45. DOWNLOAD_UPPER = $(call uc, $(DOWNLOAD))
  46. DEFAULT_RISCV_ARCH ?= rv32imac
  47. DEFAULT_RISCV_ABI ?= ilp32
  48. ifeq ($(RISCV_ARCH),)
  49. $(warning RISCV_ARCH is not defined, use $(DEFAULT_RISCV_ARCH) as default)
  50. RISCV_ARCH := $(DEFAULT_RISCV_ARCH)
  51. endif
  52. ifeq ($(RISCV_ABI),)
  53. $(warning RISCV_ABI is not defined, use $(DEFAULT_RISCV_ABI) as default)
  54. RISCV_ABI := $(DEFAULT_RISCV_ABI)
  55. endif
  56. # Adjust CPU_SERIES according to passed CORE
  57. ifneq ($(findstring 10,$(CORE)),)
  58. CPU_SERIES ?= 100
  59. else ifneq ($(findstring 20,$(CORE)),)
  60. CPU_SERIES ?= 200
  61. else ifneq ($(findstring 30,$(CORE)),)
  62. CPU_SERIES ?= 300
  63. else ifneq ($(findstring 60,$(CORE)),)
  64. CPU_SERIES ?= 600
  65. else ifneq ($(findstring 90,$(CORE)),)
  66. CPU_SERIES ?= 900
  67. else
  68. CPU_SERIES ?= 0
  69. endif
  70. # Set default RISC_CMODEL=medlow for rv32, otherwise medany
  71. ifeq ($(RISCV_CMODEL),)
  72. ifneq ($(findstring 32,$(RISCV_ABI)),)
  73. override RISCV_CMODEL := medlow
  74. else
  75. override RISCV_CMODEL := medany
  76. endif
  77. endif
  78. XLSPIKE := xl_spike
  79. # QEMU settings
  80. ifneq ($(findstring 32,$(RISCV_ABI)),)
  81. QEMU := qemu-system-riscv32
  82. else
  83. QEMU := qemu-system-riscv64
  84. endif
  85. ## QEMU/XLSPIKE options
  86. QEMU_OPT += -icount shift=0
  87. # Include RTOS and Components Makefiles
  88. include $(NUCLEI_SDK_BUILD)/Makefile.rtos
  89. include $(NUCLEI_SDK_BUILD)/Makefile.components
  90. XLSPIKE_ARCH ?= $(RISCV_ARCH)
  91. MKDEP_OPT = -MMD -MT $@ -MF $@.d
  92. C_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(C_INCDIRS)),-I$(dir))
  93. CXX_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(CXX_INCDIRS)),-I$(dir))
  94. ASM_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(ASM_INCDIRS)),-I$(dir))
  95. ifeq ($(NOGC),1)
  96. GC_CFLAGS =
  97. GC_LDFLAGS =
  98. else
  99. GC_CFLAGS = -ffunction-sections -fdata-sections
  100. GC_LDFLAGS = -Wl,--gc-sections -Wl,--check-sections
  101. endif
  102. ifeq ($(SIMULATION),1)
  103. COMMON_FLAGS += -DCFG_SIMULATION
  104. endif
  105. ifeq ($(BANNER),0)
  106. COMMON_FLAGS += -DNUCLEI_BANNER=0
  107. endif
  108. include $(NUCLEI_SDK_BUILD)/Makefile.toolchain
  109. # For N100, access must be strict alignment, unaligned access is not supported
  110. # So we must pass -mstrict-align, see https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html
  111. COMMON_FLAGS += -g -fno-common -mstrict-align
  112. COMMON_FLAGS += $(APP_COMMON_FLAGS) $(GC_CFLAGS) \
  113. -DDOWNLOAD_MODE=DOWNLOAD_MODE_$(DOWNLOAD_UPPER) \
  114. -DDOWNLOAD_MODE_STRING=\"$(DOWNLOAD_UPPER)\" \
  115. -DCPU_SERIES=$(CPU_SERIES)
  116. CFLAGS += $(COMMON_FLAGS) $(APP_CFLAGS) $(C_INCLUDE_OPT)
  117. CXXFLAGS += $(COMMON_FLAGS) $(APP_CXXFLAGS) $(CXX_INCLUDE_OPT)
  118. ASMFLAGS += -x assembler-with-cpp $(COMMON_FLAGS) $(APP_ASMFLAGS) $(ASM_INCLUDE_OPT)
  119. LIB_OPT = $(addprefix -L, $(sort $(LIBDIRS)))
  120. # filter out -lm library when using libncrt library
  121. # since libncrt also provided math library feature
  122. # it is used to avoid issue like undefined reference to `__errno'`
  123. ifneq ($(findstring libncrt,$(STDCLIB)),)
  124. LDLIBS := $(filter-out -lm,$(LDLIBS))
  125. endif
  126. LDFLAGS += -T $(LINKER_SCRIPT) -nostartfiles -Wl,-Map=$(TARGET).map \
  127. $(APP_LDFLAGS) $(GC_LDFLAGS) $(STDCLIB_LDFLAGS) \
  128. $(LIB_OPT) -Wl,--start-group $(LDLIBS) -Wl,--end-group
  129. # Prerequesties
  130. MAKEFILE_PREREQS += $(wildcard $(NUCLEI_SDK_BUILD)/Makefile.*)
  131. MAKEFILE_PREREQS += $(EXTRA_MKS)
  132. MAKEFILE_PREREQS += $(wildcard makefile Makefile *.mk)
  133. LINK_PREREQS += $(LINKER_SCRIPT)
  134. COMMON_PREREQS = $(MAKEFILE_PREREQS) $(LINK_PREREQS)