Commit 988914c1 authored by Federico Vaga's avatar Federico Vaga

sw:fw: improve building system

Introducing TBuild file to set building variables
Compilation happens in MockTurtle building system, and not
by including it in the local project

cd /path/to/firmware
make -C /path/to/mockturtle/software/firmware M=$PWD
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent f3435ff6
OBJS = fw-ac.o
OBJS += # add other object files that you need
OUTPUT = fw-ac
TRTL ?= ../../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = fw-ac.o
OBJS += # add other object files that you need
OUTPUT = fw-ac
OBJS = fw-dg.o
OBJS += # add other object files that you need
OUTPUT = fw-dg
TRTL ?= ../../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = fw-dg.o
OBJS += # add other object files that you need
OUTPUT = fw-dg
include ../../../project.mk
OBJS = fw-spec.o
OBJS += common/fw-spec-smem-code.o
OBJDIR += common
OUTPUT = fw-spec-1
TRTL ?= ../../../../../
TRTL_SW = $(TRTL)/software
EXTRA_CFLAGS += -I../../include
EXTRA_CFLAGS += -I../common
EXTRA_CFLAGS += -DFPGA_APPLICATION_ID=APPLICATION_ID
EXTRA_CFLAGS += -DRT_APPLICATION_ID=$(RT_APPLICATION_ID_CPU1)
vpath %.c ../
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
include $(src)/../../../project.mk
OBJS = fw-spec.o
OBJS += common/fw-spec-smem-code.o
OBJDIR += common
OUTPUT = fw-spec-1
EXTRA_CFLAGS += -I$(src)/../../include
EXTRA_CFLAGS += -I$(src)/../common
EXTRA_CFLAGS += -DFPGA_APPLICATION_ID=APPLICATION_ID
EXTRA_CFLAGS += -DRT_APPLICATION_ID=$(RT_APPLICATION_ID_CPU1)
vpath %.c $(src)../
include ../../../project.mk
OBJS = fw-spec.o
OBJS += common/fw-spec-smem-code.o
OBJDIR += common
OUTPUT = fw-spec-2
TRTL ?= ../../../../../
TRTL_SW = $(TRTL)/software
EXTRA_CFLAGS += -I../../include
EXTRA_CFLAGS += -I../common
EXTRA_CFLAGS += -DFPGA_APPLICATION_ID=$(APPLICATION_ID)
EXTRA_CFLAGS += -DRT_APPLICATION_ID=$(RT_APPLICATION_ID_CPU2)
EXTRA_CFLAGS += -DLIBRT_DEBUG_VERBOSE -DLIBRT_DEBUG
vpath %.c ../
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
include $(src)../../../project.mk
OBJS = fw-spec.o
OBJS += common/fw-spec-smem-code.o
OBJDIR += common
OUTPUT = fw-spec-2
EXTRA_CFLAGS += -I$(src)/../../include
EXTRA_CFLAGS += -I$(src)/../common
EXTRA_CFLAGS += -DFPGA_APPLICATION_ID=$(APPLICATION_ID)
EXTRA_CFLAGS += -DRT_APPLICATION_ID=$(RT_APPLICATION_ID_CPU2)
EXTRA_CFLAGS += -DLIBRT_DEBUG_VERBOSE -DLIBRT_DEBUG
vpath %.c $(src)/../
include ../../../project.mk
OBJS = fw-svec.o
OBJS += common/fw-svec-smem-code.o
OBJDIR += common
OUTPUT = fw-svec-1
TRTL ?= ../../../../../
TRTL_SW = $(TRTL)/software
EXTRA_CFLAGS += -I../../include
EXTRA_CFLAGS += -I../common
EXTRA_CFLAGS += -DFPGA_APPLICATION_ID=APPLICATION_ID
EXTRA_CFLAGS += -DRT_APPLICATION_ID=$(RT_APPLICATION_ID_CPU1)
vpath %.c ../
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
include $(src)/../../../project.mk
OBJS = fw-svec.o
OBJS += common/fw-svec-smem-code.o
OBJDIR += common
OUTPUT = fw-svec-1
EXTRA_CFLAGS += -I$(src)/../../include
EXTRA_CFLAGS += -I$(src)/../common
EXTRA_CFLAGS += -DFPGA_APPLICATION_ID=APPLICATION_ID
EXTRA_CFLAGS += -DRT_APPLICATION_ID=$(RT_APPLICATION_ID_CPU1)
vpath %.c $(src)/../
include ../../../project.mk
OBJS = fw-svec.o
OBJS += common/fw-svec-smem-code.o
OBJDIR += common
OUTPUT = fw-svec-2
TRTL ?= ../../../../../
TRTL_SW = $(TRTL)/software
EXTRA_CFLAGS += -I../../include
EXTRA_CFLAGS += -I../common
EXTRA_CFLAGS += -DFPGA_APPLICATION_ID=$(APPLICATION_ID)
EXTRA_CFLAGS += -DRT_APPLICATION_ID=$(RT_APPLICATION_ID_CPU2)
EXTRA_CFLAGS += -DLIBRT_DEBUG_VERBOSE -DLIBRT_DEBUG
vpath %.c ../
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
include $(src)/../../../project.mk
OBJS = fw-svec.o
OBJS += common/fw-svec-smem-code.o
OBJDIR += common
OUTPUT = fw-svec-2
EXTRA_CFLAGS += -I$(src)/../../include
EXTRA_CFLAGS += -I$(src)/../common
EXTRA_CFLAGS += -DFPGA_APPLICATION_ID=$(APPLICATION_ID)
EXTRA_CFLAGS += -DRT_APPLICATION_ID=$(RT_APPLICATION_ID_CPU2)
EXTRA_CFLAGS += -DLIBRT_DEBUG_VERBOSE -DLIBRT_DEBUG
vpath %.c $(src)/../
OBJS = fw-hello.o
OBJS += # add other object files that you need
OUTPUT = fw-hello
TRTL ?= ../../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = fw-hello.o
OBJS += # add other object files that you need
OUTPUT = fw-hello
OBJS = fw-hellofrm.o
OBJS += # add other object files that you need
OUTPUT = fw-hellofrm
TRTL ?= ../../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = fw-hellofrm.o
OBJS += # add other object files that you need
OUTPUT = fw-hellofrm
......@@ -43,11 +43,10 @@ memory) or you need much better performances: don't use this framework.
All the Mock Turtle firmware source code can be found in the directory
``/path/to/mockturtle/software/firmware/``.
Mock Turtle has a generic ``Makefile`` that you should include in your
``Makefile`` in order to import all the Mock Turtle building rules.::
TRTL ?= /path/to/mcokturtle/
TRTL_SW = $(TRTL)/software
Mock Turtle has a generic building system which can be used to produce
Mock Turtle firmware applications. What you have to do is to prepare a
file named ``TBuild`` next to your firmware source files. In this file
you have to specify what to build, for example::
# Mandatory
OBJS = source1.o
......@@ -56,15 +55,10 @@ Mock Turtle has a generic ``Makefile`` that you should include in your
OUTPUT = firmware-name
# Optional (prefer default when possible)
CFLAGS_OPT := -O1
CFLAGS_DBG := -ggdb
EXTRA_CFLGAS :=
EXTRA_CFLAGS :=
MOCKTURTLE_LDSCRIPT := myfirmware.ld
# INCLUDE GENERIC Makefile
include $(TRTL_SW)/firmware/Makefile
Here the list of supported Makefile environment variables
Here the list of supported TBuild variables
OBJS
(Mandatory) List of object files to generate from sources with
......@@ -74,10 +68,30 @@ OBJS
OUTPUT
(Mandatory) Final binary name (the firmware).
EXTRA_CFLAGS
(Optional) Additional compiler options.
MOCKTURTLE_LDSCRIPT
(Optional ) Local path to the linker script.
(Optional) Local path to the linker script.
The default is the standard Mock Turtle linker script.
You can build such firmware application by calling ``make`` from the
application directory (where the ``TBuild`` file is) like this::
make -C <path-to-mockturtle-project>/software/firmware M=$PWD
Or alternatively, you can copy the following lines in a Makefile::
TRTL_FW = $(TRTL)/software/firmware
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
Then, you will compile your application with the following command
from the application directory (where the ``TBuild`` file is)::
make TRTL=<path-to-mockturtle-project>
Memory resources on Mock Turtle are very limited and the full framework
may take more space than needed. For this reason Mock Turtle has
*Kconfig* support which allows you to interactivly enable/disable both
......
-include Makefile.specific
-include $(CURDIR)/.config
src := $(M)/
-include $(src)/Makefile.specific
-include $(src)/.config
include $(src)/TBuild
# Validation
ifndef OUTPUT
$(error Missing variable OUTPUT)
else
build_output=$(src)/$(OUTPUT)
endif
ifndef OBJS
......@@ -21,7 +27,7 @@ TRTL_HDL ?= $(TRTL)/hdl/rtl
RT_GIT_VERSION = 0x$(shell git rev-parse --short=8 HEAD || echo "0") # empty if git is not there
# header file generated from the .config
AUTOCONF = $(CURDIR)/$(BUILDDIR)/include/generated/autoconf.h
AUTOCONF = $(src)/$(BUILDDIR)/include/generated/autoconf.h
CROSS_COMPILE_TARGET ?= riscv32-elf-
# FIXME the mult/div is broken, for the time being remove it completely
......@@ -33,8 +39,10 @@ LDFLAGS += -lgcc -lc -Wl,--gc-sections
# provide search patch for sources
vpath %.c $(TRTL_FW)
vpath %.S $(TRTL_FW)
vpath %.c $(src)
vpath %.S $(src)
BUILDDIR := build
BUILDDIR := $(src)/build
# auto dependency generation from
# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
......@@ -90,7 +98,7 @@ MOCKTURTLE_LDSCRIPT ?= $(TRTL_FW)/urv/mockturtle.ld
.PHONY: all clean cleanall
all: $(OUTPUT).bin
all: $(build_output).bin
WBGEN_FILES = mt_cpu_csr.wb mt_cpu_lr.wb
WBGEN_HEADERS = mockturtle_cpu_csr.h mockturtle_cpu_lr.h
......@@ -115,12 +123,13 @@ $(OBJDIR_BUILD):
$(OBJS_BUILD): | $(AUTOCONF)
$(OBJS_BUILD): | $(OBJDIR_BUILD)
$(OUTPUT).elf: $(addprefix $(TRTL_SW)/include/hw/,$(WBGEN_HEADERS)) $(MOCKTURTLE_LDSCRIPT) $(OBJS_BUILD)
${CC} $(CFLAGS) $(LDFLAGS) -o $(OUTPUT).elf -nostartfiles $(OBJS_BUILD) -T $(MOCKTURTLE_LDSCRIPT)
$(build_output).elf: $(addprefix $(TRTL_SW)/include/hw/,$(WBGEN_HEADERS)) $(MOCKTURTLE_LDSCRIPT) $(OBJS_BUILD)
$(warning $(OBJS_BUILD))
${CC} $(CFLAGS) $(LDFLAGS) -o $(build_output).elf -nostartfiles $(OBJS_BUILD) -T $(MOCKTURTLE_LDSCRIPT)
$(OUTPUT).bin: $(OUTPUT).elf
${OBJCOPY} --remove-section .smem -O binary $(OUTPUT).elf $(OUTPUT).bin
$(SIZE) $(OUTPUT).elf
$(build_output).bin: $(build_output).elf
${OBJCOPY} --remove-section .smem -O binary $(build_output).elf $(build_output).bin
$(SIZE) $(build_output).elf
$(BUILDDIR)/urv/emulate.o: urv/emulate.c
${CC} $(DEPFLAGS) $(CFLAGS) -march=rv32i -c $< -o $@
......@@ -129,13 +138,15 @@ $(BUILDDIR)/urv/emulate.o: urv/emulate.c
$(BUILDDIR)/%.o: %.c
${CC} $(DEPFLAGS) $(CFLAGS) $(LDFLAGS) -c $< -o $@
$(POSTCOMPILE)
$(warning $< ---- $@)
@echo ""
$(BUILDDIR)/%.o: %.S
${CC} $(DEPFLAGS) $(CFLAGS) $(LDFLAGS) -c $< -o $@
$(POSTCOMPILE)
clean:
rm -f $(OUTPUT).bin $(OUTPUT).elf
rm -f $(build_output).bin $(build_output).elf
rm -rf $(BUILDDIR)
clean-dot-config:
......@@ -144,7 +155,7 @@ clean-dot-config:
cleanall: clean clean-dot-config
install:
@cp $(OUTPUT).bin $(INSTALL_PREFIX)
@cp $(build_output).bin $(INSTALL_PREFIX)
# inlude *.d files from the build directory
include $(wildcard $(patsubst %,%/.d/*.d,$(basename $(OBJDIR_BUILD))))
......@@ -153,20 +164,20 @@ include $(wildcard $(patsubst %,%/.d/*.d,$(basename $(OBJDIR_BUILD))))
# following targets from Makefile.kconfig
# this one is used to generate autoconf.h file
$(AUTOCONF) silentoldconfig: .config | $(BUILDDIR)
export KCONFIG_CONFIG=$(CURDIR)/.config; \
$(MAKE) quiet=quiet_ KBUILD_KCONFIG=$(CURDIR)/Kconfig projtree=$(CURDIR)/$(BUILDDIR) -C $(TRTL_FW) -f Makefile.kconfig silentoldconfig
export KCONFIG_CONFIG=$(src)/.config; \
$(MAKE) quiet=quiet_ KBUILD_KCONFIG=$(src)/Kconfig projtree=$(BUILDDIR) -C $(TRTL_FW) -f Makefile.kconfig silentoldconfig
scripts_basic config:
$(MAKE) quiet=quiet_ KBUILD_KCONFIG=$(CURDIR)/Kconfig projtree=$(CURDIR) -C $(TRTL_FW) -f Makefile.kconfig $@
$(MAKE) quiet=quiet_ KBUILD_KCONFIG=$(src)/Kconfig projtree=$(src) -C $(TRTL_FW) -f Makefile.kconfig $@
%config:
$(MAKE) quiet=quiet_ KBUILD_KCONFIG=$(CURDIR)/Kconfig projtree=$(CURDIR) -C $(TRTL_FW) -f Makefile.kconfig $@
$(MAKE) quiet=quiet_ KBUILD_KCONFIG=$(src)/Kconfig projtree=$(src) -C $(TRTL_FW) -f Makefile.kconfig $@
defconfig:
$(MAKE) quiet=quiet_ KBUILD_KCONFIG=$(CURDIR)/Kconfig projtree=$(CURDIR) -C $(TRTL_FW) -f Makefile.kconfig mt_defconfig
$(MAKE) quiet=quiet_ KBUILD_KCONFIG=$(src)/Kconfig projtree=$(src) -C $(TRTL_FW) -f Makefile.kconfig mt_defconfig
.config: ;
# Explicit rule for .config
# needed since -include XXX triggers build for XXX
$(CURDIR)/.config: ;
$(src)/.config: ;
OBJS = config_rom.o
OBJS += # add other object files that you need
OUTPUT = fw-config-rom
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = config_rom.o
OBJS += # add other object files that you need
OUTPUT = fw-config-rom
OBJS = byte-addressing.o
OBJS += # add other object files that you need
OUTPUT = fw-byte-addressing
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = byte-addressing.o
OBJS += # add other object files that you need
OUTPUT = fw-byte-addressing
OBJS = cpu-loop.o
OBJS += # add other object files that you need
OUTPUT = fw-loop
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = cpu-loop.o
OBJS += # add other object files that you need
OUTPUT = fw-loop
OBJS = notify.o
OBJS += # add other object files that you need
OUTPUT = fw-notify
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = notify.o
OBJS += # add other object files that you need
OUTPUT = fw-notify
OBJS = hmq-async-recv.o
OBJS += # add other object files that you need
OUTPUT = fw-hmq-async-recv
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = hmq-async-recv.o
OBJS += # add other object files that you need
OUTPUT = fw-hmq-async-recv
OBJS = hmq-async-send.o
OBJS += # add other object files that you need
OUTPUT = fw-hmq-async-send
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = hmq-async-send.o
OBJS += # add other object files that you need
OUTPUT = fw-hmq-async-send
OBJS = hmq-purge.o
OBJS += # add other object files that you need
OUTPUT = fw-hmq-purge
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = hmq-purge.o
OBJS += # add other object files that you need
OUTPUT = fw-hmq-purge
-include ../Makefile.specific
OBJS = rmq-udp-send.o
OBJS += # add other object files that you need
OUTPUT = fw-rmq-udp-send
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
CFLAGS_OPT = -O0 # disable optimization
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = rmq-udp-send.o
OBJS += # add other object files that you need
OUTPUT = fw-rmq-udp-send
CFLAGS_OPT = -O0 # disable optimization
OBJS = rt-frm.o
OBJS += # add other object files that you need
OUTPUT = fw-rt-frm
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = rt-frm.o
OBJS += # add other object files that you need
OUTPUT = fw-rt-frm
-include ../Makefile.specific
OBJS = serial.o
OBJS += # add other object files that you need
OUTPUT = fw-serial
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = serial.o
OBJS += # add other object files that you need
OUTPUT = fw-serial
OBJS = sim-verif.o
OBJS += # add other object files that you need
OUTPUT = sim-verif
TRTL ?= ../../../
TRTL_SW = $(TRTL)/software
TRTL_FW = $(TRTL)/software/firmware
include $(TRTL_SW)/firmware/Makefile
all clean:
$(MAKE) -C $(TRTL_FW) M=$(shell /bin/pwd) $@
OBJS = sim-verif.o
OBJS += # add other object files that you need
OUTPUT = sim-verif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment