blob: e45a9265ac773f80762b829eb47f64f3f1ea7b15 [file] [log] [blame]
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +02001#!/bin/sh
SimonBba9dd1e2016-04-03 15:06:52 +01002#
Bence Szépkúti1e148272020-08-07 13:07:28 +02003# Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00004# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02005#
SimonBba9dd1e2016-04-03 15:06:52 +01006# Purpose
7#
Gilles Peskinee820c0a2023-08-03 17:45:20 +02008# This script determines ROM size (or code size) for the standard Mbed TLS
SimonBba9dd1e2016-04-03 15:06:52 +01009# configurations, when built for a Cortex M3/M4 target.
10#
11# Configurations included:
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020012# default include/mbedtls/mbedtls_config.h
SimonBba9dd1e2016-04-03 15:06:52 +010013# thread configs/config-thread.h
14# suite-b configs/config-suite-b.h
15# psk configs/config-ccm-psk-tls1_2.h
16#
17# Usage: footprint.sh
18#
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020019set -eu
20
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020021CONFIG_H='include/mbedtls/mbedtls_config.h'
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020022
23if [ -r $CONFIG_H ]; then :; else
24 echo "$CONFIG_H not found" >&2
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000025 echo "This script needs to be run from the root of" >&2
26 echo "a git checkout or uncompressed tarball" >&2
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020027 exit 1
28fi
29
30if grep -i cmake Makefile >/dev/null; then
31 echo "Not compatible with CMake" >&2
32 exit 1
33fi
34
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000035if which arm-none-eabi-gcc >/dev/null 2>&1; then :; else
36 echo "You need the ARM-GCC toolchain in your path" >&2
37 echo "See https://launchpad.net/gcc-arm-embedded/" >&2
38 exit 1
39fi
40
41ARMGCC_FLAGS='-Os -march=armv7-m -mthumb'
42OUTFILE='00-footprint-summary.txt'
43
44log()
45{
46 echo "$@"
47 echo "$@" >> "$OUTFILE"
48}
49
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020050doit()
51{
52 NAME="$1"
53 FILE="$2"
54
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000055 log ""
56 log "$NAME ($FILE):"
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020057
58 cp $CONFIG_H ${CONFIG_H}.bak
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000059 if [ "$FILE" != $CONFIG_H ]; then
60 cp "$FILE" $CONFIG_H
61 fi
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020062
63 {
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020064 scripts/config.py unset MBEDTLS_NET_C || true
65 scripts/config.py unset MBEDTLS_TIMING_C || true
66 scripts/config.py unset MBEDTLS_FS_IO || true
Valerio Setti73bd2102025-04-15 08:56:51 +020067 scripts/config.py --force set MBEDTLS_PLATFORM_GET_ENTROPY_ALT || true
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020068 } >/dev/null 2>&1
69
Andres Amaya Garcia9a5398f2016-09-06 17:15:54 +010070 make clean >/dev/null
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020071 CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld \
Andres Amaya Garcia9a5398f2016-09-06 17:15:54 +010072 CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020073
74 OUT="size-${NAME}.txt"
75 arm-none-eabi-size -t library/libmbed*.a > "$OUT"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000076 log "$( head -n1 "$OUT" )"
77 log "$( tail -n1 "$OUT" )"
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020078
79 cp ${CONFIG_H}.bak $CONFIG_H
80}
81
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000082# truncate the file just this time
83echo "(generated by $0)" > "$OUTFILE"
84echo "" >> "$OUTFILE"
85
Andres AG788aa4a2016-09-14 14:32:09 +010086log "Footprint of standard configurations (minus net_sockets.c, timing.c, fs_io)"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000087log "for bare-metal ARM Cortex-M3/M4 microcontrollers."
88
89VERSION_H="include/mbedtls/version.h"
90MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H )
91if git rev-parse HEAD >/dev/null; then
92 GIT_HEAD=$( git rev-parse HEAD | head -c 10 )
Manuel Pégourié-Gonnard3134ef02015-11-25 10:50:27 +000093 GIT_VERSION=" (git head: $GIT_HEAD)"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000094else
95 GIT_VERSION=""
96fi
97
98log ""
Gilles Peskinee820c0a2023-08-03 17:45:20 +020099log "Mbed TLS $MBEDTLS_VERSION$GIT_VERSION"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000100log "$( arm-none-eabi-gcc --version | head -n1 )"
101log "CFLAGS=$ARMGCC_FLAGS"
102
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +0200103doit default include/mbedtls/mbedtls_config.h
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +0200104doit thread configs/config-thread.h
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000105doit suite-b configs/config-suite-b.h
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +0200106doit psk configs/config-ccm-psk-tls1_2.h
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000107
108zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null