blob: 07e89987bf668c48fa695ca554eb972c630f2fac [file] [log] [blame]
Sam Elliott45fb1c62020-06-02 18:18:54 +01001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
lowRISC Contributors802543a2019-08-31 12:12:56 +01005CUR_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
6PRJ_DIR := $(realpath ${CUR_DIR}/../)
lowRISC Contributors802543a2019-08-31 12:12:56 +01007
Srikrishna Iyer6c870cb2019-10-30 02:08:12 -07008REG_OUTPUT_DIR ?= ${PRJ_DIR}/build/regs-generated
9REG_OUTPUT_DV_DIR ?= ${REG_OUTPUT_DIR}/dv
10REG_OUTPUT_SW_DIR ?= ${REG_OUTPUT_DIR}/sw
11
Michael Schaffner24984fc2020-01-17 17:42:57 -080012IPS ?= aes \
Eric Shiu5f1d3042021-03-17 17:24:11 -070013 adc_ctrl \
Timothy Chen2b8ef762021-02-16 14:44:55 -080014 aon_timer \
Timothy Chen3525aa82020-04-23 23:23:18 -070015 clkmgr \
Cindy Chendec07712020-10-27 17:16:12 -070016 entropy_src \
Mark Branstada069bb02020-12-02 11:59:34 -080017 csrng \
18 edn \
Michael Schaffner24984fc2020-01-17 17:42:57 -080019 flash_ctrl \
20 gpio \
21 hmac \
Eunchan Kim1a959052020-09-18 15:10:22 -070022 kmac \
Michael Schaffner24984fc2020-01-17 17:42:57 -080023 i2c \
Timothy Chen15adeee2020-09-09 15:44:35 -070024 keymgr \
Michael Schaffnere81ab752020-09-30 18:57:29 -070025 lc_ctrl \
Michael Schaffner41319c22020-04-12 15:40:24 -070026 otp_ctrl \
Timothy Chend12569f2021-02-12 15:28:12 -080027 pattgen \
Michael Schaffner24984fc2020-01-17 17:42:57 -080028 pinmux \
Michael Schaffnerfd39dc42021-06-22 19:28:07 -070029 pwm \
Timothy Chenbc16a172020-04-07 23:45:23 -070030 pwrmgr \
Rupert Swarbrick9855d4b2020-12-02 08:41:35 +000031 rom_ctrl \
Timothy Chen612901b2020-03-05 17:03:13 -080032 rstmgr \
Timothy Chen1d8b9602021-07-08 19:58:08 -070033 rv_core_ibex \
Michael Schaffner690d7322021-06-24 14:37:22 -070034 rv_dm \
Michael Schaffner24984fc2020-01-17 17:42:57 -080035 rv_timer \
Timothy Chen1e6db372020-05-19 20:52:45 -070036 sensor_ctrl \
Michael Schaffner24984fc2020-01-17 17:42:57 -080037 spi_device \
Michael Schaffner8e04df32021-02-09 19:52:24 -080038 spi_host \
Michael Schaffner86c0e322020-10-07 19:56:32 -070039 sram_ctrl \
Eric Shiu33ad5322021-03-11 19:23:00 -080040 sysrst_ctrl \
Michael Schaffner24984fc2020-01-17 17:42:57 -080041 trial1 \
Philipp Wagner5c2d2942020-06-22 11:34:00 +010042 otbn \
Michael Schaffner24984fc2020-01-17 17:42:57 -080043 uart \
Michael Schaffner6b434662022-04-14 20:16:57 -070044 usbdev
lowRISC Contributors802543a2019-08-31 12:12:56 +010045
Eunchan Kim49634d72019-09-05 14:39:57 -070046TOPS ?= top_earlgrey
47
Timothy Chen3193b002019-10-04 16:56:05 -070048# conditional flags
49VERBOSE ?= 0
50toolflags ?=
51ifeq ($(VERBOSE),1)
52 toolflags += -v
53endif
54
Tobias Wölfel4c5fbec2019-10-23 12:43:17 +020055dir_hjson = data
Timothy Chen3193b002019-10-04 16:56:05 -070056
Rupert Swarbrickbf7fe812021-08-27 16:59:56 +010057hjson_for_ip = ${PRJ_DIR}/hw/ip/$(1)/$(dir_hjson)/$(1).hjson
Eunchan Kim53e3b3b2019-11-13 12:33:49 -080058
Rupert Swarbrickbf7fe812021-08-27 16:59:56 +010059# IPs that have a directory in hw/ip
60local_ips := \
61 $(foreach i,$(IPS),$(if $(wildcard $(call hjson_for_ip,$(i))),$(i)))
lowRISC Contributors802543a2019-08-31 12:12:56 +010062
Rupert Swarbrickbf7fe812021-08-27 16:59:56 +010063# Per-IP targets (all phonies)
64ips_reg = $(addsuffix _reg, $(local_ips))
65ips_reg_header = $(addsuffix _reg_header, $(local_ips))
Rupert Swarbricked64f3b2021-08-31 16:51:11 +010066ips_reg_rust = $(foreach ip,$(local_ips),$(REG_OUTPUT_SW_DIR)/$(ip)_reg_constants.rs)
Tobias Wölfelce06a242019-10-23 13:54:46 +020067
Rupert Swarbrickbf7fe812021-08-27 16:59:56 +010068# Per-top targets (all phonies)
Eunchan Kim49634d72019-09-05 14:39:57 -070069tops_gen = $(addsuffix _gen,$(TOPS))
Srikrishna Iyer6c870cb2019-10-30 02:08:12 -070070tops_reg = $(addsuffix _reg,$(TOPS))
lowRISC Contributors802543a2019-08-31 12:12:56 +010071
Rupert Swarbricked64f3b2021-08-31 16:51:11 +010072# Targets for installing files into TOCK_ROOT (empty if TOCK_ROOT is not defined)
73ifneq ($(TOCK_ROOT),)
74tock_rust_destdir := $(TOCK_ROOT)/chips/lowrisc/src/reg_constants
75ips_reg_rust_install := $(addprefix $(tock_rust_destdir)/,$(notdir $(ips_reg_rust)))
76
77$(tock_rust_destdir):
78 mkdir -p $@
79endif
80
Rupert Swarbrickbf7fe812021-08-27 16:59:56 +010081.PHONY: $(ips_reg) $(ips_reg_header) $(ips_reg_rust) $(tops_gen) $(tops_reg)
82
Rupert Swarbrick8d44b372021-08-31 16:59:40 +010083all: $(ips_reg) $(tops_gen) $(tops_reg)
Srikrishna Iyer6c870cb2019-10-30 02:08:12 -070084
Rupert Swarbrick8d44b372021-08-31 16:59:40 +010085regs: $(ips_reg) $(tops_reg)
Srikrishna Iyer6c870cb2019-10-30 02:08:12 -070086
Rupert Swarbrickdd2a2cc2021-08-31 16:55:50 +010087$(REG_OUTPUT_DV_DIR) $(REG_OUTPUT_SW_DIR): %:
88 mkdir -p $@
lowRISC Contributors802543a2019-08-31 12:12:56 +010089
Rupert Swarbrickbf7fe812021-08-27 16:59:56 +010090blk-gen-script = $(PRJ_DIR)/hw/ip/$*/util/$*_gen.py
91blk-hjson = $(PRJ_DIR)/hw/ip/$*/$(dir_hjson)/$*.hjson
92
93# If the ip has a local generation script, run it first. This will
94# require all blocks to use a consistent naming. This should be hooked
95# into ipgen (see #5636) for completeness.
Rupert Swarbrick50b364a2021-08-31 17:13:26 +010096$(ips_reg): %_reg: | $(REG_OUTPUT_DV_DIR)
Rupert Swarbrickbf7fe812021-08-27 16:59:56 +010097 $(if $(wildcard $(blk-gen-script)),$(blk-gen-script))
98 ${PRJ_DIR}/util/regtool.py ${toolflags} -r $(blk-hjson)
Srikrishna Iyera463e172022-02-02 12:09:39 -080099 ${PRJ_DIR}/util/regtool.py --sec-cm-testplan $(blk-hjson)
Rupert Swarbrickdd2a2cc2021-08-31 16:55:50 +0100100 ${PRJ_DIR}/util/regtool.py -s -t $(REG_OUTPUT_DV_DIR) $(blk-hjson)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100101
Rupert Swarbrick8dbaba42021-08-31 17:06:46 +0100102# Register generation for otp_ctrl also depends on running gen-otp-mmap.py
103.PHONY: otp-mmap
104$(filter otp_ctrl_reg,$(ips_reg)): otp-mmap
Michael Schaffnerf6a79002020-10-27 10:00:13 -0700105otp-mmap:
Michael Schaffner1fff9852021-01-08 14:06:35 -0800106 cd ${PRJ_DIR} && ./util/design/gen-otp-mmap.py
Michael Schaffnerf6a79002020-10-27 10:00:13 -0700107
Rupert Swarbrick50b364a2021-08-31 17:13:26 +0100108# Register generation for lc_ctrl also depends on running gen-lc-state-enc.py
109.PHONY: lc-state-enc
110$(filter lc_ctrl_reg,$(ips_reg)): lc-state-enc
Michael Schaffner6db11f22021-01-25 18:24:20 -0800111lc-state-enc:
112 cd ${PRJ_DIR} && ./util/design/gen-lc-state-enc.py
113
Rupert Swarbrick8d44b372021-08-31 16:59:40 +0100114regs-header: $(ips_reg_header)
Srikrishna Iyer6c870cb2019-10-30 02:08:12 -0700115
Rupert Swarbrickdd2a2cc2021-08-31 16:55:50 +0100116$(ips_reg_header): %_reg_header: | $(REG_OUTPUT_SW_DIR)
117 ${PRJ_DIR}/util/regtool.py -D -o $(REG_OUTPUT_SW_DIR)/$*_reg_headers.h $(blk-hjson)
Tobias Wölfelce06a242019-10-23 13:54:46 +0200118
Rupert Swarbrick8d44b372021-08-31 16:59:40 +0100119regs-rust: $(ips_reg_rust_install) $(ips_reg_rust)
Chia-Chi Tenga0387902021-08-10 10:39:22 -0600120
Rupert Swarbrickdd2a2cc2021-08-31 16:55:50 +0100121$(ips_reg_rust): $(REG_OUTPUT_SW_DIR)/%_reg_constants.rs: | $(REG_OUTPUT_SW_DIR)
Rupert Swarbricked64f3b2021-08-31 16:51:11 +0100122 ${PRJ_DIR}/util/regtool.py -R -o $@ $(blk-hjson)
123
124$(ips_reg_rust_install): $(tock_rust_destdir)/%: $(REG_OUTPUT_SW_DIR)/% | $(tock_rust_destdir)
125 cp $< $@
Chia-Chi Tenga0387902021-08-10 10:39:22 -0600126
Tobias Wölfelce06a242019-10-23 13:54:46 +0200127clean-regs-header:
Srikrishna Iyer6c870cb2019-10-30 02:08:12 -0700128 rm -r -f ${REG_OUTPUT_SW_DIR}
Tobias Wölfelce06a242019-10-23 13:54:46 +0200129
Rupert Swarbrick08b54212021-08-31 17:21:53 +0100130top-hjson = $(PRJ_DIR)/hw/$*/data/$*.hjson
Eunchan Kim49634d72019-09-05 14:39:57 -0700131
Rupert Swarbrick08b54212021-08-31 17:21:53 +0100132top: $(tops_gen) $(tops_reg)
133$(tops_gen): %_gen:
134 ${PRJ_DIR}/util/topgen.py -t $(top-hjson) -o ${PRJ_DIR}/hw/$*/ ${toolflags}
135
136$(tops_reg): %_reg:
137 mkdir -p ${REG_OUTPUT_DV_DIR}/$*
138 ${PRJ_DIR}/util/topgen.py -t $(top-hjson) -r -o ${REG_OUTPUT_DV_DIR}/$* ${toolflags}
Srikrishna Iyer6c870cb2019-10-30 02:08:12 -0700139
140
Rupert Swarbrick50b364a2021-08-31 17:13:26 +0100141.PHONY: all