blob: 0c60be6a9418988532e6f29e70e4edd677e1d454 [file] [log] [blame]
Alan Green9b7a93d2021-03-11 14:24:52 +11001#!/bin/bash
2
Alan Green73b365c2021-05-05 20:22:37 +10003# 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
Alan Green9b7a93d2021-03-11 14:24:52 +11007# Builds code and prints binary sizes. For now, this only reports sizes of MCU
8# binaries as that is by far the most space-constrained.
9
Alan Green73b365c2021-05-05 20:22:37 +100010PROJECT_ROOT=$(realpath "$(dirname "${BASH_SOURCE[0]}")"/..)
David Lattimorebcc2d842021-03-19 14:28:26 +110011
Alan Green73b365c2021-05-05 20:22:37 +100012source "${PROJECT_ROOT}/environment"
David Lattimorebcc2d842021-03-19 14:28:26 +110013
14set -e
David Lattimore417ea752021-11-17 10:26:52 +110015STAGE0="${PROJECT_ROOT}/rust/mcu/stage0/target/thumbv6m-none-eabi/release/stage0.bin"
16APPLICATION="${PROJECT_ROOT}/rust/mcu/stage1_app/target/thumbv6m-none-eabi/release/stage1_app.bin"
Alan Green9b7a93d2021-03-11 14:24:52 +110017(
David Lattimore417ea752021-11-17 10:26:52 +110018 cd "${PROJECT_ROOT}/rust/mcu/stage0"
Alan Green73b365c2021-05-05 20:22:37 +100019 cargo "+${RUST_VERSION}" build --release
Alan Green9b7a93d2021-03-11 14:24:52 +110020 arm-none-eabi-objcopy \
21 -O binary \
22 target/thumbv6m-none-eabi/release/stage0 \
Alan Green73b365c2021-05-05 20:22:37 +100023 "${STAGE0}"
Alan Green9b7a93d2021-03-11 14:24:52 +110024)
25(
David Lattimore417ea752021-11-17 10:26:52 +110026 cd "${PROJECT_ROOT}/rust/mcu/stage1_app"
Alan Green73b365c2021-05-05 20:22:37 +100027 cargo "+${RUST_VERSION}" build --release
David Lattimorebcc2d842021-03-19 14:28:26 +110028 arm-none-eabi-objcopy \
29 -O binary \
Edward O'Callaghan94002392021-09-27 14:49:13 +100030 target/thumbv6m-none-eabi/release/stage1_app \
Alan Green73b365c2021-05-05 20:22:37 +100031 "${APPLICATION}"
David Lattimorebcc2d842021-03-19 14:28:26 +110032)
Alan Green9b7a93d2021-03-11 14:24:52 +110033echo
Alan Green73b365c2021-05-05 20:22:37 +100034STAGE0_SIZE=$(stat --printf='%s' "${STAGE0}")
Alan Green73b365c2021-05-05 20:22:37 +100035APPLICATION_SIZE=$(stat --printf='%s' "${APPLICATION}")
Alan Green9b7a93d2021-03-11 14:24:52 +110036echo "Stage0: ${STAGE0_SIZE} bytes"
David Lattimorebcc2d842021-03-19 14:28:26 +110037echo "Application: ${APPLICATION_SIZE} bytes"