| #!/bin/bash |
| # |
| # Copyright 2024 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # https://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| # Firmware image to build & load at boot. |
| ifeq ($(CHERIOT_FIRMWARE),) |
| $(error "CHERIOT_FIRMWARE not set. Did build/platforms/${PLATFORM}/setup.sh get sourced?") |
| endif |
| CHERIOT_FIRMWARE_SRC_DIR := ${ROOTDIR}/hw/matcha/sw/device/cheriot/${CHERIOT_FIRMWARE} |
| |
| # Optional xmake config options, typically useful for enabling debugging |
| # otherwise compiled out. |
| #CHERIOT_DEBUG_CONFIG_OPTIONS=--debug-scheduler=true --debug-allocator=true |
| #CHERIOT_RELEASE_CONFIG_OPTIONS=--debug-scheduler=true --debug-allocator=true |
| |
| # Platform-specific requirements handled by "m prereqs" |
| PLATFORM_PYTHON_DEPS=\ |
| ${ROOTDIR}/hw/opentitan-upstream/python-requirements.txt |
| PLATFORM_APT_DEPS=\ |
| ${ROOTDIR}/hw/opentitan-upstream/apt-requirements.txt |
| |
| # Put host tool targets first. |
| include $(ROOTDIR)/build/platforms/nexus/renode.mk |
| include $(ROOTDIR)/build/platforms/sencha/cheriot.mk |
| include $(ROOTDIR)/build/platforms/sencha/riscv_toolchain.mk |
| |
| include $(ROOTDIR)/build/platforms/nexus/iree.mk |
| include $(ROOTDIR)/build/platforms/nexus/kelvin.mk |
| include $(ROOTDIR)/build/platforms/nexus/opentitan_sw.mk |
| include $(ROOTDIR)/build/platforms/nexus/opentitan_hw.mk |
| include $(ROOTDIR)/build/platforms/nexus/matcha_hw.mk |
| include $(ROOTDIR)/build/platforms/nexus/tock.mk |
| |
| # Put simulation targets at the end |
| include $(ROOTDIR)/build/platforms/sencha/sim.mk |
| |
| # Driver include files auto-generated from opentitan definitions. |
| |
| ifeq ($(OPENTITAN_SOURCE),) |
| $(error "OPENTITAN_SOURCE not set. Did build/platforms/sencha/setup.sh get sourced?") |
| endif |
| |
| ifeq ($(OPENTITAN_GEN_DIR),) |
| $(error "OPENTITAN_GEN_DIR not set. Did build/platforms/sencha/setup.sh get sourced?") |
| endif |
| |
| $(OPENTITAN_GEN_DIR): |
| mkdir -p $(OPENTITAN_GEN_DIR) |
| |
| # Matcha hw config #defines generated from RTL |
| |
| I2S_HEADER=$(OPENTITAN_GEN_DIR)/i2s_regs.h |
| ML_TOP_HEADER=$(OPENTITAN_GEN_DIR)/ml_top_regs.h |
| TLUL_MAILBOX_HEADER=$(OPENTITAN_GEN_DIR)/tlul_mailbox_regs.h |
| UART_HEADER=$(OPENTITAN_GEN_DIR)/uart_regs.h |
| |
| $(I2S_HEADER): $(REGTOOL) $(I2S_HJSON) | $(OPENTITAN_GEN_DIR) |
| $(REGTOOL) -D -o $@ $(I2S_HJSON) |
| $(ML_TOP_HEADER): $(REGTOOL) $(ML_TOP_HJSON) | $(OPENTITAN_GEN_DIR) |
| $(REGTOOL) -D -o $@ $(ML_TOP_HJSON) |
| $(TLUL_MAILBOX_HEADER): $(REGTOOL) $(MBOX_HJSON) | $(OPENTITAN_GEN_DIR) |
| $(REGTOOL) -D -o $@ $(MBOX_HJSON) |
| $(UART_HEADER): $(REGTOOL) $(UART_HJSON) | $(OPENTITAN_GEN_DIR) |
| $(REGTOOL) -D -o $@ $(UART_HJSON) |
| |
| TOP_MATCHA_DIR=${CHERIOT_OUT_DIR}/top_matcha |
| TOP_MATCHA_MEMORY_HEADER=$(TOP_MATCHA_DIR)/sw/autogen/top_matcha_memory.h |
| TOP_MATCHA_IRQ_HEADER=$(TOP_MATCHA_DIR)/sw/autogen/top_matcha_smc_irq.h |
| # NB: could depend on the templates instead |
| TOPGEN_MATCHA=${ROOTDIR}/hw/matcha/util/topgen_matcha.py |
| |
| ${TOP_MATCHA_DIR}: |
| mkdir -p $(TOP_MATCHA_DIR) |
| |
| # NB: no way to generate just the files we need |
| $(TOP_MATCHA_IRQ_HEADER): $(TOPGEN_MATCHA) ${TOP_MATCHA_DIR} $(TOP_MATCHA_HJSON) |
| PYTHONPATH=${OPENTITAN_SOURCE}/util/ ${TOPGEN_MATCHA} -t ${TOP_MATCHA_HJSON} -o ${TOP_MATCHA_DIR}/ --top-only |
| $(TOP_MATCHA_MEMORY_HEADER): $(TOPGEN_MATCHA) ${TOP_MATCHA_DIR} $(TOP_MATCHA_HJSON) |
| PYTHONPATH=${OPENTITAN_SOURCE}/util/ ${TOPGEN_MATCHA} -t ${TOP_MATCHA_HJSON} -o ${TOP_MATCHA_DIR}/ --top-only |
| |
| # Targets to install the symlink to opentitan headers for each build |
| |
| cheriot-build-debug-prepare:: | $(CHERIOT_OUT_DEBUG) |
| ln -sf $(CHERIOT_OUT_DIR)/opentitan-gen $(CHERIOT_OUT_DEBUG)/ |
| |
| cheriot-build-release-prepare:: | $(CHERIOT_OUT_RELEASE) |
| ln -sf $(CHERIOT_OUT_DIR)/opentitan-gen $(CHERIOT_OUT_RELEASE)/ |
| |
| CHERIOT_GEN_HEADERS=\ |
| $(I2S_HEADER) \ |
| $(ML_TOP_HEADER) \ |
| $(TLUL_MAILBOX_HEADER) \ |
| $(UART_HEADER) \ |
| $(TOP_MATCHA_IRQ_HEADER) \ |
| $(TOP_MATCHA_MEMORY_HEADER) |
| |
| cheriot-gen-headers:: $(CHERIOT_GEN_HEADERS) |
| |
| cheriot-clean-headers:: |
| rm -f $(CHERIOT_GEN_HEADERS) |
| |
| # Point to the clang++ target to make sure the binary is installed. |
| $(CACHE)/cheriot-tools/bin/clang++: | $(CACHE) |
| ./scripts/install-toolchain.sh cheriot |
| |
| ## Installs the LLVM compiler for CHERIoT |
| # |
| # Requires network access. This fetches the toolchain from the GCP archive and |
| # extracts it locally to the cache/. |
| install_cheriot: $(CACHE)/cheriot-tools/bin/clang++ |
| |
| # NB: install the prebuilt CHERIoT toolchain. Note this means it |
| # is necessary to do something like: |
| # $ set-platform sencha |
| # $ m tools |
| # to get a working build environment. |
| tools:: install_cheriot |
| |
| .PHONY:: install_cheriot |