| 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 | 
| Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 4 | # SPDX-License-Identifier: Apache-2.0 | 
|  | 5 | # | 
|  | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | 
|  | 7 | # not use this file except in compliance with the License. | 
|  | 8 | # You may obtain a copy of the License at | 
|  | 9 | # | 
|  | 10 | # http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 11 | # | 
|  | 12 | # Unless required by applicable law or agreed to in writing, software | 
|  | 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | 
|  | 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 15 | # See the License for the specific language governing permissions and | 
|  | 16 | # limitations under the License. | 
|  | 17 | # | 
| SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 18 | # Purpose | 
|  | 19 | # | 
| Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 20 | # This script determines ROM size (or code size) for the standard Mbed TLS | 
| SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 21 | # configurations, when built for a Cortex M3/M4 target. | 
|  | 22 | # | 
|  | 23 | # Configurations included: | 
| Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 24 | #   default    include/mbedtls/mbedtls_config.h | 
| SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 25 | #   thread     configs/config-thread.h | 
|  | 26 | #   suite-b    configs/config-suite-b.h | 
|  | 27 | #   psk        configs/config-ccm-psk-tls1_2.h | 
|  | 28 | # | 
|  | 29 | # Usage: footprint.sh | 
|  | 30 | # | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 31 | set -eu | 
|  | 32 |  | 
| Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 33 | CONFIG_H='include/mbedtls/mbedtls_config.h' | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 34 |  | 
|  | 35 | if [ -r $CONFIG_H ]; then :; else | 
|  | 36 | echo "$CONFIG_H not found" >&2 | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 37 | echo "This script needs to be run from the root of" >&2 | 
|  | 38 | echo "a git checkout or uncompressed tarball" >&2 | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 39 | exit 1 | 
|  | 40 | fi | 
|  | 41 |  | 
|  | 42 | if grep -i cmake Makefile >/dev/null; then | 
|  | 43 | echo "Not compatible with CMake" >&2 | 
|  | 44 | exit 1 | 
|  | 45 | fi | 
|  | 46 |  | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 47 | if which arm-none-eabi-gcc >/dev/null 2>&1; then :; else | 
|  | 48 | echo "You need the ARM-GCC toolchain in your path" >&2 | 
|  | 49 | echo "See https://launchpad.net/gcc-arm-embedded/" >&2 | 
|  | 50 | exit 1 | 
|  | 51 | fi | 
|  | 52 |  | 
|  | 53 | ARMGCC_FLAGS='-Os -march=armv7-m -mthumb' | 
|  | 54 | OUTFILE='00-footprint-summary.txt' | 
|  | 55 |  | 
|  | 56 | log() | 
|  | 57 | { | 
|  | 58 | echo "$@" | 
|  | 59 | echo "$@" >> "$OUTFILE" | 
|  | 60 | } | 
|  | 61 |  | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 62 | doit() | 
|  | 63 | { | 
|  | 64 | NAME="$1" | 
|  | 65 | FILE="$2" | 
|  | 66 |  | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 67 | log "" | 
|  | 68 | log "$NAME ($FILE):" | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 69 |  | 
|  | 70 | cp $CONFIG_H ${CONFIG_H}.bak | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 71 | if [ "$FILE" != $CONFIG_H ]; then | 
|  | 72 | cp "$FILE"  $CONFIG_H | 
|  | 73 | fi | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 74 |  | 
|  | 75 | { | 
| Gilles Peskine | 5d46f6a | 2019-07-27 23:52:53 +0200 | [diff] [blame] | 76 | scripts/config.py unset MBEDTLS_NET_C || true | 
|  | 77 | scripts/config.py unset MBEDTLS_TIMING_C || true | 
|  | 78 | scripts/config.py unset MBEDTLS_FS_IO || true | 
|  | 79 | scripts/config.py --force set MBEDTLS_NO_PLATFORM_ENTROPY || true | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 80 | } >/dev/null 2>&1 | 
|  | 81 |  | 
| Andres Amaya Garcia | 9a5398f | 2016-09-06 17:15:54 +0100 | [diff] [blame] | 82 | make clean >/dev/null | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 83 | 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] | 84 | CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 85 |  | 
|  | 86 | OUT="size-${NAME}.txt" | 
|  | 87 | arm-none-eabi-size -t library/libmbed*.a > "$OUT" | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 88 | log "$( head -n1 "$OUT" )" | 
|  | 89 | log "$( tail -n1 "$OUT" )" | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 90 |  | 
|  | 91 | cp ${CONFIG_H}.bak $CONFIG_H | 
|  | 92 | } | 
|  | 93 |  | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 94 | # truncate the file just this time | 
|  | 95 | echo "(generated by $0)" > "$OUTFILE" | 
|  | 96 | echo "" >> "$OUTFILE" | 
|  | 97 |  | 
| Andres AG | 788aa4a | 2016-09-14 14:32:09 +0100 | [diff] [blame] | 98 | 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] | 99 | log "for bare-metal ARM Cortex-M3/M4 microcontrollers." | 
|  | 100 |  | 
|  | 101 | VERSION_H="include/mbedtls/version.h" | 
|  | 102 | MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H ) | 
|  | 103 | if git rev-parse HEAD >/dev/null; then | 
|  | 104 | GIT_HEAD=$( git rev-parse HEAD | head -c 10 ) | 
| Manuel Pégourié-Gonnard | 3134ef0 | 2015-11-25 10:50:27 +0000 | [diff] [blame] | 105 | GIT_VERSION=" (git head: $GIT_HEAD)" | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 106 | else | 
|  | 107 | GIT_VERSION="" | 
|  | 108 | fi | 
|  | 109 |  | 
|  | 110 | log "" | 
| Gilles Peskine | e820c0a | 2023-08-03 17:45:20 +0200 | [diff] [blame] | 111 | log "Mbed TLS $MBEDTLS_VERSION$GIT_VERSION" | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 112 | log "$( arm-none-eabi-gcc --version | head -n1 )" | 
|  | 113 | log "CFLAGS=$ARMGCC_FLAGS" | 
|  | 114 |  | 
| Bence Szépkúti | bb0cfeb | 2021-05-28 09:42:25 +0200 | [diff] [blame] | 115 | doit default    include/mbedtls/mbedtls_config.h | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 116 | doit thread     configs/config-thread.h | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 117 | doit suite-b    configs/config-suite-b.h | 
| Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 118 | doit psk        configs/config-ccm-psk-tls1_2.h | 
| Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 119 |  | 
|  | 120 | zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null |