blob: 2347e7639a097bcaae7cc51330fdc1a6e62d0b81 [file] [log] [blame]
# 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.
EXT_FLASH_DEBUG=$(CHERIOT_OUT_DEBUG)/ext_flash.tar
EXT_FLASH_RELEASE=$(CHERIOT_OUT_RELEASE)/ext_flash.tar
CHERIOT_SIM_SRC_DIR := $(ROOTDIR)/sim/cheriot
CHERIOT_SIM_OUT_DIR := $(OUT)/cheriot/sim
TMP_DEBUG=$(CHERIOT_OUT_DEBUG)/tmp
TMP_RELEASE=$(CHERIOT_OUT_RELEASE)/tmp
sim_configs:
$(RENODE_SIM_GENERATOR_SCRIPT)
clean_sim_configs:
@rm -rf $(OUT)/renode_configs
$(TMP_DEBUG):
mkdir $(TMP_DEBUG)
$(TMP_RELEASE):
mkdir $(TMP_RELEASE)
# XXX symlink cheriot fw to "kernel" to satisfy elfloader
$(EXT_FLASH_DEBUG): $(MATCHA_BUNDLE_DEBUG) $(CHERIOT_FIRMWARE_DEBUG) | $(TMP_DEBUG)
cp -f $(MATCHA_BUNDLE_DEBUG) $(TMP_DEBUG)/matcha-tock-bundle
${C_PREFIX}strip $(TMP_DEBUG)/matcha-tock-bundle
${C_PREFIX}objcopy -O binary -g $(TMP_DEBUG)/matcha-tock-bundle $(TMP_DEBUG)/matcha-tock-bundle.bin
ln -sf $(CHERIOT_FIRMWARE_DEBUG) $(TMP_DEBUG)/kernel
tar -C $(TMP_DEBUG) -cvhf $@ matcha-tock-bundle.bin kernel
ext_flash_debug: $(EXT_FLASH_DEBUG)
# XXX symlink cheriot fw to "kernel" to satisfy elfloader
$(EXT_FLASH_RELEASE): $(MATCHA_BUNDLE_RELEASE) $(CHERIOT_FIRMWARE_RELEASE) | $(TMP_RELEASE)
cp -f $(MATCHA_BUNDLE_RELEASE) $(TMP_RELEASE)/matcha-tock-bundle
${C_PREFIX}strip $(TMP_RELEASE)/matcha-tock-bundle
${C_PREFIX}objcopy -O binary -g $(TMP_RELEASE)/matcha-tock-bundle $(TMP_RELEASE)/matcha-tock-bundle.bin
ln -sf $(CHERIOT_FIRMWARE_RELEASE) $(TMP_RELEASE)/kernel
tar -C $(TMP_RELEASE) -cvhf $@ matcha-tock-bundle.bin kernel
ext_flash_release: $(EXT_FLASH_RELEASE)
# Renode commands to issue before the initial start of a simulation.
# This pauses all cores and then sets cpu0 (SC).
RENODE_PRESTART_CMDS=pause; cpu0 IsHalted false;
PORT_PRESTART_CMDS:=$(shell $(ROOTDIR)/scripts/generate-renode-port-cmd.sh $(RENODE_PORT))
# XXX the same for now
SENCHA_RESC_DEBUG=sim/config/sencha.resc
SENCHA_RESC_RELEASE=sim/config/sencha.resc
CHERIOT_RESC_RELEASE=sim/config/cheriot.resc
SENCHA_REPL=sim/config/platforms/sencha.repl
## Run the testbench in standalone cheriot
cheriot-testbench: renode cheriot_sim $(CHERIOT_TEST)
$(RENODE_CMD) -e "\
i @${CHERIOT_RESC_RELEASE}; \
start"
## Launches an end-to-end build of the system and starts Renode
#
# This top-level target triggers the `matcha_tock_release`, `cheriot`, `renode`,
# `multihart_boot_rom`, and `iree` targets to build the entire system and then
# finally starts the Renode simulator.
#
# This is the default target for the build system, and is generally what you
# need for day-to-day work on the software side of Shodan.
simulate: renode cheriot_sim kelvin_sim multihart_boot_rom ext_flash_release
$(RENODE_CMD) -e "\
\$$repl_file = @${SENCHA_REPL}; \
\$$tar = @$(EXT_FLASH_RELEASE); \
\$$sc_bin =@$(TMP_RELEASE)/matcha-tock-bundle.bin; \
$(PORT_PRESTART_CMDS) i @${SENCHA_RESC_RELEASE}; \
$(RENODE_PRESTART_CMDS) start"
## Version of the `simulate` target that also enables the simulator command
## line interface on port 4567. To access the simulator use something like
## telnet localhost 4567. Note renode will block until the cli is connected.
simulate+cli: renode cheriot_sim kelvin_sim multihart_boot_rom ext_flash_release
$(RENODE_CMD) -e "\
\$$repl_file = @${SENCHA_REPL}; \
\$$tar = @$(EXT_FLASH_RELEASE); \
\$$sc_bin =@$(TMP_RELEASE)/matcha-tock-bundle.bin; \
\$$cli_port = 4567; \
\$$wait_for_cli = true; \
$(PORT_PRESTART_CMDS) i @${SENCHA_RESC_RELEASE}; \
$(RENODE_PRESTART_CMDS) start"
## Debug version of the `simulate` target
#
# This top-level target does the same job as `simulate`, but instead of
# unhalting the CPUs and starting the system, this alternate target only unhalts
# cpu0, and uses the debug build of TockOS from the `matcha_tock_debug` target.
simulate-debug: renode cheriot_sim kelvin_sim multihart_boot_rom ext_flash_debug
$(RENODE_CMD) -e "\
\$$repl_file = @${SENCHA_REPL}; \
\$$tar = @$(EXT_FLASH_DEBUG); \
\$$sc_bin =@$(TMP_DEBUG)/matcha-tock-bundle.bin; \
$(PORT_PRESTART_CMDS) i @${SENCHA_RESC_DEBUG}; \
$(RENODE_PRESTART_CMDS); start"
## Debug version of the `simulate` target
#
# This top-level target does the same job as `simulate-debug`, but instead of
# unhalting the CPUs and starting the system, this alternate target starts
# renode with no CPUs unhalted, allowing for GDB to be used for early system
# start.
debug-simulation: renode cheriot_sim kelvin_sim multihart_boot_rom ext_flash_debug
$(RENODE_CMD) -e "\
\$$repl_file = @${SENCHA_REPL}; \
\$$tar = @$(EXT_FLASH_DEBUG); \
\$$sc_bin =@$(TMP_DEBUG)/matcha-tock-bundle.bin; \
$(PORT_PRESTART_CMDS) i @${SENCHA_RESC_DEBUG}; start"
$(CHERIOT_SIM_OUT_DIR):
mkdir -p "$(CHERIOT_SIM_OUT_DIR)"
## Build CHERIoT ISS
#
# Build mpact-sim-based CHERIoT ISS with bazel, and copy it to out/
# Use /tmp as the bazel tmpfs to unblock CI
cheriot_sim_notyet: | $(CHERIOT_SIM_OUT_DIR)
cd "$(CHERIOT_SIM_SRC_DIR)" && \
bazel build --sandbox_tmpfs_path=/tmp //sim:cheriot_sim \
//sim/renode:renode_cheriot
cd "$(CHERIOT_SIM_SRC_DIR)/bazel-bin" && \
cp -f sim/cheriot_sim "$(CHERIOT_SIM_OUT_DIR)" && \
cp -f sim/renode/librenode_mpact_cheriot.so "$(CHERIOT_SIM_OUT_DIR)"
## Clean CHERIoT ISS
#
# Clean the CHERIoT ISS
cheriot_sim_clean_notyet:
cd "$(CHERIOT_SIM_SRC_DIR)" && \
bazel clean --expunge
rm -rf $(CHERIOT_SIM_OUT_DIR)
# TODO(sleffler): temporary hack until the simulator source is integrated
cheriot_sim: | $(CHERIOT_SIM_OUT_DIR)
cp -f ${CACHE}/cheriot-tools/librenode_mpact_cheriot.so "$(CHERIOT_SIM_OUT_DIR)"
cheriot_sim_clean:
rm -rf $(CHERIOT_SIM_OUT_DIR)
.PHONY:: sim_configs clean_sim_configs simulate simulate-debug debug-simulation
.PHONY:: cheriot_sim cheriot_sim_clean