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