David Lattimore | 60e282a | 2021-05-26 11:27:48 +1000 | [diff] [blame] | 1 | #!/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 | |
| 10 | set -e |
| 11 | |
| 12 | PROJECT_ROOT=$(git rev-parse --show-toplevel) |
| 13 | ROM="${PROJECT_ROOT}/build/hps_platform/soc_rom.bin" |
| 14 | |
David Lattimore | 8df3676 | 2021-11-24 16:07:01 +1100 | [diff] [blame] | 15 | FEATURES=image-transfer,debug-commands |
David Lattimore | e36e52a | 2021-11-22 16:49:51 +1100 | [diff] [blame] | 16 | if [ "$TFLM" != "0" ]; then |
David Lattimore | eeb3115 | 2021-11-24 17:34:48 +1100 | [diff] [blame] | 17 | FEATURES+=,tflm |
David Lattimore | e36e52a | 2021-11-22 16:49:51 +1100 | [diff] [blame] | 18 | fi |
| 19 | |
David Lattimore | 28a3381 | 2021-11-17 09:26:31 +1100 | [diff] [blame] | 20 | cd "${PROJECT_ROOT}/rust/riscv" |
David Lattimore | e36e52a | 2021-11-22 16:49:51 +1100 | [diff] [blame] | 21 | BUILD_FLAGS=( |
| 22 | -p fpga_rom |
| 23 | --release |
| 24 | --no-default-features |
| 25 | --features "${FEATURES}") |
David Lattimore | 52cfefc | 2021-11-26 13:24:49 +1100 | [diff] [blame] | 26 | |
David Lattimore | 1d6660f | 2021-11-16 22:07:34 +1100 | [diff] [blame] | 27 | cargo build "${BUILD_FLAGS[@]}" |
David Lattimore | 52cfefc | 2021-11-26 13:24:49 +1100 | [diff] [blame] | 28 | |
| 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 Lattimore | 60e282a | 2021-05-26 11:27:48 +1000 | [diff] [blame] | 39 | "${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 | "$@" |