From 15d7e8b80192d8e965865e7da353b23916c5987e Mon Sep 17 00:00:00 2001 From: Joppe Blondel Date: Thu, 8 Sep 2022 13:58:03 +0200 Subject: [PATCH] Added gcc make toolchain for remote compilation Signed-off-by: Joppe Blondel --- examples/zynq7000/SW/Makefile | 11 ++++---- examples/zynq7000/SW/src/boot.S | 9 ++++++ examples/zynq7000/SW/src/main.c | 1 + examples/zynq7000/project.cfg | 24 ++++++++++++++++ remotesyn/toolchains/gccmake.py | 49 +++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 remotesyn/toolchains/gccmake.py diff --git a/examples/zynq7000/SW/Makefile b/examples/zynq7000/SW/Makefile index 7b50bf5..e579c28 100644 --- a/examples/zynq7000/SW/Makefile +++ b/examples/zynq7000/SW/Makefile @@ -2,9 +2,10 @@ TARGET := app.elf +BUILDROOT ?= $(shell pwd) BUILDDIR := build -SRCDIRS := src +SRCDIRS := $(BUILDROOT)/src SRCFILESC := $(shell find $(SRCDIRS) -type f -name "*.c") OBJFILESC := $(SRCFILESC:%.c=$(BUILDDIR)/%.c.o) $(BUILDDIR)/src/ps7_init.o DEPFILESC := $(SRCFILESC:%.c=$(BUILDDIR)/%.c.d) @@ -25,8 +26,8 @@ LD := $(CROSS_COMPILE)gcc CC_WARNING := -Wall -Wextra CC_LIBS := -lgcc CC_FLAGS := -nostdlib -fno-builtin -g -mcpu=cortex-a9 -CC_INCLUDES := -I src -I ../OUT/ip/zynqps -LD_FLAGS := -Wl,-Tlinker.ld +CC_INCLUDES := -I $(BUILDROOT)/src -I $(BUILDROOT)/../OUT/ip/zynqps +LD_FLAGS := -Wl,-T$(BUILDROOT)/linker.ld .PHONY: $(TARGET) all clean all: $(TARGET) @@ -48,10 +49,10 @@ $(BUILDDIR)/$(TARGET): $(OBJFILES) $(LD) $(CC_FLAGS) $(LD_FLAGS) -o $(BUILDDIR)/$(TARGET) $(OBJFILES) $(CC_LIBS) $(XILINX_BASE)/bin/$(CROSS_COMPILE)objdump -D $(BUILDDIR)/$(TARGET) > DISASS -$(BUILDDIR)/src/ps7_init.o : ../OUT/ip/zynqps/ps7_init.c ../OUT/ip/zynqps/ps7_init.h +$(BUILDDIR)/src/ps7_init.o : $(BUILDROOT)/../OUT/ip/zynqps/ps7_init.c $(BUILDROOT)/../OUT/ip/zynqps/ps7_init.h echo 'CC ' $@ -mkdir -p $(shell dirname $@) - $(CC) $(CC_FLAGS) $(CC_WARNING) $(CC_INCLUDES) -MD -o $(BUILDDIR)/src/ps7_init.o -c ../OUT/ip/zynqps/ps7_init.c + $(CC) $(CC_FLAGS) $(CC_WARNING) $(CC_INCLUDES) -MD -o $(BUILDDIR)/src/ps7_init.o -c $(BUILDROOT)/../OUT/ip/zynqps/ps7_init.c $(OBJFILES): $(BUILDDIR)/%.c.o: %.c echo 'CC ' $@ diff --git a/examples/zynq7000/SW/src/boot.S b/examples/zynq7000/SW/src/boot.S index 919c999..1398935 100644 --- a/examples/zynq7000/SW/src/boot.S +++ b/examples/zynq7000/SW/src/boot.S @@ -75,6 +75,15 @@ _start: ldr sp, =__proc0_svc_stack /* load SVC mode stack pointer */ /* We are now in SVC mode */ + // Disable L1 cache + mov r0, #0 + mcr p15, 0, r0, c7, c7, 0 // Invalidate cache + mcr p15, 0, r0, c8, c7, 0 // Invalidate tlb + mrc p15, 0, r0, c1, c0, 0 + bic r0, r0, #0x1000 + bic r0, r0, #0x0004 + mcr p15, 0, r0, c1, c0, 0 + /* Set vector table base address */ ldr r0, =vectortable mcr p15, #0, r0, c12, c0, #0 diff --git a/examples/zynq7000/SW/src/main.c b/examples/zynq7000/SW/src/main.c index 0f36916..84a2411 100644 --- a/examples/zynq7000/SW/src/main.c +++ b/examples/zynq7000/SW/src/main.c @@ -12,4 +12,5 @@ void main(){ printf("Hello World!\n"); + for(;;); } \ No newline at end of file diff --git a/examples/zynq7000/project.cfg b/examples/zynq7000/project.cfg index a0e396b..b7e2670 100644 --- a/examples/zynq7000/project.cfg +++ b/examples/zynq7000/project.cfg @@ -90,4 +90,28 @@ files_verilog = OUT/synth/impl_netlist.v #files_sysverilog = #files_xci = files_other = OUT/synth/impl_netlist.sdf +# ###################################### + +# ###################################### +# Firmware compilation +[target.firmware] +toolchain = gccmake + +# Toolchain settings +output_files = build/app.elf DISASS +buildroot = SW + +# Fileset +files_makefile = SW/Makefile +files_other = SW/linker.ld + SW/src/boot.S + SW/src/main.c + SW/src/printf.c + SW/src/printf.h + SW/src/uart.c + SW/src/uart.h + SW/src/xil_io.h + SW/src/zynq.h + OUT/ip/zynqps/ps7_init.c + OUT/ip/zynqps/ps7_init.h # ###################################### \ No newline at end of file diff --git a/remotesyn/toolchains/gccmake.py b/remotesyn/toolchains/gccmake.py new file mode 100644 index 0000000..fd136d8 --- /dev/null +++ b/remotesyn/toolchains/gccmake.py @@ -0,0 +1,49 @@ +import shutil +import os +import time +import subprocess + +def do(config, target, log, subprocesses, prefix='.'): + shutil.rmtree(config.get('project', 'build_dir', fallback='build'), True) + + log("Starting gcc-make build process") + + log(" - parsing options") + files_makefile = config.get(f'target.{target}', 'files_makefile', fallback='') + buildroot = config.get(f'target.{target}', 'buildroot', fallback='.') + output_files = config.get(f'target.{target}', 'output_files', fallback='').split() + build_dir = config.get(f'project', 'build_dir', fallback='build') + out_dir = config.get(f'project', 'out_dir', fallback='out') + + prefix = f'{os.getcwd()}/{prefix}' + build_dir = f'{prefix}/{build_dir}' + out_dir = f'{prefix}/{out_dir}/{target}' + + log(" - creating output directories") + os.makedirs(build_dir, exist_ok=True) + os.makedirs(out_dir, exist_ok=True) + + log(" - Copy makefile to build directory") + shutil.copy(f"{prefix}/{files_makefile}", f"{build_dir}/Makefile") + + log(" - run make") + p = subprocess.Popen(f"BUILDROOT={prefix}/{buildroot} make 2>make.log", + shell=True, cwd=build_dir, + stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + subprocesses.append(p) + while p.poll() is None: + time.sleep(1) + res = p.returncode + + log(" - copy logs") + shutil.copy(f'{build_dir}/make.log', f'{out_dir}/make.log') + + if res!=0: + log("ERROR: make returned with:", res) + return res + + log(" - copy output files") + for f in output_files: + shutil.copy(f'{build_dir}/{f}', f'{out_dir}/{os.path.basename(f)}') + + return 0 \ No newline at end of file