| # Copyright 2022 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. | |
| MATCHA_SRC_DIR := $(ROOTDIR)/hw/matcha | |
| MATCHA_OUT_DIR := $(OUT)/matcha/hw | |
| MATCHA_VERILATOR_TB := $(MATCHA_OUT_DIR)/sim-verilator/Vchip_sim_tb | |
| MATCHA_TESTLOG_DIR := $(MATCHA_OUT_DIR)/test-log | |
| MATCHA_ASIC_BINARY_DIR := $(MATCHA_OUT_DIR)/asic_tests | |
| MATCHA_ASIC_MATCHA_BINARY_DIR := $(MATCHA_ASIC_BINARY_DIR)/matcha | |
| MATCHA_ASIC_KELVIN_BINARY_DIR := $(MATCHA_ASIC_BINARY_DIR)/kelvin | |
| BOOT_ROM_ELF := boot_rom.elf | |
| $(MATCHA_OUT_DIR): | |
| mkdir -p $(MATCHA_OUT_DIR) | |
| ## Regenerate Matcha HW files frop IPs and top_matcha definition. | |
| # This target uses Open Titan's autogen tools as well as the HW IPs to generate | |
| # the system verilog files as well as the DV register definition cores and | |
| # system verilog files. The source code is from both hw/opentitan-upstream and | |
| # hw/matcha/, while the output is stored at out/matcha/hw. | |
| # | |
| # This is a dev-only target (not for CI), as it modifies the hw/matcha source | |
| # tree with generated code. | |
| matcha_hw_generate_all: | $(MATCHA_OUT_DIR) | |
| $(MAKE) -C "$(MATCHA_SRC_DIR)/hw" all | |
| ## Build Matcha verilator testbench. | |
| # This target builds the verilator testbench binary from hw/matcha using | |
| # hw/opentitan-upstream as the library. The output is stored in | |
| # out/matcha/hw/. | |
| # This target is compute-intensive. Make sure you have a powerful enough machine | |
| # to build it. | |
| matcha_hw_verilator_sim: $(MATCHA_VERILATOR_TB) | |
| # TODO(ykwang): Copy only needed files into matcha output directory. | |
| # TODO(ykwang): Revise the structure of matcha output directory. | |
| $(MATCHA_VERILATOR_TB): $(MATCHA_OUT_DIR) verilator | |
| cd $(MATCHA_SRC_DIR) && \ | |
| bazel build //hw:verilator | |
| cd $(MATCHA_SRC_DIR) && \ | |
| cp -rf --no-preserve=mode bazel-bin/hw/build.verilator_real/* "$(MATCHA_OUT_DIR)" && \ | |
| chmod +x "$(MATCHA_OUT_DIR)/sim-verilator/Vchip_sim_tb" | |
| $(MATCHA_TESTLOG_DIR): | |
| mkdir -p $(MATCHA_TESTLOG_DIR) | |
| ## Build Matcha sw artifacts | |
| # | |
| # Checks the matcha sw code integrity for targets not covered by the verilator | |
| # tests. | |
| # | |
| matcha_sw_all: | $(MATCHA_OUT_DIR) | |
| cd $(MATCHA_SRC_DIR) && \ | |
| bazel build --define DISABLE_VERILATOR_BUILD=true --build_tag_filters="-kelvin_asic" \ | |
| //sw/device/... | |
| cd $(MATCHA_SRC_DIR) && \ | |
| find "bazel-out/" \( -type f -name "*.elf" -o -name "*.bin" -o -name "*.vmem" \) \ | |
| -exec cp -f --parents "{}" "$(MATCHA_OUT_DIR)" \; | |
| $(MATCHA_ASIC_MATCHA_BINARY_DIR): | |
| mkdir -p $(MATCHA_ASIC_MATCHA_BINARY_DIR) | |
| ## Build test binaries that run on ASIC | |
| matcha_asic_tests: | $(MATCHA_ASIC_MATCHA_BINARY_DIR) | |
| cd $(MATCHA_SRC_DIR) && \ | |
| bazel query //sw/device/tests/... \ | |
| | grep 'asic' \ | |
| | egrep '_bin$$' \ | |
| | grep -v '/smc:' \ | |
| | grep -v 'kelvin' \ | |
| | grep -v 'example_test_from_rom_rom_prog_asic_bin' \ | |
| | xargs bazel build | |
| cd $(MATCHA_SRC_DIR) && \ | |
| find 'bazel-out/' \ | |
| -type f \ | |
| \( -wholename "*ST-*/*asic.elf" -o -wholename "*ST-*/*asic.bin" \) \ | |
| -exec cp -f '{}' "$(MATCHA_ASIC_MATCHA_BINARY_DIR)" \; | |
| $(MATCHA_ASIC_KELVIN_BINARY_DIR): | |
| mkdir -p "$(MATCHA_ASIC_KELVIN_BINARY_DIR)" | |
| ## Build Matcha Kelvin SW ASIC test artifacts | |
| # | |
| # Build kelvin artifacts and package it in a tarball and ready for use on the ASIC | |
| # The output is at out/matcha/hw/asic_tests/kelvin | |
| # | |
| matcha_kelvin_asic_tarballs: kelvin_sw | $(MATCHA_ASIC_KELVIN_BINARY_DIR) | |
| cd $(MATCHA_SRC_DIR) && \ | |
| bazel build --define DISABLE_VERILATOR_BUILD=true \ | |
| @kelvin-binary//... | |
| # Copy the tarballs and sc binary to out/. | |
| cd $(MATCHA_SRC_DIR) && \ | |
| find "bazel-out/" -type f -wholename "*fastbuild-*/sw/device/tests/kelvin/asic_tests/kelvin_test_sc_extflash_asic.bin" |\ | |
| xargs -I {} cp -f {} "$(MATCHA_ASIC_KELVIN_BINARY_DIR)" | |
| cd $(MATCHA_SRC_DIR) && \ | |
| find "bazel-bin/external/kelvin-binary" -name "*.tar" |\ | |
| xargs -I {} cp -f {} "$(MATCHA_ASIC_KELVIN_BINARY_DIR)" | |
| ## Build opentitantool for matcha ASIC tests | |
| opentitantool_pkg: | $(MATCHA_OUT_DIR) | |
| cd $(MATCHA_SRC_DIR) && \ | |
| bazel build //sw:opentitantool_pkg | |
| cd $(MATCHA_SRC_DIR) && \ | |
| cp -f bazel-bin/sw/opentitantool_pkg.tar.gz $(MATCHA_OUT_DIR) | |
| ## Build and run matcha verilator test suite | |
| # | |
| matcha_hw_verilator_tests: verilator | $(MATCHA_TESTLOG_DIR) | |
| cd $(MATCHA_SRC_DIR) && \ | |
| bazel test --test_output=errors --test_timeout=180,600,1800,3600 \ | |
| --local_test_jobs=HOST_CPUS*0.25 \ | |
| --//hw:make_options=-j,16 \ | |
| //sw/device/tests:verilator_test_suite | |
| cd $(MATCHA_SRC_DIR) && cp -rf "bazel-testlogs/sw" "$(MATCHA_TESTLOG_DIR)" | |
| ## Build the boot ROM image | |
| # | |
| # This builds the HW boot rom executable for simulation. | |
| # Source is in hw/matcha, while output is placed in | |
| # out/matcha/hw/ | |
| multihart_boot_rom: | $(MATCHA_OUT_DIR) | |
| cd $(MATCHA_SRC_DIR) && \ | |
| bazel build --config=riscv32 //sw/device/lib/testing/test_rom:test_rom_no_otp_asic.elf | |
| cd $(MATCHA_SRC_DIR) && \ | |
| find "bazel-out/" -wholename "*test_rom/test_rom_no_otp_asic.elf" \ | |
| -exec cp -f '{}' "$(MATCHA_OUT_DIR)/$(BOOT_ROM_ELF)" \; | |
| ## Clean Matcha HW artifact | |
| matcha_hw_clean: | |
| rm -rf $(MATCHA_OUT_DIR) | |
| cd $(MATCHA_SRC_DIR) && \ | |
| bazel clean --expunge | |
| ## Build the spi_passthough binary | |
| # | |
| # This builds the spi_passthrough_asic.bin binary that can be used to | |
| # write flash tarballs to the nexus SPI boot flash. The binary will be copied | |
| # to out/spi_passthrough_asic.bin | |
| spi_passthrough: | $(OUT) | |
| cd $(MATCHA_SRC_DIR) && \ | |
| bazel build --define DISABLE_VERILATOR_BUILD=true \ | |
| sw/device/examples/spi_passthrough | |
| find "$(MATCHA_SRC_DIR)/bazel-out/" -type f -wholename "*fastbuild-*/sw/device/examples/spi_passthrough/spi_passthrough_asic.bin" |\ | |
| xargs -I '{}' cp -f '{}' "$(OUT)" | |
| ## Fetch latest prebuilt opentitantool | |
| latest_opentitantool: | $(OUT) | |
| curl https://storage.googleapis.com/shodan-public-artifacts/opentitantool_pkg_latest.tar.gz -o $(OUT)/opentitantool_pkg.tar.gz | |
| tar -C $(OUT) -xf $(OUT)/opentitantool_pkg.tar.gz | |
| .PHONY:: matcha_hw_verilator_sim matcha_hw_clean matcha_hw_verilator_tests | |
| .PHONY:: matcha_sw_all opentitantool_pkg | |
| .PHONY:: matcha_kelvin_asic_tarballs | |
| .PHONY:: multihart_boot_rom | |
| .PHONY:: spi_passthrough | |
| .PHONY:: latest_opentitantool |