Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 1 | #!/bin/sh |
SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 2 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 3 | # Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 4 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 5 | # |
SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 6 | # Purpose |
| 7 | # |
Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 8 | # This script determines ROM size (or code size) for the standard Mbed TLS |
SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 9 | # configurations, when built for a Cortex M3/M4 target. |
| 10 | # |
| 11 | # Configurations included: |
Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 12 | # default include/mbedtls/mbedtls_config.h |
SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 13 | # 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é-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 19 | set -eu |
| 20 | |
Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 21 | CONFIG_H='include/mbedtls/mbedtls_config.h' |
Ronald Cron | b01be14 | 2025-09-10 12:01:52 +0200 | [diff] [blame] | 22 | CRYPTO_CONFIG_H='tf-psa-crypto/include/psa/crypto_config.h' |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 23 | |
Ronald Cron | 9a10e39 | 2025-09-10 17:08:12 +0200 | [diff] [blame^] | 24 | if [ ! -r $CONFIG_H ]; then |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 25 | echo "$CONFIG_H not found" >&2 |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 26 | echo "This script needs to be run from the root of" >&2 |
| 27 | echo "a git checkout or uncompressed tarball" >&2 |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 28 | exit 1 |
| 29 | fi |
| 30 | |
Ronald Cron | 9a10e39 | 2025-09-10 17:08:12 +0200 | [diff] [blame^] | 31 | if [ ! -r $CRYPTO_CONFIG_H ]; then |
Ronald Cron | b01be14 | 2025-09-10 12:01:52 +0200 | [diff] [blame] | 32 | 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 |
| 36 | fi |
| 37 | |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 38 | if grep -i cmake Makefile >/dev/null; then |
| 39 | echo "Not compatible with CMake" >&2 |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 43 | if 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 |
| 47 | fi |
| 48 | |
| 49 | ARMGCC_FLAGS='-Os -march=armv7-m -mthumb' |
| 50 | OUTFILE='00-footprint-summary.txt' |
| 51 | |
| 52 | log() |
| 53 | { |
| 54 | echo "$@" |
| 55 | echo "$@" >> "$OUTFILE" |
| 56 | } |
| 57 | |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 58 | doit() |
| 59 | { |
| 60 | NAME="$1" |
| 61 | FILE="$2" |
| 62 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 63 | log "" |
| 64 | log "$NAME ($FILE):" |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 65 | |
| 66 | cp $CONFIG_H ${CONFIG_H}.bak |
Ronald Cron | b01be14 | 2025-09-10 12:01:52 +0200 | [diff] [blame] | 67 | cp $CRYPTO_CONFIG_H ${CRYPTO_CONFIG_H}.bak |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 68 | if [ "$FILE" != $CONFIG_H ]; then |
Ronald Cron | b01be14 | 2025-09-10 12:01:52 +0200 | [diff] [blame] | 69 | CRYPTO_FILE="${FILE%/*}/crypto-${FILE##*/}" |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 70 | cp "$FILE" $CONFIG_H |
Ronald Cron | b01be14 | 2025-09-10 12:01:52 +0200 | [diff] [blame] | 71 | cp "$CRYPTO_FILE" $CRYPTO_CONFIG_H |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 72 | fi |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 73 | |
| 74 | { |
Ronald Cron | b01be14 | 2025-09-10 12:01:52 +0200 | [diff] [blame] | 75 | scripts/config.py unset MBEDTLS_HAVE_TIME || true |
| 76 | scripts/config.py unset MBEDTLS_HAVE_TIME_DATE || true |
Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 77 | 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 Cron | b01be14 | 2025-09-10 12:01:52 +0200 | [diff] [blame] | 80 | scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C || true |
| 81 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C || true |
Ronald Cron | eb16a9d | 2025-09-03 09:57:29 +0200 | [diff] [blame] | 82 | scripts/config.py unset MBEDTLS_PSA_BUILTIN_GET_ENTROPY || true |
Ronald Cron | b01be14 | 2025-09-10 12:01:52 +0200 | [diff] [blame] | 83 | # 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é-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 86 | } >/dev/null 2>&1 |
| 87 | |
Andres Amaya Garcia | 9a5398f | 2016-09-06 17:15:54 +0100 | [diff] [blame] | 88 | make clean >/dev/null |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 89 | CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld \ |
Andres Amaya Garcia | 9a5398f | 2016-09-06 17:15:54 +0100 | [diff] [blame] | 90 | CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 91 | |
| 92 | OUT="size-${NAME}.txt" |
| 93 | arm-none-eabi-size -t library/libmbed*.a > "$OUT" |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 94 | log "$( head -n1 "$OUT" )" |
| 95 | log "$( tail -n1 "$OUT" )" |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 96 | |
Ronald Cron | b01be14 | 2025-09-10 12:01:52 +0200 | [diff] [blame] | 97 | mv ${CONFIG_H}.bak $CONFIG_H |
| 98 | mv ${CRYPTO_CONFIG_H}.bak $CRYPTO_CONFIG_H |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 101 | # truncate the file just this time |
| 102 | echo "(generated by $0)" > "$OUTFILE" |
| 103 | echo "" >> "$OUTFILE" |
| 104 | |
Andres AG | 788aa4a | 2016-09-14 14:32:09 +0100 | [diff] [blame] | 105 | log "Footprint of standard configurations (minus net_sockets.c, timing.c, fs_io)" |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 106 | log "for bare-metal ARM Cortex-M3/M4 microcontrollers." |
| 107 | |
| 108 | VERSION_H="include/mbedtls/version.h" |
| 109 | MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H ) |
| 110 | if git rev-parse HEAD >/dev/null; then |
| 111 | GIT_HEAD=$( git rev-parse HEAD | head -c 10 ) |
Manuel Pégourié-Gonnard | 3134ef0 | 2015-11-25 10:50:27 +0000 | [diff] [blame] | 112 | GIT_VERSION=" (git head: $GIT_HEAD)" |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 113 | else |
| 114 | GIT_VERSION="" |
| 115 | fi |
| 116 | |
| 117 | log "" |
Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 118 | log "Mbed TLS $MBEDTLS_VERSION$GIT_VERSION" |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 119 | log "$( arm-none-eabi-gcc --version | head -n1 )" |
| 120 | log "CFLAGS=$ARMGCC_FLAGS" |
| 121 | |
Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 122 | doit default include/mbedtls/mbedtls_config.h |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 123 | doit thread configs/config-thread.h |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 124 | doit suite-b configs/config-suite-b.h |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 125 | doit psk configs/config-ccm-psk-tls1_2.h |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 126 | |
| 127 | zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null |