blob: b69e053ab74725638321a200dd73429ccf5340c2 [file] [log] [blame]
David Lattimore42b2bb12022-01-06 08:58:29 +11001#!/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
9set -e
10
11PROJECT_ROOT=$(git rev-parse --show-toplevel)
12ROM="${PROJECT_ROOT}/build/hps_platform/fpga_rom.bin"
13
David Lattimore3e6d4f12022-07-18 11:58:13 +100014# If we're outside the chroot, rerun inside.
15if [ ! -e /etc/cros_chroot_version ] ; then
16 exec "${PROJECT_ROOT}/scripts/run-tool" "$0" "$@"
17fi
18
David Lattimore42b2bb12022-01-06 08:58:29 +110019FEATURES="${FEATURES-tflm}"
David Lattimore51124662022-07-28 14:33:01 +100020PROFILE="${PROFILE-release}"
David Lattimore42b2bb12022-01-06 08:58:29 +110021
Dan Callaghan30a4ee22022-01-10 19:16:25 +110022source "${PROJECT_ROOT}/environment"
23
David Lattimore42b2bb12022-01-06 08:58:29 +110024cd "${PROJECT_ROOT}/rust/riscv"
25BUILD_FLAGS=(
26 -p fpga_rom
David Lattimore51124662022-07-28 14:33:01 +100027 --profile "${PROFILE}"
David Lattimore42b2bb12022-01-06 08:58:29 +110028 --no-default-features
29 --features "${FEATURES}")
30
31cargo build "${BUILD_FLAGS[@]}"
32
David Lattimore51124662022-07-28 14:33:01 +100033# For the dev profile, cargo outputs to "debug". For "release" and any custom
34# profiles it outputs to the profile name.
35if [[ "${PROFILE}" == "dev" ]]; then
36 PROFILE_OUT="debug"
37else
38 PROFILE_OUT="${PROFILE}"
39fi
40
David Lattimorec4bf2a32022-07-18 14:04:18 +100041llvm-objcopy \
David Lattimore51124662022-07-28 14:33:01 +100042 "target/riscv32i-unknown-none-elf/${PROFILE_OUT}/fpga_rom" \
David Lattimore42b2bb12022-01-06 08:58:29 +110043 -O binary \
44 "${ROM}"