Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update examples build system #186

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions examples/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Common makefile for GHDL synthesis

PLUGIN_LIB = ../../library

ifneq ($(VERILOG_FILES),)
MAYBE_READ_VERILOG = read_verilog $(VERILOG_FILES);
endif

# agnostic synthesis
%.json: $(VHDL_SYN_FILES)
$(YOSYS) -m $(GHDLSYNTH) -p \
"ghdl $(GHDL_FLAGS) $(GHDL_GENERICS) $^ -e $(TOPLEVEL); \
$(MAYBE_READ_VERILOG) \
synth_$(PLATFORM) \
-top $(TOPLEVEL)$(TOPLEVEL_PARAMETER) -json $@" 2>&1

# ECP pouting
%.config: %.json
$(NEXTPNR) --json $< --lpf $(LPF_DEF) \
--textcfg $@ $(NEXTPNR_FLAGS) --package $(PACKAGE)

# ECP packing
%.svf: %.config
$(ECPPACK) --svf $*.svf $< $@

# ICE routing
%.asc: %.json
$(NEXTPNR) --$(DEVICE) --json $< \
--package $(PACKAGE) --pcf $(PCF_DEF) \
--asc $@ $(NEXTPNR_FLAGS)

# ICE packing
%.bin: %.asc
$(ICEPACK) $< $@

ifeq ($(PLATFORM), ecp5)

# ECP5 bitstream target
bitstream: $(PROJ).svf

# ECP programming
prog: $(PROJ).svf
$(OPENOCD) -f $(OPENOCD_JTAG_CONFIG) -f $(OPENOCD_DEVICE_CONFIG) \
-c "transport select jtag; init; svf $<; exit"

else ifeq ($(PLATFORM), ice40)

# ICE bitstream target
bitstream: report $(PROJ).bin

# ICE programming
prog: $(PROJ).bin
$(ICEPROG) $<

# ICE timing report
report: $(PROJ).asc
$(ICETIME) -d $(DEVICE) -mtr $@.txt $<
endif

clean:
rm -rf ./*.json ./*.asc ./*.bin ./report.txt ./*.work-obj93.cf \
./*.work-obj08.cf ./*.config ./*.svf $(LOCAL_LIB)

all: bitstream

.PRECIOUS: %.json %.config
.PHONY: bitstream report clean all
.DEFAULT: all
17 changes: 0 additions & 17 deletions examples/docker.mk

This file was deleted.

50 changes: 22 additions & 28 deletions examples/ecp5_versa/Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,44 @@
LIB = ../../library

GHDL ?= ghdl
USE_DOCKER?=

GHDL_FLAGS = -Plib
PROJ ?= versa_ecp5_top
TOPLEVEL ?= versa_ecp5_top

CLK_FREQ = 25000000
VHDL_SYN_FILES = versa_ecp5_top.vhdl pll_mac.vhd
VHDL_SYN_FILES += soc_iomap_pkg.vhdl
VHDL_SYN_FILES += uart.vhdl uart_tx.vhdl uart_rx.vhdl fifobuf.vhdl

GHDL_GENERICS=-gCLK_FREQUENCY=$(CLK_FREQ)
LPF = versa_ecp5.lpf
LPF_DEF = versa_ecp5.lpf
PACKAGE = CABGA381

NEXTPNR_FLAGS = --um5g-45k --freq 100
NEXTPNR_FLAGS += --lpf-allow-unconstrained

OPENOCD_JTAG_CONFIG = ../../openocd/ecp5-versa.cfg
OPENOCD_DEVICE_CONFIG = ../../openocd/LFE5UM5G-45F.cfg

WORKDIR = work
# Files to synthesize:
VHDL_SYN_FILES = versa_ecp5_top.vhdl pll_mac.vhd
VHDL_SYN_FILES += soc_iomap_pkg.vhdl
VHDL_SYN_FILES += uart.vhdl uart_tx.vhdl uart_rx.vhdl fifobuf.vhdl
VERILOG_FILES = $(PLUGIN_LIB)/wrapper/primitives.v
VERILOG_FILES += $(PLUGIN_LIB)/wrapper/bram.v

TOPLEVEL = versa_ecp5_top
TOPLEVEL_PARAMETER =
GHDL_FLAGS = -Plib
PLATFORM = ecp5

VERILOG_FILES = $(LIB)/wrapper/primitives.v
VERILOG_FILES += $(LIB)/wrapper/bram.v
LOCAL_LIB=./lib

SVFFILE = versa_ecp5_top.svf
DEPENDENCIES = lib/ecp5um-std93.cf
include ../tools.mk
include ../common.mk

all: $(SVFFILE)
# this project requires verilog wrappers to enable vendor black-box components
# these are defined in project-root/library
# the following targets compile these wrappers into a project specific directory

include ../docker.mk
include ../ghdlsynth.mk
# NOTE: if you're using VHDL-2008 you MUST rename the file suffix to "-std08.cf"

lib:
mkdir $@

lib/ecp5um-std93.cf: $(LIB)/ecp5u/components.vhdl | lib
$(LOCAL_LIB)/ecp5um-std93.cf: $(PLUGIN_LIB)/ecp5u/components.vhdl | lib
$(GHDL) -i --workdir=$(dir $@) --work=ecp5um $<

DEPENDENCIES = $(LOCAL_LIB)/ecp5um-std93.cf
pll_mac.vhd: $(DEPENDENCIES)

prog: $(SVFFILE)
$(OPENOCD) -f $(OPENOCD_JTAG_CONFIG) -f $(OPENOCD_DEVICE_CONFIG) \
-c "transport select jtag; init; svf $<; exit"

clean:
rm -fr lib work *.json *.svf *.config *-report.txt
20 changes: 20 additions & 0 deletions examples/ice40hx8k/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

USE_DOCKER?=

PROJ ?= leds
TOPLEVEL ?= leds

VHDL_SYN_FILES = leds.vhdl

# choose one implementation
VHDL_SYN_FILES += spin1.vhdl
# VHDL_SYN_FILES += spin2.vhdl

PCF_DEF = pinmap.pcf
PACKAGE = ct256

PLATFORM = ice40
DEVICE = hx8k

include ../tools.mk
include ../common.mk
33 changes: 13 additions & 20 deletions examples/icestick/leds/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
PROJ = blink

USE_DOCKER?=

# choose one project to build
PROJ ?= blink
#PROJ = fixed1
#PROJ = multi1
#PROJ = multi2
Expand All @@ -9,26 +13,15 @@ PROJ = blink
#PROJ = spin1
#PROJ = spin2

PIN_DEF = leds.pcf
DEVICE = hx1k

all: $(PROJ).bin
TOPLEVEL ?= leds

%.json: leds.vhdl %.vhdl
yosys -m ghdl -p 'ghdl $^ -e leds; synth_ice40 -json $@'
VHDL_SYN_FILES = leds.vhdl ./*.vhdl

%.asc: %.json
nextpnr-ice40 --package $(DEVICE) --pcf $(PIN_DEF) --json $< --asc $@
PCF_DEF = leds.pcf
PACKAGE = tq144

%.bin: %.asc
icepack $< $@

prog: $(PROJ).bin
iceprog $<

clean:
rm -f $(PROJ).json $(PROJ).asc $(PROJ).bin

.SECONDARY:
PLATFORM = ice40
DEVICE = hx1k

.PHONY: all prog clean
include ../../tools.mk
include ../../common.mk
18 changes: 18 additions & 0 deletions examples/icestick/uart/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

USE_DOCKER?=

PROJ ?= uart
TOPLEVEL ?= uart_top

VHDL_SYN_FILES = ./hdl/*.vhd

PCF_DEF = ./syn/constraints/uart.pcf
PACKAGE = tq144

PLATFORM = ice40
DEVICE = hx1k

NEXTPNR_FLAGS=--pcf-allow-unconstrained

include ../../tools.mk
include ../../common.mk
27 changes: 10 additions & 17 deletions examples/icezum/Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
PROJ ?= blink
PIN_DEF = icezum.pcf
DEVICE = hx1k

all: report bin

json: $(PROJ).vhdl
yosys -m ghdl -p 'ghdl $(PROJ).vhdl -e $(PROJ); synth_ice40 -json $@'
USE_DOCKER?=

asc: $(PIN_DEF) json
nextpnr-ice40 --$(DEVICE) --json json --pcf $(PIN_DEF) --asc $@
PROJ ?= blink
TOPLEVEL ?= blink

bin: asc
icepack $< $@
VHDL_SYN_FILES = ./*.vhdl

report: asc
icetime -d $(DEVICE) -mtr $@ $<
PCF_DEF = icezum.pcf
PACKAGE = tq144

clean:
rm -f json asc bin report work-obj93.cf
PLATFORM = ice40
DEVICE = hx1k

.SECONDARY:
.PHONY: all prog clean
include ../tools.mk
include ../common.mk
36 changes: 36 additions & 0 deletions examples/tools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

ifneq ($(USE_DOCKER),)
# Use Docker tools

DOCKER=docker
#DOCKER=podman

PWD = $(shell pwd)
DOCKERARGS = run --rm -v $(PWD)/../..:/src \
-w /src/examples/$(notdir $(PWD))

GHDL = $(DOCKER) $(DOCKERARGS) ghdl/synth:beta ghdl
GHDLSYNTH = ghdl
YOSYS = $(DOCKER) $(DOCKERARGS) ghdl/synth:beta yosys
NEXTPNR = $(DOCKER) $(DOCKERARGS) ghdl/synth:nextpnr-$(PLATFORM) nextpnr-$(PLATFORM)
ECPPACK = $(DOCKER) $(DOCKERARGS) ghdl/synth:trellis ecppack
ICEPACK = $(DOCKER) $(DOCKERARGS) ghdl/synth:trellis icepack
OPENOCD = $(DOCKER) $(DOCKERARGS) --device /dev/bus/usb ghdl/synth:prog openocd

ICEPORG = # ?
ICETIME = # ?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging, could someone check if iceprog and icetime exist in the docker image?
And if they do, how would they be included and would they need any flags like openocd does?


else
# Use local tools

GHDL = ghdl
GHDLSYNTH = ghdl
YOSYS = yosys
NEXTPNR = nextpnr-$(PLATFORM)
ECPPACK = ecppack
ICEPACK = icepack
OPENOCD = openocd
ICEPROG = iceprog
ICETIME = icetime

endif