## NUCLEI RISCV GCC COMPILER ## NUCLEI RISCV OPENOCD # #!< Nuclei SDK Tools Root COMPILE_PREFIX ?= riscv-nuclei-elf- NUCLEI_SDK_TOOL_ROOT ?= $(NUCLEI_SDK_ROOT)/prebuilt_tools NUCLEI_RISCV_GCC_ROOT ?= $(NUCLEI_SDK_TOOL_ROOT)/gcc NUCLEI_OPENOCD_ROOT ?= $(NUCLEI_SDK_TOOL_ROOT)/openocd NUCLEI_SDK_TOOL_ROOT_EXIST = 0 ifneq ($(wildcard $(NUCLEI_RISCV_GCC_ROOT)),) ifneq ($(wildcard $(NUCLEI_OPENOCD_ROOT)),) NUCLEI_SDK_TOOL_ROOT_EXIST = 1 endif endif ifeq ($(NUCLEI_SDK_TOOL_ROOT_EXIST),1) CC := $(abspath $(NUCLEI_RISCV_GCC_ROOT)/bin/$(COMPILE_PREFIX)gcc) CXX := $(abspath $(NUCLEI_RISCV_GCC_ROOT)/bin/$(COMPILE_PREFIX)g++) OBJDUMP := $(abspath $(NUCLEI_RISCV_GCC_ROOT)/bin/$(COMPILE_PREFIX)objdump) OBJCOPY := $(abspath $(NUCLEI_RISCV_GCC_ROOT)/bin/$(COMPILE_PREFIX)objcopy) GDB := $(abspath $(NUCLEI_RISCV_GCC_ROOT)/bin/$(COMPILE_PREFIX)gdb) AR := $(abspath $(NUCLEI_RISCV_GCC_ROOT)/bin/$(COMPILE_PREFIX)ar) SIZE := $(abspath $(NUCLEI_RISCV_GCC_ROOT)/bin/$(COMPILE_PREFIX)size) OPENOCD := $(abspath $(NUCLEI_OPENOCD_ROOT)/bin/openocd) else CC := $(COMPILE_PREFIX)gcc CXX := $(COMPILE_PREFIX)g++ OBJDUMP := $(COMPILE_PREFIX)objdump OBJCOPY := $(COMPILE_PREFIX)objcopy GDB := $(COMPILE_PREFIX)gdb AR := $(COMPILE_PREFIX)ar SIZE := $(COMPILE_PREFIX)size OPENOCD := openocd endif include $(NUCLEI_SDK_BUILD)/Makefile.soc # Set your GDB port using variable GDB_PORT GDB_PORT ?= 3333 ## Makefile Variable GDBREMOTE # You can change GDBREMOTE to other gdb remotes ## eg. if you have started openocd server with (bindto 0.0.0.0 defined in openocd.cfg) ## make sure your machine can connect to remote machine ## in remote machine(ipaddr 192.168.43.199, port 3333) which connect the hardware board, ## then you can change the GDBREMOTE to 192.168.43.199:3333 ## GDBREMOTE ?= 192.168.43.199:3333 GDBREMOTE ?= | $(OPENOCD) -c \"gdb_port pipe; log_output openocd.log\" -f $(OPENOCD_CFG) GDB_UPLOAD_ARGS ?= --batch GDB_UPLOAD_CMDS += -ex "monitor halt" GDB_UPLOAD_CMDS += -ex "load" GDB_UPLOAD_CMDS += -ex "monitor resume" GDB_UPLOAD_CMDS += -ex "quit" OPENOCD_PORT_ARGS = -c "gdb_port $(GDB_PORT)" OPENOCD_ARGS += -f $(OPENOCD_CFG) GDB_CMDS += -ex "set remotetimeout 240" GDB_CMDS += -ex "target extended-remote localhost:$(GDB_PORT)" SUPPORT_DOWNLOAD_MODES=flash flashxip ilm ddr DOWNLOAD_UPPER = $(call uc, $(DOWNLOAD)) SUPPORT_DOWNLOAD_MODES_UPPER=$(call uc, $(SUPPORT_DOWNLOAD_MODES)) VALID_DOWNLOAD = $(call check_item_exist, $(DOWNLOAD_UPPER), $(SUPPORT_DOWNLOAD_MODES_UPPER)) include $(NUCLEI_SDK_BUILD)/Makefile.files include $(NUCLEI_SDK_BUILD)/Makefile.rtos ifeq ($(VALID_DOWNLOAD),) $(error Download mode $(DOWNLOAD) is not supported, support modes: $(SUPPORT_DOWNLOAD_MODES)) endif DEFAULT_RISCV_ARCH ?= rv32imac DEFAULT_RISCV_ABI ?= ilp32 ifeq ($(RISCV_ARCH),) $(warning RISCV_ARCH is not defined, use $(DEFAULT_RISCV_ARCH) as default) RISCV_ARCH := $(DEFAULT_RISCV_ARCH) endif ifeq ($(RISCV_ABI),) $(warning RISCV_ABI is not defined, use $(DEFAULT_RISCV_ABI) as default) RISCV_ABI := $(DEFAULT_RISCV_ABI) endif MKDEP_OPT = -MMD -MT $@ -MF $@.d C_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(C_INCDIRS)),-I$(dir)) CXX_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(CXX_INCDIRS)),-I$(dir)) ASM_INCLUDE_OPT = $(foreach dir,$(sort $(INCDIRS) $(ASM_INCDIRS)),-I$(dir)) ifeq ($(NOGC),1) GC_CFLAGS = GC_LDFLAGS = else GC_CFLAGS = -ffunction-sections -fdata-sections GC_LDFLAGS = -Wl,--gc-sections -Wl,--check-sections endif ifeq ($(SIMULATION),1) COMMON_FLAGS += -DCFG_SIMULATION endif ifeq ($(NEWLIB),nano) NEWLIB_LDFLAGS = --specs=nano.specs ifeq ($(PFLOAT),1) NEWLIB_LDFLAGS += -u _printf_float endif else NEWLIB_LDFLAGS = endif ifeq ($(SIMU),xlspike) COMMON_FLAGS += -DSIMULATION_XLSPIKE endif COMMON_FLAGS += -g -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -mcmodel=medany \ $(GC_CFLAGS) -fno-common -DDOWNLOAD_MODE=DOWNLOAD_MODE_$(DOWNLOAD_UPPER) CFLAGS += $(COMMON_FLAGS) $(C_INCLUDE_OPT) $(MKDEP_OPT) CXXFLAGS += $(COMMON_FLAGS) $(CXX_INCLUDE_OPT) $(MKDEP_OPT) ASMFLAGS += $(COMMON_FLAGS) $(ASM_INCLUDE_OPT) $(MKDEP_OPT) LIB_OPT = $(addprefix -L, $(sort $(LIBDIRS))) LDFLAGS += -T $(LINKER_SCRIPT) -lstdc++ -nostartfiles -Wl,-M,-Map=$(TARGET).map \ $(GC_LDFLAGS) $(NEWLIB_LDFLAGS) --specs=nosys.specs \ $(LIB_OPT) $(LDLIBS) # More options needed by -flto, if not passed, will fail in linking phase LDFLAGS += -u _isatty -u _write -u _sbrk -u _read -u _close -u _fstat -u _lseek # Prerequesties MAKEFILE_PREREQS += $(NUCLEI_SDK_BUILD)/Makefile.base MAKEFILE_PREREQS += $(NUCLEI_SDK_BUILD)/Makefile.soc MAKEFILE_PREREQS += $(NUCLEI_SDK_BUILD)/Makefile.soc.$(SOC) MAKEFILE_PREREQS += $(NUCLEI_SDK_BUILD)/Makefile.conf MAKEFILE_PREREQS += $(NUCLEI_SDK_BUILD)/Makefile.core MAKEFILE_PREREQS += $(NUCLEI_SDK_BUILD)/Makefile.files MAKEFILE_PREREQS += $(NUCLEI_SDK_BUILD)/Makefile.files.$(SOC) MAKEFILE_PREREQS += $(NUCLEI_SDK_BUILD)/Makefile.misc MAKEFILE_PREREQS += $(NUCLEI_SDK_BUILD)/Makefile.rules MAKEFILE_PREREQS += $(EXTRA_MKS) MAKEFILE_PREREQS += Makefile LINK_PREREQS += $(LINKER_SCRIPT) COMMON_PREREQS = $(MAKEFILE_PREREQS) $(LINK_PREREQS)