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 | # |
| 3 | # This file is part of mbed TLS (https://tls.mbed.org) |
| 4 | # |
| 5 | # Copyright (c) 2015-2016, ARM Limited, All Rights Reserved |
| 6 | # |
| 7 | # Purpose |
| 8 | # |
| 9 | # This script determines ROM size (or code size) for the standard mbed TLS |
| 10 | # configurations, when built for a Cortex M3/M4 target. |
| 11 | # |
| 12 | # Configurations included: |
| 13 | # default include/mbedtls/config.h |
SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 14 | # thread configs/config-thread.h |
| 15 | # suite-b configs/config-suite-b.h |
| 16 | # psk configs/config-ccm-psk-tls1_2.h |
| 17 | # |
| 18 | # Usage: footprint.sh |
| 19 | # |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 20 | set -eu |
| 21 | |
| 22 | CONFIG_H='include/mbedtls/config.h' |
| 23 | |
| 24 | if [ -r $CONFIG_H ]; then :; else |
| 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 | |
| 31 | if grep -i cmake Makefile >/dev/null; then |
| 32 | echo "Not compatible with CMake" >&2 |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 36 | if which arm-none-eabi-gcc >/dev/null 2>&1; then :; else |
| 37 | echo "You need the ARM-GCC toolchain in your path" >&2 |
| 38 | echo "See https://launchpad.net/gcc-arm-embedded/" >&2 |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | ARMGCC_FLAGS='-Os -march=armv7-m -mthumb' |
| 43 | OUTFILE='00-footprint-summary.txt' |
| 44 | |
| 45 | log() |
| 46 | { |
| 47 | echo "$@" |
| 48 | echo "$@" >> "$OUTFILE" |
| 49 | } |
| 50 | |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 51 | doit() |
| 52 | { |
| 53 | NAME="$1" |
| 54 | FILE="$2" |
| 55 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 56 | log "" |
| 57 | log "$NAME ($FILE):" |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 58 | |
| 59 | cp $CONFIG_H ${CONFIG_H}.bak |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 60 | if [ "$FILE" != $CONFIG_H ]; then |
| 61 | cp "$FILE" $CONFIG_H |
| 62 | fi |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 63 | |
| 64 | { |
| 65 | scripts/config.pl unset MBEDTLS_NET_C || true |
| 66 | scripts/config.pl unset MBEDTLS_TIMING_C || true |
| 67 | scripts/config.pl unset MBEDTLS_FS_IO || true |
SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 68 | scripts/config.pl --force set MBEDTLS_NO_PLATFORM_ENTROPY || true |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 69 | } >/dev/null 2>&1 |
| 70 | |
Andres Amaya Garcia | 9a5398f | 2016-09-06 17:15:54 +0100 | [diff] [blame] | 71 | make clean >/dev/null |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 72 | 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] | 73 | CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 74 | |
| 75 | OUT="size-${NAME}.txt" |
| 76 | arm-none-eabi-size -t library/libmbed*.a > "$OUT" |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 77 | log "$( head -n1 "$OUT" )" |
| 78 | log "$( tail -n1 "$OUT" )" |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 79 | |
| 80 | cp ${CONFIG_H}.bak $CONFIG_H |
| 81 | } |
| 82 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 83 | # truncate the file just this time |
| 84 | echo "(generated by $0)" > "$OUTFILE" |
| 85 | echo "" >> "$OUTFILE" |
| 86 | |
Andres AG | 788aa4a | 2016-09-14 14:32:09 +0100 | [diff] [blame] | 87 | 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] | 88 | log "for bare-metal ARM Cortex-M3/M4 microcontrollers." |
| 89 | |
| 90 | VERSION_H="include/mbedtls/version.h" |
| 91 | MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H ) |
| 92 | if git rev-parse HEAD >/dev/null; then |
| 93 | GIT_HEAD=$( git rev-parse HEAD | head -c 10 ) |
Manuel Pégourié-Gonnard | 3134ef0 | 2015-11-25 10:50:27 +0000 | [diff] [blame] | 94 | GIT_VERSION=" (git head: $GIT_HEAD)" |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 95 | else |
| 96 | GIT_VERSION="" |
| 97 | fi |
| 98 | |
| 99 | log "" |
| 100 | log "mbed TLS $MBEDTLS_VERSION$GIT_VERSION" |
| 101 | log "$( arm-none-eabi-gcc --version | head -n1 )" |
| 102 | log "CFLAGS=$ARMGCC_FLAGS" |
| 103 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 104 | doit default include/mbedtls/config.h |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 105 | doit thread configs/config-thread.h |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 106 | doit suite-b configs/config-suite-b.h |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 107 | doit psk configs/config-ccm-psk-tls1_2.h |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 108 | |
| 109 | zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null |