blob: 5892bddfd555a7f6c06d054bec2166fca2da0c43 [file] [log] [blame] [edit]
# 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.
# NB: The SMC/CHERIoT has no (working) gdb support so debug builds
# are not useful.
EXT_FLASH_DEBUG=$(CHERIOT_OUT_DEBUG)/ext_flash.tar
EXT_FLASH_RELEASE=$(CHERIOT_OUT_RELEASE)/ext_flash.tar
CHERIOT_SIM_SRC_DIR := $(ROOTDIR)/sim/mpact-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
.PHONY:: sim_configs clean_sim_configs
# 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))
SENCHA_REPL=sim/config/platforms/sencha.repl
SENCHA_RESC_RELEASE=sim/config/sencha.resc
# Common logic for running a CHERIoT firmware ELF image on sencha.
# SEC boots first using multihart_boot_rom. It loads matcha-tock
# which loads the SMC firmware image (cheriot_elf) from the tarball
# located in flash and then resets the SMC with the pc set to the
# entry_point in cheriot_elf.
#
# The following targets do slightly different versions of the above;
# some of which are useless due to the missing gdb support.
# Sencha-specific renode scripts. We construct them in make as much
# as possible to avoid shell quoting/escape issues. The only parts
# done in the shell use __SENCHA_* variables that are dynamically
# calculated.
SENCHA_SCRIPT:= $$repl_file = @${SENCHA_REPL};
SENCHA_SCRIPT+= $$sc_bin =@$(TMP_RELEASE)/matcha-tock-bundle.bin;
SENCHA_SCRIPT+= i @${SENCHA_RESC_RELEASE};
# Hack: copy before the prestart commands are appended
SENCHA_DEBUG_SCRIPT := ${SENCHA_SCRIPT}
SENCHA_SCRIPT+= $(RENODE_PRESTART_CMDS)
SENCHA_CLI_SCRIPT:= $$repl_file = @${SENCHA_REPL};
SENCHA_CLI_SCRIPT+= $$sc_bin =@$(TMP_RELEASE)/matcha-tock-bundle.bin;
SENCHA_CLI_SCRIPT+= $$cli_port = 4567;
SENCHA_CLI_SCRIPT+= $$wait_for_cli = true;
SENCHA_CLI_SCRIPT+= i @${SENCHA_RESC_RELEASE};
SENCHA_CLI_SCRIPT+= $(RENODE_PRESTART_CMDS)
__sencha-simulate: renode cheriot_sim kelvin_sim multihart_boot_rom
$(RENODE_CMD) -e '$$tar=${__SENCHA_TAR}; $$cheriot_elf=${__SENCHA_CHERIOT_ELF}; ${SENCHA_SCRIPT} start'
__sencha-simulate+cli: renode cheriot_sim kelvin_sim multihart_boot_rom
$(RENODE_CMD) -e '$$tar=${__SENCHA_TAR}; $$cheriot_elf=${__SENCHA_CHERIOT_ELF}; ${SENCHA_CLI_SCRIPT} start'
# NB: just run the release version for now
__sencha-simulate-debug: __sencha-simulate
# NB: can attach with gdb but runs the release build artifacts
__sencha-debug-simulation: renode cheriot_sim kelvin_sim multihart_boot_rom
$(RENODE_CMD) -e '$$tar=${__SENCHA_TAR}; $$cheriot_elf=${__SENCHA_CHERIOT_ELF}; ${SENCHA_DEBUG_SCRIPT} start'
.PHONY:: __sencha-simulate __sencha-simulate+cli
.PHONY:: __sencha-simulate-debug __sencha-debug-simulation
$(TMP_DEBUG):
mkdir -p $(TMP_DEBUG)
$(TMP_RELEASE):
mkdir -p $(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)
## Launches an end-to-end build of the system and starts Renode
#
# This top-level target triggers the `ext_flash_release`, `cheriot_sim`, `renode`,
# `multihart_boot_rom`, and `kelvin_sim` 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: ext_flash_release
${MAKE} \
__SENCHA_TAR="@${EXT_FLASH_RELEASE}" \
__SENCHA_CHERIOT_ELF="@${TMP_RELEASE}/kernel" \
__sencha-simulate
## Version of the `simulate` target that also enables the mpact-cheriot
## simulator command line interface on port 4567. To access the simulator
## use something like `telnet localhost 4567`. Note the simulation will
## block until the cli is connected.
simulate+cli: ext_flash_release
${MAKE} \
__SENCHA_TAR="@${EXT_FLASH_RELEASE}" \
__SENCHA_CHERIOT_ELF="@${TMP_RELEASE}/kernel" \
__sencha-simulate+cli
## 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 `ext_flash_debug` target.
simulate-debug: ext_flash_debug
${MAKE} \
__SENCHA_TAR="@${EXT_FLASH_DEBUG}" \
__SENCHA_CHERIOT_ELF="@${TMP_DEBUG}/kernel" \
__sencha-simulate-debug
## 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
# debugging.
debug-simulation: ext_flash_debug
${MAKE} \
__SENCHA_TAR="@${EXT_FLASH_DEBUG}" \
__SENCHA_CHERIOT_ELF="@${TMP_DEBUG}/kernel" \
__sencha-debug-simulation
.PHONY:: simulate simulate+cli simulate-debug debug-simulation
$(CHERIOT_SIM_OUT_DIR):
mkdir -p "$(CHERIOT_SIM_OUT_DIR)"
# Support for building the standalone mpact-cheriot simulator and the
# library packaged for use within renode.
## 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: | $(CHERIOT_SIM_OUT_DIR)
cd "$(CHERIOT_SIM_SRC_DIR)" && \
bazel build --sandbox_tmpfs_path=/tmp \
//cheriot:mpact_cheriot \
//cheriot:renode_mpact_cheriot
cd "$(CHERIOT_SIM_SRC_DIR)/bazel-bin" && \
cp -f cheriot/mpact_cheriot "$(CHERIOT_SIM_OUT_DIR)" && \
cp -f cheriot/librenode_mpact_cheriot.so "$(CHERIOT_SIM_OUT_DIR)"
## Clean CHERIoT ISS
#
# Clean the CHERIoT ISS
cheriot_sim_clean:
cd "$(CHERIOT_SIM_SRC_DIR)" && \
bazel clean --expunge
rm -rf $(CHERIOT_SIM_OUT_DIR)
.PHONY:: cheriot_sim cheriot_sim_clean
include $(ROOTDIR)/build/platforms/sencha/sim_ottf.mk
include $(ROOTDIR)/build/platforms/sencha/sim_testbench.mk