blob: 1da811195fafad5a507e9cdac425d3b5bb562370 [file] [log] [blame]
#!/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.
# NB: the pathname to the source directory is formulated in platform.mk
export CHERIOT_FIRMWARE="soundstream"
export C_PREFIX="riscv32-unknown-elf-"
export OPENTITAN_GEN_DIR="${CHERIOT_OUT_DIR}/opentitan-gen/include/opentitan"
export OPENTITAN_SOURCE="${ROOTDIR}/hw/opentitan-upstream"
# Some build.rs files use the regtool crate which needs to know where to find
# regtool.py.
export REGTOOL="${OPENTITAN_SOURCE}/util/regtool.py"
# The following files are the input to regtool.py
export I2S_HJSON="${ROOTDIR}/hw/matcha/hw/top_matcha/ip/i2s/data/i2s.hjson"
export MBOX_HJSON="${ROOTDIR}/hw/matcha/hw/top_matcha/ip/tlul_mailbox/data/tlul_mailbox.hjson"
export ML_TOP_HJSON="${ROOTDIR}/hw/matcha/hw/top_matcha/ip/ml_top/data/ml_top.hjson"
export TIMER_HJSON="${OPENTITAN_GEN_DIR}/rv_timer.hjson"
export UART_HJSON="${OPENTITAN_SOURCE}/hw/ip/uart/data/uart.hjson"
export VC_TOP_HJSON="${ROOTDIR}/hw/matcha/hw/top_matcha/ip/vc_top/data/vc_top.hjson"
# Input for topgen_matcha.py to generate hw configuration
export TOP_MATCHA_HJSON="${ROOTDIR}/hw/matcha/hw/top_matcha/data/top_matcha.hjson"
function parting_messages() {
if [[ ! -d "${RUSTDIR}" ]] ||
[[ ! -d "${ROOTDIR}/cache/cheriot-tools" ]] ||
[[ ! -d "${ROOTDIR}/cache/toolchain" ]] ||
[[ ! -d "${ROOTDIR}/cache/toolchain_kelvin" ]] ||
[[ ! -d "${ROOTDIR}/cache/renode" ]]; then
echo
echo '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
echo You have missing tools. Please run \'m prereqs\' followed
echo by \'m tools\' to install them.
echo '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
echo
[[ -d "${RUSTDIR}" ]] || echo "${RUSTDIR} is missing!"
[[ -d "${ROOTDIR}/cache/cheriot-tools" ]] || echo "${ROOTDIR}/cache/cheriot-tools is missing"
[[ -d "${ROOTDIR}/cache/toolchain" ]] || echo "${ROOTDIR}/cache/toolchain is missing"
[[ -d "${ROOTDIR}/cache/toolchain_kelvin" ]] || echo "${ROOTDIR}/cache/toolchain_kelvin is missing!"
[[ -d "${ROOTDIR}/cache/renode" ]] || echo "${ROOTDIR}/cache/renode is missing!"
fi
echo Run \'set-nexus-id NN\' to set your Nexus board ID
}
function sim_kelvin
{
# Run the ELF/Bin program with kelvin_sim
local bin_file="$(realpath $1)"
local magic_bytes="$(xxd -p -l 4 ${bin_file})"
local -a flags=()
local is_elf=false
if [[ ${magic_bytes} == "7f454c46" ]]; then
is_elf=true
else
flags+=("--entry_point 0 ")
fi
if [[ "$2" == "debug" ]]; then
flags+=("-i")
if [[ "${is_elf}" == false ]]; then
echo "debug mode only works on ELF files"
return 1
fi
fi
("${OUT}/kelvin/sim/kelvin_sim" "${bin_file}" ${flags[@]})
}
function sim_kelvin_renode
{
# Run the Bin program with renode
local bin_file="$(realpath $1)"
local command="start;"
(cd "${ROOTDIR}" && renode -e "\$bin=@${bin_file}; i @sim/config/kelvin.resc; \
${command} sysbus.ml_top_controlblock WriteDoubleWord 0xc 0" \
--disable-xwt --console)
}