| 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' | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 22 |  | 
|  | 23 | if [ -r $CONFIG_H ]; then :; else | 
|  | 24 | echo "$CONFIG_H not found" >&2 | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 25 | echo "This script needs to be run from the root of" >&2 | 
|  | 26 | echo "a git checkout or uncompressed tarball" >&2 | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 27 | exit 1 | 
|  | 28 | fi | 
|  | 29 |  | 
|  | 30 | if grep -i cmake Makefile >/dev/null; then | 
|  | 31 | echo "Not compatible with CMake" >&2 | 
|  | 32 | exit 1 | 
|  | 33 | fi | 
|  | 34 |  | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 35 | if 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 | 
|  | 39 | fi | 
|  | 40 |  | 
|  | 41 | ARMGCC_FLAGS='-Os -march=armv7-m -mthumb' | 
|  | 42 | OUTFILE='00-footprint-summary.txt' | 
|  | 43 |  | 
|  | 44 | log() | 
|  | 45 | { | 
|  | 46 | echo "$@" | 
|  | 47 | echo "$@" >> "$OUTFILE" | 
|  | 48 | } | 
|  | 49 |  | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 50 | doit() | 
|  | 51 | { | 
|  | 52 | NAME="$1" | 
|  | 53 | FILE="$2" | 
|  | 54 |  | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 55 | log "" | 
|  | 56 | log "$NAME ($FILE):" | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 57 |  | 
|  | 58 | cp $CONFIG_H ${CONFIG_H}.bak | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 59 | if [ "$FILE" != $CONFIG_H ]; then | 
|  | 60 | cp "$FILE"  $CONFIG_H | 
|  | 61 | fi | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 62 |  | 
|  | 63 | { | 
| Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 64 | 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 | 
|  | 67 | scripts/config.py --force set MBEDTLS_NO_PLATFORM_ENTROPY || true | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 68 | } >/dev/null 2>&1 | 
|  | 69 |  | 
| Andres Amaya Garcia | 9a5398f | 2016-09-06 17:15:54 +0100 | [diff] [blame] | 70 | make clean >/dev/null | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 71 | 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] | 72 | CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 73 |  | 
|  | 74 | OUT="size-${NAME}.txt" | 
|  | 75 | arm-none-eabi-size -t library/libmbed*.a > "$OUT" | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 76 | log "$( head -n1 "$OUT" )" | 
|  | 77 | log "$( tail -n1 "$OUT" )" | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 78 |  | 
|  | 79 | cp ${CONFIG_H}.bak $CONFIG_H | 
|  | 80 | } | 
|  | 81 |  | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 82 | # truncate the file just this time | 
|  | 83 | echo "(generated by $0)" > "$OUTFILE" | 
|  | 84 | echo "" >> "$OUTFILE" | 
|  | 85 |  | 
| Andres AG | 788aa4a | 2016-09-14 14:32:09 +0100 | [diff] [blame] | 86 | 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] | 87 | log "for bare-metal ARM Cortex-M3/M4 microcontrollers." | 
|  | 88 |  | 
|  | 89 | VERSION_H="include/mbedtls/version.h" | 
|  | 90 | MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H ) | 
|  | 91 | if git rev-parse HEAD >/dev/null; then | 
|  | 92 | GIT_HEAD=$( git rev-parse HEAD | head -c 10 ) | 
| Manuel Pégourié-Gonnard | 3134ef0 | 2015-11-25 10:50:27 +0000 | [diff] [blame] | 93 | GIT_VERSION=" (git head: $GIT_HEAD)" | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 94 | else | 
|  | 95 | GIT_VERSION="" | 
|  | 96 | fi | 
|  | 97 |  | 
|  | 98 | log "" | 
| Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 99 | log "Mbed TLS $MBEDTLS_VERSION$GIT_VERSION" | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 100 | log "$( arm-none-eabi-gcc --version | head -n1 )" | 
|  | 101 | log "CFLAGS=$ARMGCC_FLAGS" | 
|  | 102 |  | 
| Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 103 | doit default    include/mbedtls/mbedtls_config.h | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 104 | doit thread     configs/config-thread.h | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 105 | doit suite-b    configs/config-suite-b.h | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 106 | doit psk        configs/config-ccm-psk-tls1_2.h | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 107 |  | 
|  | 108 | zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null |