blob: d38e50af2728dd0f9c2b32224b62266f3a451055 [file] [log] [blame]
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +02001#!/bin/sh
SimonBba9dd1e2016-04-03 15:06:52 +01002#
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
14# yotta yotta/module/mbedtls/config.h
15# thread configs/config-thread.h
16# suite-b configs/config-suite-b.h
17# psk configs/config-ccm-psk-tls1_2.h
18#
19# Usage: footprint.sh
20#
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020021set -eu
22
23CONFIG_H='include/mbedtls/config.h'
24
25if [ -r $CONFIG_H ]; then :; else
26 echo "$CONFIG_H not found" >&2
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000027 echo "This script needs to be run from the root of" >&2
28 echo "a git checkout or uncompressed tarball" >&2
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020029 exit 1
30fi
31
32if grep -i cmake Makefile >/dev/null; then
33 echo "Not compatible with CMake" >&2
34 exit 1
35fi
36
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000037if which arm-none-eabi-gcc >/dev/null 2>&1; then :; else
38 echo "You need the ARM-GCC toolchain in your path" >&2
39 echo "See https://launchpad.net/gcc-arm-embedded/" >&2
40 exit 1
41fi
42
43ARMGCC_FLAGS='-Os -march=armv7-m -mthumb'
44OUTFILE='00-footprint-summary.txt'
45
46log()
47{
48 echo "$@"
49 echo "$@" >> "$OUTFILE"
50}
51
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020052doit()
53{
54 NAME="$1"
55 FILE="$2"
56
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000057 log ""
58 log "$NAME ($FILE):"
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020059
60 cp $CONFIG_H ${CONFIG_H}.bak
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000061 if [ "$FILE" != $CONFIG_H ]; then
62 cp "$FILE" $CONFIG_H
63 fi
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020064
65 {
66 scripts/config.pl unset MBEDTLS_NET_C || true
67 scripts/config.pl unset MBEDTLS_TIMING_C || true
68 scripts/config.pl unset MBEDTLS_FS_IO || true
SimonBba9dd1e2016-04-03 15:06:52 +010069 scripts/config.pl --force set MBEDTLS_NO_PLATFORM_ENTROPY || true
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020070 } >/dev/null 2>&1
71
Andres Amaya Garcia9a5398f2016-09-06 17:15:54 +010072 make clean >/dev/null
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020073 CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld \
Andres Amaya Garcia9a5398f2016-09-06 17:15:54 +010074 CFLAGS="$ARMGCC_FLAGS" make lib >/dev/null
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020075
76 OUT="size-${NAME}.txt"
77 arm-none-eabi-size -t library/libmbed*.a > "$OUT"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000078 log "$( head -n1 "$OUT" )"
79 log "$( tail -n1 "$OUT" )"
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +020080
81 cp ${CONFIG_H}.bak $CONFIG_H
82}
83
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000084# truncate the file just this time
85echo "(generated by $0)" > "$OUTFILE"
86echo "" >> "$OUTFILE"
87
Andres AG788aa4a2016-09-14 14:32:09 +010088log "Footprint of standard configurations (minus net_sockets.c, timing.c, fs_io)"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000089log "for bare-metal ARM Cortex-M3/M4 microcontrollers."
90
91VERSION_H="include/mbedtls/version.h"
92MBEDTLS_VERSION=$( sed -n 's/.*VERSION_STRING *"\(.*\)"/\1/p' $VERSION_H )
93if git rev-parse HEAD >/dev/null; then
94 GIT_HEAD=$( git rev-parse HEAD | head -c 10 )
Manuel Pégourié-Gonnard3134ef02015-11-25 10:50:27 +000095 GIT_VERSION=" (git head: $GIT_HEAD)"
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +000096else
97 GIT_VERSION=""
98fi
99
100log ""
101log "mbed TLS $MBEDTLS_VERSION$GIT_VERSION"
102log "$( arm-none-eabi-gcc --version | head -n1 )"
103log "CFLAGS=$ARMGCC_FLAGS"
104
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +0200105# creates the yotta config
106yotta/create-module.sh >/dev/null
107
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000108doit default include/mbedtls/config.h
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +0200109doit yotta yotta/module/mbedtls/config.h
110doit thread configs/config-thread.h
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000111doit suite-b configs/config-suite-b.h
Manuel Pégourié-Gonnardac8673c2015-10-16 13:03:04 +0200112doit psk configs/config-ccm-psk-tls1_2.h
Manuel Pégourié-Gonnard4553a6c2015-11-25 10:39:00 +0000113
114zip mbedtls-footprint.zip "$OUTFILE" size-*.txt >/dev/null