1#!/bin/sh 2# 3# Copyright The Mbed TLS Contributors 4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 5# 6# Purpose 7# 8# This script determines ROM size (or code size) for the standard Mbed TLS 9# configurations, when built for a Cortex M3/M4 target. 10# 11# Configurations included: 12# default include/mbedtls/mbedtls_config.h 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# 19set -eu 20 21CONFIG_H='include/mbedtls/mbedtls_config.h' 22 23if [ -r $CONFIG_H ]; then :; else 24 echo "$CONFIG_H not found" >&2 25 echo "This script needs to be run from the root of" >&2 26 echo "a git checkout or uncompressed tarball" >&2 27 exit 1 28fi 29 30if grep -i cmake Makefile >/dev/null; then 31 echo "Not compatible with CMake" >&2 32 exit 1 33fi 34 35if 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 39fi 40 41ARMGCC_FLAGS='-Os -march=armv7-m -mthumb' 42OUTFILE='00-footprint-summary.txt' 43 44log() 45{ 46 echo "$@" 47 echo "$@" >> "$OUTFILE" 48} 49 50doit() 51{ 52 NAME="$1" 53 FILE="$2" 54 55 log "" 56 log "$NAME ($FILE):" 57 58 cp $CONFIG_H ${CONFIG_H}.bak 59 if [ "$FILE" != $CONFIG_H ]; then 60 cp "$FILE" $CONFIG_H 61 fi 62 63 { 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 68 } >/dev/null 2>&1 69 70 make clean >/dev/null 71 CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld \ 72 CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null 73 74 OUT="size-${NAME}.txt" 75 arm-none-eabi-size -t library/libmbed*.a > "$OUT" 76 log "$( head -n1 "$OUT" )" 77 log "$( tail -n1 "$OUT" )" 78 79 cp ${CONFIG_H}.bak $CONFIG_H 80} 81 82# truncate the file just this time 83echo "(generated by $0)" > "$OUTFILE" 84echo "" >> "$OUTFILE" 85 86log "Footprint of standard configurations (minus net_sockets.c, timing.c, fs_io)" 87log "for bare-metal ARM Cortex-M3/M4 microcontrollers." 88 89VERSION_H="include/mbedtls/version.h" 90MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H ) 91if git rev-parse HEAD >/dev/null; then 92 GIT_HEAD=$( git rev-parse HEAD | head -c 10 ) 93 GIT_VERSION=" (git head: $GIT_HEAD)" 94else 95 GIT_VERSION="" 96fi 97 98log "" 99log "Mbed TLS $MBEDTLS_VERSION$GIT_VERSION" 100log "$( arm-none-eabi-gcc --version | head -n1 )" 101log "CFLAGS=$ARMGCC_FLAGS" 102 103doit default include/mbedtls/mbedtls_config.h 104doit thread configs/config-thread.h 105doit suite-b configs/config-suite-b.h 106doit psk configs/config-ccm-psk-tls1_2.h 107 108zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null 109