blob: b550eaa3dc8c67ef8071e08a0c5d9e0005408215 [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
Alan Green9b7a93d2021-03-11 14:24:52 +110015STAGE0="${PROJECT_ROOT}/mcu_rom/stage0/target/thumbv6m-none-eabi/release/stage0.bin"
16STAGE1="${PROJECT_ROOT}/mcu_rom/stage1/target/thumbv6m-none-eabi/release/stage1.bin"
David Lattimore941f6b42021-04-26 15:53:01 +100017APPLICATION="${PROJECT_ROOT}/mcu_rom/stm32g0_application/target/thumbv6m-none-eabi/release/stm32g0_application.bin"
Alan Green9b7a93d2021-03-11 14:24:52 +110018(
19 cd "${PROJECT_ROOT}/mcu_rom/stage0"
Alan Green73b365c2021-05-05 20:22:37 +100020 cargo "+${RUST_VERSION}" build --release
Alan Green9b7a93d2021-03-11 14:24:52 +110021 arm-none-eabi-objcopy \
22 -O binary \
23 target/thumbv6m-none-eabi/release/stage0 \
Alan Green73b365c2021-05-05 20:22:37 +100024 "${STAGE0}"
Alan Green9b7a93d2021-03-11 14:24:52 +110025)
26(
27 cd "${PROJECT_ROOT}/mcu_rom/stage1"
Alan Green73b365c2021-05-05 20:22:37 +100028 cargo "+${RUST_VERSION}" build --release
Alan Green9b7a93d2021-03-11 14:24:52 +110029 arm-none-eabi-objcopy \
30 -O binary \
31 target/thumbv6m-none-eabi/release/stage1 \
Alan Green73b365c2021-05-05 20:22:37 +100032 "${STAGE1}"
Alan Green9b7a93d2021-03-11 14:24:52 +110033)
David Lattimorebcc2d842021-03-19 14:28:26 +110034(
David Lattimore941f6b42021-04-26 15:53:01 +100035 cd "${PROJECT_ROOT}/mcu_rom/stm32g0_application"
Alan Green73b365c2021-05-05 20:22:37 +100036 cargo "+${RUST_VERSION}" build --release
David Lattimorebcc2d842021-03-19 14:28:26 +110037 arm-none-eabi-objcopy \
38 -O binary \
David Lattimore941f6b42021-04-26 15:53:01 +100039 target/thumbv6m-none-eabi/release/stm32g0_application \
Alan Green73b365c2021-05-05 20:22:37 +100040 "${APPLICATION}"
David Lattimorebcc2d842021-03-19 14:28:26 +110041)
Alan Green9b7a93d2021-03-11 14:24:52 +110042echo
Alan Green73b365c2021-05-05 20:22:37 +100043STAGE0_SIZE=$(stat --printf='%s' "${STAGE0}")
44STAGE1_SIZE=$(stat --printf='%s' "${STAGE1}")
45APPLICATION_SIZE=$(stat --printf='%s' "${APPLICATION}")
Alan Green9b7a93d2021-03-11 14:24:52 +110046echo "Stage0: ${STAGE0_SIZE} bytes"
47echo "Stage1: ${STAGE1_SIZE} bytes"
David Lattimorebcc2d842021-03-19 14:28:26 +110048echo "Application: ${APPLICATION_SIZE} bytes"