blob: c464f21fe75ea61c108757dfd48b5e9099fdf264 [file] [log] [blame]
# A modified hw Makefile to build top level HW and pull the related support from
# Opentitan repository
CUR_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PRJ_DIR := $(realpath ${CUR_DIR}/../)
ROOTDIR ?= $(CUR_DIR)/../../..
OUT ?= $(ROOTDIR)/out
OPENTITAN_SRC_DIR ?= ${ROOTDIR}/hw/opentitan-upstream
OPENTITAN_UTIL_DIR ?= $(OPENTITAN_SRC_DIR)/util
REG_OUTPUT_DIR ?= ${OUT}/matcha/hw/regs-generated
REG_OUTPUT_DV_DIR ?= ${REG_OUTPUT_DIR}/dv
REG_OUTPUT_SW_DIR ?= ${REG_OUTPUT_DIR}/sw
# Still collect the list IP here for the generated reg output.
IPS ?= aes \
adc_ctrl \
aon_timer \
clkmgr \
entropy_src \
csrng \
edn \
flash_ctrl \
gpio \
hmac \
kmac \
i2c \
keymgr \
lc_ctrl \
otp_ctrl \
pattgen \
pinmux \
pwm \
pwrmgr \
rom_ctrl \
rstmgr \
rv_core_ibex \
rv_dm \
rv_timer \
sensor_ctrl \
spi_device \
spi_host \
sram_ctrl \
sysrst_ctrl \
trial1 \
otbn \
uart \
usbdev
TOPS ?= top_matcha
# conditional flags
VERBOSE ?= 0
toolflags ?=
ifeq ($(VERBOSE),1)
toolflags += -v
endif
dir_hjson = data
hjson_for_ip = ${OPENTITAN_SRC_DIR}/hw/ip/$(1)/$(dir_hjson)/$(1).hjson
# IPs that have a directory in hw/ip
local_ips := \
$(foreach i,$(IPS),$(if $(wildcard $(call hjson_for_ip,$(i))),$(i)))
# Per-IP targets (all phonies)
ips_reg = $(addsuffix _reg, $(local_ips))
ips_reg_header = $(addsuffix _reg_header, $(local_ips))
ips_reg_rust = $(foreach ip,$(local_ips),$(REG_OUTPUT_SW_DIR)/$(ip)_reg_constants.rs)
# Per-top targets (all phonies)
tops_gen = $(addsuffix _gen,$(TOPS))
tops_reg = $(addsuffix _reg,$(TOPS))
tops_dif = $(addsuffix _dif,$(TOPS))
# Targets for installing files into TOCK_ROOT (empty if TOCK_ROOT is not defined)
ifneq ($(TOCK_ROOT),)
tock_rust_destdir := $(TOCK_ROOT)/chips/lowrisc/src/reg_constants
ips_reg_rust_install := $(addprefix $(tock_rust_destdir)/,$(notdir $(ips_reg_rust)))
$(tock_rust_destdir):
mkdir -p $@
endif
.PHONY: $(ips_reg) $(ips_reg_header) $(ips_reg_rust) $(tops_gen) $(tops_reg) $(tops_dif)
all: $(ips_reg) $(tops_gen) $(tops_reg)
regs: $(ips_reg) $(tops_reg)
$(REG_OUTPUT_DV_DIR) $(REG_OUTPUT_SW_DIR): %:
mkdir -p $@
blk-gen-script = $(OPENTITAN_SRC_DIR)/hw/ip/$*/util/$*_gen.py
blk-hjson = $(OPENTITAN_SRC_DIR)/hw/ip/$*/$(dir_hjson)/$*.hjson
# If the ip has a local generation script, run it first. This will
# require all blocks to use a consistent naming. This should be hooked
# into ipgen (see #5636) for completeness.
$(ips_reg): %_reg: | $(REG_OUTPUT_DV_DIR)
$(if $(wildcard $(blk-gen-script)),$(blk-gen-script))
${OPENTITAN_SRC_DIR}/util/regtool.py ${toolflags} -r $(blk-hjson)
${OPENTITAN_SRC_DIR}/util/regtool.py --sec-cm-testplan $(blk-hjson)
${OPENTITAN_SRC_DIR}/util/regtool.py -s -t $(REG_OUTPUT_DV_DIR) $(blk-hjson)
# Register generation for otp_ctrl also depends on running gen-otp-mmap.py
.PHONY: otp-mmap
$(filter otp_ctrl_reg,$(ips_reg)): otp-mmap
otp-mmap:
cd ${OPENTITAN_SRC_DIR} && ./util/design/gen-otp-mmap.py
# Register generation for lc_ctrl also depends on running gen-lc-state-enc.py
.PHONY: lc-state-enc
$(filter lc_ctrl_reg,$(ips_reg)): lc-state-enc
lc-state-enc:
cd ${OPENTITAN_SRC_DIR} && ./util/design/gen-lc-state-enc.py
regs-header: $(ips_reg_header)
$(ips_reg_header): %_reg_header: | $(REG_OUTPUT_SW_DIR)
${OPENTITAN_SRC_DIR}/util/regtool.py -D -o $(REG_OUTPUT_SW_DIR)/$*_reg_headers.h $(blk-hjson)
regs-rust: $(ips_reg_rust_install) $(ips_reg_rust)
$(ips_reg_rust): $(REG_OUTPUT_SW_DIR)/%_reg_constants.rs: | $(REG_OUTPUT_SW_DIR)
${OPENTITAN_SRC_DIR}/util/regtool.py -R -o $@ $(blk-hjson)
$(ips_reg_rust_install): $(tock_rust_destdir)/%: $(REG_OUTPUT_SW_DIR)/% | $(tock_rust_destdir)
cp $< $@
clean-regs-header:
rm -r -f ${REG_OUTPUT_SW_DIR}
top-hjson = $(PRJ_DIR)/hw/$*/data/$*.hjson
top: $(tops_gen) $(tops_reg)
$(tops_gen): %_gen:
PYTHONPATH=$(OPENTITAN_UTIL_DIR) ${PRJ_DIR}/util/topgen_matcha.py -t $(top-hjson) -o ${PRJ_DIR}/hw/$*/ ${toolflags}
$(tops_reg): %_reg:
mkdir -p ${REG_OUTPUT_DV_DIR}/$*
PYTHONPATH=$(OPENTITAN_UTIL_DIR) ${PRJ_DIR}/util/topgen_matcha.py -t $(top-hjson) -r -o ${REG_OUTPUT_DV_DIR}/$* ${toolflags}
# Create DIF files for new Shodan HW IP
# Usage: make dif-ip ip-name=<new IP matching hjson file> ip-desc="<new IP description>"
# Autogenerated files must first be deleted before they can be regenerated.
.PHONY: dif-ip
dif-ip: $(tops_dif)
$(tops_dif): %_dif:
PYTHONPATH=$(OPENTITAN_UTIL_DIR) ${PRJ_DIR}/util/make_new_dif.py --ip-name-snake=$(ip-name) --ip-name-long="$(ip-desc)" --mode=new --top-name=$*
.PHONY: all