blob: 1f2945159e2d5de68c718f5c06d9aa386e4de7d4 [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'
Ronald Cronb01be142025-09-10 12:01:52 +020022CRYPTO_CONFIG_H='tf-psa-crypto/include/psa/crypto_config.h'
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020023
Ronald Cron9a10e392025-09-10 17:08:12 +020024if [ ! -r $CONFIG_H ]; then
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020025 echo "$CONFIG_H not found" >&2
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000026 echo "This script needs to be run from the root of" >&2
27 echo "a git checkout or uncompressed tarball" >&2
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020028 exit 1
29fi
30
Ronald Cron9a10e392025-09-10 17:08:12 +020031if [ ! -r $CRYPTO_CONFIG_H ]; then
Ronald Cronb01be142025-09-10 12:01:52 +020032 echo "$CRYPTO_CONFIG_H not found" >&2
33 echo "This script needs to be run from the root of" >&2
34 echo "a git checkout or uncompressed tarball" >&2
35 exit 1
36fi
37
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020038if grep -i cmake Makefile >/dev/null; then
39 echo "Not compatible with CMake" >&2
40 exit 1
41fi
42
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000043if which arm-none-eabi-gcc >/dev/null 2>&1; then :; else
44 echo "You need the ARM-GCC toolchain in your path" >&2
45 echo "See https://launchpad.net/gcc-arm-embedded/" >&2
46 exit 1
47fi
48
49ARMGCC_FLAGS='-Os -march=armv7-m -mthumb'
50OUTFILE='00-footprint-summary.txt'
51
52log()
53{
54 echo "$@"
55 echo "$@" >> "$OUTFILE"
56}
57
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020058doit()
59{
60 NAME="$1"
61 FILE="$2"
62
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000063 log ""
64 log "$NAME ($FILE):"
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020065
66 cp $CONFIG_H ${CONFIG_H}.bak
Ronald Cronb01be142025-09-10 12:01:52 +020067 cp $CRYPTO_CONFIG_H ${CRYPTO_CONFIG_H}.bak
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000068 if [ "$FILE" != $CONFIG_H ]; then
Ronald Cronb01be142025-09-10 12:01:52 +020069 CRYPTO_FILE="${FILE%/*}/crypto-${FILE##*/}"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000070 cp "$FILE" $CONFIG_H
Ronald Cronb01be142025-09-10 12:01:52 +020071 cp "$CRYPTO_FILE" $CRYPTO_CONFIG_H
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000072 fi
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020073
74 {
Ronald Cronb01be142025-09-10 12:01:52 +020075 scripts/config.py unset MBEDTLS_HAVE_TIME || true
76 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE || true
Gilles Peskine5d46f6a2019-07-27 23:52:53 +020077 scripts/config.py unset MBEDTLS_NET_C || true
78 scripts/config.py unset MBEDTLS_TIMING_C || true
79 scripts/config.py unset MBEDTLS_FS_IO || true
Ronald Cronb01be142025-09-10 12:01:52 +020080 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C || true
81 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C || true
Ronald Croneb16a9d2025-09-03 09:57:29 +020082 scripts/config.py unset MBEDTLS_PSA_BUILTIN_GET_ENTROPY || true
Ronald Cronb01be142025-09-10 12:01:52 +020083 # Force the definition of MBEDTLS_PSA_DRIVER_GET_ENTROPY as it may
84 # not exist in custom configurations.
85 scripts/config.py --force -f ${CRYPTO_CONFIG_H} set MBEDTLS_PSA_DRIVER_GET_ENTROPY || true
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020086 } >/dev/null 2>&1
87
Andres Amaya Garcia9a5398f2016-09-06 17:15:54 +010088 make clean >/dev/null
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020089 CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld \
Andres Amaya Garcia9a5398f2016-09-06 17:15:54 +010090 CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020091
92 OUT="size-${NAME}.txt"
93 arm-none-eabi-size -t library/libmbed*.a > "$OUT"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000094 log "$( head -n1 "$OUT" )"
95 log "$( tail -n1 "$OUT" )"
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020096
Ronald Cronb01be142025-09-10 12:01:52 +020097 mv ${CONFIG_H}.bak $CONFIG_H
98 mv ${CRYPTO_CONFIG_H}.bak $CRYPTO_CONFIG_H
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020099}
100
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000101# truncate the file just this time
102echo "(generated by $0)" > "$OUTFILE"
103echo "" >> "$OUTFILE"
104
Andres AG788aa4a2016-09-14 14:32:09 +0100105log "Footprint of standard configurations (minus net_sockets.c, timing.c, fs_io)"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000106log "for bare-metal ARM Cortex-M3/M4 microcontrollers."
107
108VERSION_H="include/mbedtls/version.h"
109MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H )
110if git rev-parse HEAD >/dev/null; then
111 GIT_HEAD=$( git rev-parse HEAD | head -c 10 )
Manuel Pégourié-Gonnard3134ef02015-11-25 10:50:27 +0000112 GIT_VERSION=" (git head: $GIT_HEAD)"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000113else
114 GIT_VERSION=""
115fi
116
117log ""
Gilles Peskinee820c0a2023-08-03 17:45:20 +0200118log "Mbed TLS $MBEDTLS_VERSION$GIT_VERSION"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000119log "$( arm-none-eabi-gcc --version | head -n1 )"
120log "CFLAGS=$ARMGCC_FLAGS"
121
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +0200122doit default include/mbedtls/mbedtls_config.h
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +0200123doit thread configs/config-thread.h
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000124doit suite-b configs/config-suite-b.h
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +0200125doit psk configs/config-ccm-psk-tls1_2.h
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000126
127zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null