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 | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 4 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 5 | # |
| 6 | # This file is provided under the Apache License 2.0, or the |
| 7 | # GNU General Public License v2.0 or later. |
| 8 | # |
| 9 | # ********** |
| 10 | # Apache License 2.0: |
Bence Szépkúti | 09b4f19 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 11 | # |
| 12 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 13 | # not use this file except in compliance with the License. |
| 14 | # You may obtain a copy of the License at |
| 15 | # |
| 16 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | # |
| 18 | # Unless required by applicable law or agreed to in writing, software |
| 19 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 20 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 21 | # See the License for the specific language governing permissions and |
| 22 | # limitations under the License. |
| 23 | # |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 24 | # ********** |
| 25 | # |
| 26 | # ********** |
| 27 | # GNU General Public License v2.0 or later: |
| 28 | # |
| 29 | # This program is free software; you can redistribute it and/or modify |
| 30 | # it under the terms of the GNU General Public License as published by |
| 31 | # the Free Software Foundation; either version 2 of the License, or |
| 32 | # (at your option) any later version. |
| 33 | # |
| 34 | # This program is distributed in the hope that it will be useful, |
| 35 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 36 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 37 | # GNU General Public License for more details. |
| 38 | # |
| 39 | # You should have received a copy of the GNU General Public License along |
| 40 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 41 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 42 | # |
| 43 | # ********** |
| 44 | # |
Bence Szépkúti | 09b4f19 | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 45 | # This file is part of Mbed TLS (https://tls.mbed.org) |
SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 46 | # |
| 47 | # Purpose |
| 48 | # |
| 49 | # This script determines ROM size (or code size) for the standard mbed TLS |
| 50 | # configurations, when built for a Cortex M3/M4 target. |
| 51 | # |
| 52 | # Configurations included: |
| 53 | # default include/mbedtls/config.h |
| 54 | # yotta yotta/module/mbedtls/config.h |
| 55 | # thread configs/config-thread.h |
| 56 | # suite-b configs/config-suite-b.h |
| 57 | # psk configs/config-ccm-psk-tls1_2.h |
| 58 | # |
| 59 | # Usage: footprint.sh |
| 60 | # |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 61 | set -eu |
| 62 | |
| 63 | CONFIG_H='include/mbedtls/config.h' |
| 64 | |
| 65 | if [ -r $CONFIG_H ]; then :; else |
| 66 | echo "$CONFIG_H not found" >&2 |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 67 | echo "This script needs to be run from the root of" >&2 |
| 68 | echo "a git checkout or uncompressed tarball" >&2 |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 69 | exit 1 |
| 70 | fi |
| 71 | |
| 72 | if grep -i cmake Makefile >/dev/null; then |
| 73 | echo "Not compatible with CMake" >&2 |
| 74 | exit 1 |
| 75 | fi |
| 76 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 77 | if which arm-none-eabi-gcc >/dev/null 2>&1; then :; else |
| 78 | echo "You need the ARM-GCC toolchain in your path" >&2 |
| 79 | echo "See https://launchpad.net/gcc-arm-embedded/" >&2 |
| 80 | exit 1 |
| 81 | fi |
| 82 | |
| 83 | ARMGCC_FLAGS='-Os -march=armv7-m -mthumb' |
| 84 | OUTFILE='00-footprint-summary.txt' |
| 85 | |
| 86 | log() |
| 87 | { |
| 88 | echo "$@" |
| 89 | echo "$@" >> "$OUTFILE" |
| 90 | } |
| 91 | |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 92 | doit() |
| 93 | { |
| 94 | NAME="$1" |
| 95 | FILE="$2" |
| 96 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 97 | log "" |
| 98 | log "$NAME ($FILE):" |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 99 | |
| 100 | cp $CONFIG_H ${CONFIG_H}.bak |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 101 | if [ "$FILE" != $CONFIG_H ]; then |
| 102 | cp "$FILE" $CONFIG_H |
| 103 | fi |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 104 | |
| 105 | { |
| 106 | scripts/config.pl unset MBEDTLS_NET_C || true |
| 107 | scripts/config.pl unset MBEDTLS_TIMING_C || true |
| 108 | scripts/config.pl unset MBEDTLS_FS_IO || true |
SimonB | ba9dd1e | 2016-04-03 15:06:52 +0100 | [diff] [blame] | 109 | scripts/config.pl --force set MBEDTLS_NO_PLATFORM_ENTROPY || true |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 110 | } >/dev/null 2>&1 |
| 111 | |
Andres Amaya Garcia | 9a5398f | 2016-09-06 17:15:54 +0100 | [diff] [blame] | 112 | make clean >/dev/null |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 113 | 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] | 114 | CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 115 | |
| 116 | OUT="size-${NAME}.txt" |
| 117 | arm-none-eabi-size -t library/libmbed*.a > "$OUT" |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 118 | log "$( head -n1 "$OUT" )" |
| 119 | log "$( tail -n1 "$OUT" )" |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 120 | |
| 121 | cp ${CONFIG_H}.bak $CONFIG_H |
| 122 | } |
| 123 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 124 | # truncate the file just this time |
| 125 | echo "(generated by $0)" > "$OUTFILE" |
| 126 | echo "" >> "$OUTFILE" |
| 127 | |
Andres AG | 788aa4a | 2016-09-14 14:32:09 +0100 | [diff] [blame] | 128 | 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] | 129 | log "for bare-metal ARM Cortex-M3/M4 microcontrollers." |
| 130 | |
| 131 | VERSION_H="include/mbedtls/version.h" |
| 132 | MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H ) |
| 133 | if git rev-parse HEAD >/dev/null; then |
| 134 | GIT_HEAD=$( git rev-parse HEAD | head -c 10 ) |
Manuel Pégourié-Gonnard | 3134ef0 | 2015-11-25 10:50:27 +0000 | [diff] [blame] | 135 | GIT_VERSION=" (git head: $GIT_HEAD)" |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 136 | else |
| 137 | GIT_VERSION="" |
| 138 | fi |
| 139 | |
| 140 | log "" |
| 141 | log "mbed TLS $MBEDTLS_VERSION$GIT_VERSION" |
| 142 | log "$( arm-none-eabi-gcc --version | head -n1 )" |
| 143 | log "CFLAGS=$ARMGCC_FLAGS" |
| 144 | |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 145 | # creates the yotta config |
| 146 | yotta/create-module.sh >/dev/null |
| 147 | |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 148 | doit default include/mbedtls/config.h |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 149 | doit yotta yotta/module/mbedtls/config.h |
| 150 | doit thread configs/config-thread.h |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 151 | doit suite-b configs/config-suite-b.h |
Manuel Pégourié-Gonnard | ac8673c | 2015-10-16 13:03:04 +0200 | [diff] [blame] | 152 | doit psk configs/config-ccm-psk-tls1_2.h |
Manuel Pégourié-Gonnard | 4553a6c | 2015-11-25 10:39:00 +0000 | [diff] [blame] | 153 | |
| 154 | zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null |