blob: b1bbf1b9e542d78030e198f801c96734f4db9bfa [file] [log] [blame]
David Lattimore60e282a2021-05-26 11:27:48 +10001#!/bin/bash
2
3# Copyright 2021 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Builds and runs the Rust SOC ROM. ./scripts/proto2-run should already be
8# running in a separate shell.
9
10set -e
11
12PROJECT_ROOT=$(git rev-parse --show-toplevel)
13ROM="${PROJECT_ROOT}/build/hps_platform/soc_rom.bin"
14
David Lattimore8df36762021-11-24 16:07:01 +110015FEATURES=image-transfer,debug-commands
David Lattimoree36e52a2021-11-22 16:49:51 +110016if [ "$TFLM" != "0" ]; then
David Lattimoreeeb31152021-11-24 17:34:48 +110017 FEATURES+=,tflm
David Lattimoree36e52a2021-11-22 16:49:51 +110018fi
19
David Lattimore28a33812021-11-17 09:26:31 +110020cd "${PROJECT_ROOT}/rust/riscv"
David Lattimoree36e52a2021-11-22 16:49:51 +110021BUILD_FLAGS=(
22 -p fpga_rom
23 --release
24 --no-default-features
25 --features "${FEATURES}")
David Lattimore52cfefc2021-11-26 13:24:49 +110026
David Lattimore1d6660f2021-11-16 22:07:34 +110027cargo build "${BUILD_FLAGS[@]}"
David Lattimore52cfefc2021-11-26 13:24:49 +110028
29# We use our own version of objcopy rather than `cargo objcopy` because the
30# objcopy that comes with rust 1.55.0 seems to result in a non-functional 2.7MB
31# binary rather than a functional 0.7MB binary. Most likely the binary is
32# starting from address 0 rather than address 2M like it's supposed to. This
33# appears to have been fixed with rust 1.56, but we're not using that yet.
34"${PROJECT_ROOT}/third_party/installed/bin/riscv64-unknown-elf-objcopy" \
35 "target/riscv32i-unknown-none-elf/release/fpga_rom" \
36 -O binary \
37 "${ROM}"
38
David Lattimore60e282a2021-05-26 11:27:48 +100039"${PROJECT_ROOT}/scripts/hps-mon" \
40 --openocd-port 4444 \
41 --gateware "${PROJECT_ROOT}/build/hps_platform/gateware/hps_platform.bit" \
42 --soc-rom "${ROM}" \
43 --cmd 'reset_mcu; write_soc_rom; reset_fpga' \
44 "$@"