David Lattimore | 42b2bb1 | 2022-01-06 08:58:29 +1100 | [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 the Rust FPGA ROM. |
| 8 | |
| 9 | set -e |
| 10 | |
| 11 | PROJECT_ROOT=$(git rev-parse --show-toplevel) |
| 12 | ROM="${PROJECT_ROOT}/build/hps_platform/fpga_rom.bin" |
| 13 | |
David Lattimore | 3e6d4f1 | 2022-07-18 11:58:13 +1000 | [diff] [blame] | 14 | # If we're outside the chroot, rerun inside. |
| 15 | if [ ! -e /etc/cros_chroot_version ] ; then |
| 16 | exec "${PROJECT_ROOT}/scripts/run-tool" "$0" "$@" |
| 17 | fi |
| 18 | |
David Lattimore | 42b2bb1 | 2022-01-06 08:58:29 +1100 | [diff] [blame] | 19 | FEATURES="${FEATURES-tflm}" |
David Lattimore | 5112466 | 2022-07-28 14:33:01 +1000 | [diff] [blame] | 20 | PROFILE="${PROFILE-release}" |
David Lattimore | 42b2bb1 | 2022-01-06 08:58:29 +1100 | [diff] [blame] | 21 | |
Dan Callaghan | 30a4ee2 | 2022-01-10 19:16:25 +1100 | [diff] [blame] | 22 | source "${PROJECT_ROOT}/environment" |
| 23 | |
David Lattimore | 42b2bb1 | 2022-01-06 08:58:29 +1100 | [diff] [blame] | 24 | cd "${PROJECT_ROOT}/rust/riscv" |
| 25 | BUILD_FLAGS=( |
| 26 | -p fpga_rom |
David Lattimore | 5112466 | 2022-07-28 14:33:01 +1000 | [diff] [blame] | 27 | --profile "${PROFILE}" |
David Lattimore | 42b2bb1 | 2022-01-06 08:58:29 +1100 | [diff] [blame] | 28 | --no-default-features |
| 29 | --features "${FEATURES}") |
| 30 | |
| 31 | cargo build "${BUILD_FLAGS[@]}" |
| 32 | |
David Lattimore | 5112466 | 2022-07-28 14:33:01 +1000 | [diff] [blame] | 33 | # For the dev profile, cargo outputs to "debug". For "release" and any custom |
| 34 | # profiles it outputs to the profile name. |
| 35 | if [[ "${PROFILE}" == "dev" ]]; then |
| 36 | PROFILE_OUT="debug" |
| 37 | else |
| 38 | PROFILE_OUT="${PROFILE}" |
| 39 | fi |
| 40 | |
David Lattimore | c4bf2a3 | 2022-07-18 14:04:18 +1000 | [diff] [blame] | 41 | llvm-objcopy \ |
David Lattimore | 5112466 | 2022-07-28 14:33:01 +1000 | [diff] [blame] | 42 | "target/riscv32i-unknown-none-elf/${PROFILE_OUT}/fpga_rom" \ |
David Lattimore | 42b2bb1 | 2022-01-06 08:58:29 +1100 | [diff] [blame] | 43 | -O binary \ |
| 44 | "${ROM}" |